From 4647adffc41d6b10ab5c37f2ed8f5a638e1cf305 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 27 Apr 2021 21:16:08 -0700 Subject: match-str: tests and bugfix. * lib.c (do_match_str): Fix wrong return value calculation in LSTR-LSTR case. * tests/015/match-str.tl: New file. --- lib.c | 2 +- tests/015/match-str.tl | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/015/match-str.tl diff --git a/lib.c b/lib.c index e755e88a..2f0f9859 100644 --- a/lib.c +++ b/lib.c @@ -4554,7 +4554,7 @@ static val do_match_str(val bigstr, val str, cnum pos, val self) return nil; } - return length_str_le(str, num(i)) ? num(i + 1) : nil; + return length_str_le(str, num(i)) ? num(p) : nil; } default: invalid_ops(self, bigstr, str); diff --git a/tests/015/match-str.tl b/tests/015/match-str.tl new file mode 100644 index 00000000..53e2c73a --- /dev/null +++ b/tests/015/match-str.tl @@ -0,0 +1,41 @@ +(load "../common") + +(defun lz (str) + (lazy-str (spl "" str) "")) + +(defun lz* (str) + (lazy-str (append (spl "" str) 42) "")) + +(mtest + (match-str "" "") 0 + (match-str "a" "a") 1 + (match-str "a" "") 0 + (match-str "a" "" 1) 1 + (match-str "a" "" 2) nil + (match-str "abc" "c" 2) 3 + (match-str "abc" "b" 1) 2 + (match-str "abc" "a" 0) 1 + (match-str "abc" "b" 2) nil + (match-str "abc" "a" 1) nil + (match-str "abc" "c" 0) nil + (match-str "abc" "c" 3) nil + (match-str "abc" "c" 4) nil + (match-str "abc" "abcd") nil) + +(mtest + (match-str (lz* "abc#") "c" 2) 3 + (match-str "abc#" (lz "c") 2) 3 + (match-str (lz* "abc#") (lz "c") 2) 3 + (match-str (lz "abc") (lz "c") 2) 3 + (match-str (lz "abc") (lz "b") 1) 2 + (match-str (lz "abc") (lz "a") 0) 1 + (match-str (lz "abc") (lz "b") 2) nil + (match-str (lz "abc") (lz "a") 1) nil + (match-str (lz "abc") (lz "c") 0) nil + (match-str (lz "abc") (lz "c") 3) nil + (match-str (lz "abc") (lz "c") 4) nil + (match-str (lz "abc") (lz "abcd")) nil) + +(mtest + (match-str "" "" -1) nil + (match-str "" "" -1) nil) -- cgit v1.2.3