summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-22 07:39:30 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-22 07:39:30 -0700
commitb9db5d41cbf4ef8fe1c07bf0f43e01e42e632702 (patch)
tree02c3dd2be0c79ca84c20a75abc12f8bcb4f220ed
parent27ece3ffc30437f4a70228b96764e306bd5ed4f1 (diff)
downloadtxr-b9db5d41cbf4ef8fe1c07bf0f43e01e42e632702.tar.gz
txr-b9db5d41cbf4ef8fe1c07bf0f43e01e42e632702.tar.bz2
txr-b9db5d41cbf4ef8fe1c07bf0f43e01e42e632702.zip
lib: rmismatch tests and bugfix.
* lib.c (rmismatch): when left is an empty string or vector, and right is nil: we must return -1 not zero. * tests/012/seq.tl: More rmismatch tests.
-rw-r--r--lib.c2
-rw-r--r--tests/012/seq.tl39
2 files changed, 40 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index dce7b2c3..85f3f55c 100644
--- a/lib.c
+++ b/lib.c
@@ -10996,7 +10996,7 @@ val rmismatch(val left, val right, val testfun_in, val keyfun_in)
case VEC:
switch (type(right)) {
case NIL:
- return if3(length(left) == zero, nil, zero);
+ return if3(length(left) == zero, nil, negone);
case CONS:
case LCONS:
return rmismatch(right, left, testfun, keyfun);
diff --git a/tests/012/seq.tl b/tests/012/seq.tl
index 936dc8c9..23971c97 100644
--- a/tests/012/seq.tl
+++ b/tests/012/seq.tl
@@ -120,6 +120,45 @@
(rmismatch #(2 1) #(3 2 1)) -3)
(mtest
+ (rmismatch '() '()) nil
+ (rmismatch '(1) '()) -1
+ (rmismatch '() '(1)) -1
+ (rmismatch '(1) '(1)) nil
+ (rmismatch '(1 2) '(1 2)) nil
+ (rmismatch '(2 2) '(1 2)) -2
+ (rmismatch '(1 2) '(2 2)) -2
+ (rmismatch '(3 2 1) '(1 1)) -2
+ (rmismatch '(1 1) '(3 2 1)) -2
+ (rmismatch '(3 2 1) '(2 1)) -3
+ (rmismatch '(2 1) '(3 2 1)) -3)
+
+(mtest
+ (rmismatch '() #()) nil
+ (rmismatch '(1) #()) -1
+ (rmismatch '() #(1)) -1
+ (rmismatch '(1) #(1)) nil
+ (rmismatch '(1 2) #(1 2)) nil
+ (rmismatch '(2 2) #(1 2)) -2
+ (rmismatch '(1 2) #(2 2)) -2
+ (rmismatch '(3 2 1) #(1 1)) -2
+ (rmismatch '(1 1) #(3 2 1)) -2
+ (rmismatch '(3 2 1) #(2 1)) -3
+ (rmismatch '(2 1) #(3 2 1)) -3)
+
+(mtest
+ (rmismatch #() '()) nil
+ (rmismatch #(1) '()) -1
+ (rmismatch #() '(1)) -1
+ (rmismatch #(1) '(1)) nil
+ (rmismatch #(1 2) '(1 2)) nil
+ (rmismatch #(2 2) '(1 2)) -2
+ (rmismatch #(1 2) '(2 2)) -2
+ (rmismatch #(3 2 1) '(1 1)) -2
+ (rmismatch #(1 1) '(3 2 1)) -2
+ (rmismatch #(3 2 1) '(2 1)) -3
+ (rmismatch #(2 1) '(3 2 1)) -3)
+
+(mtest
(rmismatch "" "") nil
(rmismatch "1" "") -1
(rmismatch "" "1") -1