summaryrefslogtreecommitdiffstats
path: root/tests/012
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-08-17 07:07:41 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-08-17 07:07:41 -0700
commita2e0d566ef4d45d4915d43d035f6f21270d70178 (patch)
tree3e709fdf05798077b1eb3e97bc11ccab5bbe1f7f /tests/012
parentce231e5426cb9f2238158e46032215d5b410bd60 (diff)
downloadtxr-a2e0d566ef4d45d4915d43d035f6f21270d70178.tar.gz
txr-a2e0d566ef4d45d4915d43d035f6f21270d70178.tar.bz2
txr-a2e0d566ef4d45d4915d43d035f6f21270d70178.zip
New function: search-all
* eval.c (eval_init): search-all intrinsic registered. * lib.c (search_common): New Boolean argument all, indicating whether all positions are to be returned. We must handle this in the two places where empty key and sequence are handled, and also in the main loop. A trick is used: the found variable is now bound by list_collect_decl, but not used for collecting unless all is true. (search, rsearch, contains): Pass 0 for all argument of search_common. (search_all): New function. * lib.h (search_all): Declared. * tests/012/seq.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Regenerated.
Diffstat (limited to 'tests/012')
-rw-r--r--tests/012/seq.tl15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/012/seq.tl b/tests/012/seq.tl
index 4a1be8dd..a65d8ffa 100644
--- a/tests/012/seq.tl
+++ b/tests/012/seq.tl
@@ -501,6 +501,7 @@
[count #1="abc" '("abc" "abc" "abc" #1# "abc" #1#" abc") eq] 2))
(mtest
+ (search "" "") 0
(search "abcde" "ab") 0
(search "abcde" "bc") 1
(search "abcde" "cd") 2
@@ -510,6 +511,7 @@
(search "abcde" "x") nil)
(mtest
+ (search nil nil) 0
(search '#"a b c d e" '#"a b") 0
(search '#"a b c d e" '#"b c") 1
(search '#"a b c d e" '#"c d") 2
@@ -519,6 +521,7 @@
(search '#"a b c d e" '#"x") nil)
(mtest
+ (rsearch nil nil) 0
(rsearch "abcde" "ab") 0
(rsearch "abcde" "bc") 1
(rsearch "abcde" "cd") 2
@@ -535,3 +538,15 @@
(rsearch '#"a b c d e" '#"e") 4
(rsearch '#"a b c d e" nil) 5
(rsearch '#"a b c d e" '#"x") nil)
+
+(mtest
+ (search-all "" "") (0)
+ (search-all "xxxxx" "y") nil
+ (search-all "xxxxx" "x") (0 1 2 3 4)
+ (search-all "xxx" "") (0 1 2 3))
+
+(mtest
+ (search-all nil nil) (0)
+ (search-all '#"x x x x x" '#"y") nil
+ (search-all '#"x x x x x" '#"x") (0 1 2 3 4)
+ (search-all '#"x x x" "") (0 1 2 3))