summaryrefslogtreecommitdiffstats
path: root/tests/015
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-05-17 21:02:21 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-05-17 21:02:21 -0700
commitf255d4cfaf866ced7a5fb2f4af4681d96a069b4b (patch)
tree755ddf6bfcc6ede8f6e8d7d2eabf16bae6e96c4f /tests/015
parentf16a4c07c8dad9d7d144063618cf65c6e076233e (diff)
downloadtxr-f255d4cfaf866ced7a5fb2f4af4681d96a069b4b.tar.gz
txr-f255d4cfaf866ced7a5fb2f4af4681d96a069b4b.tar.bz2
txr-f255d4cfaf866ced7a5fb2f4af4681d96a069b4b.zip
split-str: new count parameter.
* eval.c (eval_init): Fix up registration of split-str to account for new parameter. * lib.c (split_str_keep): Implement new optional count argument. (spl): Pass nil value to split_str_keep for new argument. I'd like this function to benefit from this argument also, but the design isn't settled. (split_str): Pass nil argument to split_str_keep. * lib.h (split_str_keep): Declaration updated. * tests/015/split.tl: New tests. * txr.1: Documented.
Diffstat (limited to 'tests/015')
-rw-r--r--tests/015/split.tl39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/015/split.tl b/tests/015/split.tl
index e54092c5..8cdf7f04 100644
--- a/tests/015/split.tl
+++ b/tests/015/split.tl
@@ -217,3 +217,42 @@
(join-with "a" "b") "b"
(join-with "--" "b" "c" "d") "b--c--d"
(join-with #\- "b" "c" "d") "b-c-d")
+
+(mtest
+ (split-str "abc" "" : 0) ("abc")
+ (split-str "abc" "" : 1) ("a" "bc")
+ (split-str "abc" "" : 2) ("a" "b" "c")
+ (split-str "abc" "" : 3) ("a" "b" "c")
+ (split-str "abc" "" : -1) :error)
+
+(mtest
+ (split-str "abc" "" t 0) ("abc")
+ (split-str "abc" "" t 1) ("a" "" "bc")
+ (split-str "abc" "" t 2) ("a" "" "b" "" "c")
+ (split-str "abc" "" t 3) ("a" "" "b" "" "c"))
+
+(mtest
+ (split-str "a,b,c" "," : 0) ("a,b,c")
+ (split-str "a,b,c" "," : 1) ("a" "b,c")
+ (split-str "a,b,c" "," : 2) ("a" "b" "c")
+ (split-str "a,b,c" "," : 3) ("a" "b" "c"))
+
+(mtest
+ (split-str "a,b,c" "," t 0) ("a,b,c")
+ (split-str "a,b,c" "," t 1) ("a" "," "b,c")
+ (split-str "a,b,c" "," t 2) ("a" "," "b" "," "c")
+ (split-str "a,b,c" "," t 3) ("a" "," "b" "," "c"))
+
+(mtest
+ (split-str "a12b34c567d" #/[0-9]+/ : 0) ("a12b34c567d")
+ (split-str "a12b34c567d" #/[0-9]+/ : 1) ("a" "b34c567d")
+ (split-str "a12b34c567d" #/[0-9]+/ : 2) ("a" "b" "c567d")
+ (split-str "a12b34c567d" #/[0-9]+/ : 3) ("a" "b" "c" "d")
+ (split-str "a12b34c567d" #/[0-9]+/ : 4) ("a" "b" "c" "d"))
+
+(mtest
+ (split-str "a12b34c567d" #/[0-9]+/ t 0) ("a12b34c567d")
+ (split-str "a12b34c567d" #/[0-9]+/ t 1) ("a" "12" "b34c567d")
+ (split-str "a12b34c567d" #/[0-9]+/ t 2) ("a" "12" "b" "34" "c567d")
+ (split-str "a12b34c567d" #/[0-9]+/ t 3) ("a" "12" "b" "34" "c" "567" "d")
+ (split-str "a12b34c567d" #/[0-9]+/ t 4) ("a" "12" "b" "34" "c" "567" "d"))