From b157a04411e9efb61bb29b418f077307a4ee8088 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 22 Jun 2021 07:39:30 -0700 Subject: 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. --- lib.c | 2 +- tests/012/seq.tl | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) 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 @@ -119,6 +119,45 @@ (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 + (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 -- cgit v1.2.3