shithub: mc

Download patch

ref: 6aab6b7b0d8fb0e37f7021f17714efbe02a227bb
parent: 76fc43acecea75b362d7e56557a0466cbda94572
author: S. Gilles <[email protected]>
date: Thu Nov 9 14:51:58 EST 2017

Allow sleq to read far enough into the array to compare wide types

--- a/lib/std/sleq.myr
+++ b/lib/std/sleq.myr
@@ -7,7 +7,7 @@
 
 generic sleq = {a, b
 	if a.len == b.len
-		-> memeq((a : byte#), (b : byte#), a.len)
+		-> memeq((a : byte#), (b : byte#), a.len * sizeof(@a))
 	else
 		-> false
 	;;
--- /dev/null
+++ b/lib/std/test/sleq.myr
@@ -1,0 +1,25 @@
+use std
+
+use testr
+
+const main = {
+	testr.run([
+		[.name = "wider-than-byte", .fn = wide],
+		[.name = "slices", .fn = slices],
+	][:])
+}
+
+const wide = {c
+	var a : uint[3] = [ 0, 1, 2]
+	var b : uint[3] = [ 0, 1, 3]
+	testr.check(c, !std.sleq(a[:], b[:]), "expected {} != {} as uint[:]", a, b)
+}
+
+const slices = {c
+	var a : int8[8] = [ 0, 0, 3, 1, 0, 3, 1, 2 ]
+	var b : int8[3] = [ 1, 0, 3]
+	testr.check(c, std.sleq(a[1:4], a[4:7]), "expected {} = {}", a[1:4], a[4:7])
+	testr.check(c, !std.sleq(a[0:4], a[3:7]), "expected {} = {}", a[0:4], a[3:7])
+	testr.check(c, !std.sleq(a[:], b[:]), "expected {} = {}", a, b)
+	testr.check(c, !std.sleq(a[3:7], b[:]), "expected {} = {}", a[3:7], b)
+}