summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-09-17 10:43:19 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-09-17 10:43:19 -0700
commit972d095787d6107141004a66f8e5c86b89f446c6 (patch)
treeaa552db14da3a8fabf0f265181667011656a2afa
parentfd22fbc29fc0ee1a726880fa3bab64e187433854 (diff)
downloadtxr-972d095787d6107141004a66f8e5c86b89f446c6.tar.gz
txr-972d095787d6107141004a66f8e5c86b89f446c6.tar.bz2
txr-972d095787d6107141004a66f8e5c86b89f446c6.zip
Adding tests for split-str.
* Makefile (TXR_DBG_OPTS): Disable for tst/tests/015. * tests/common.tl (mtest): New macro. * tests/015/split.tl: New file.
-rw-r--r--Makefile1
-rw-r--r--tests/015/split.tl123
-rw-r--r--tests/common.tl3
3 files changed, 127 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 31d6294c..0ca4a3a0 100644
--- a/Makefile
+++ b/Makefile
@@ -316,6 +316,7 @@ tst/tests/011/%: TXR_DBG_OPTS :=
tst/tests/012/%: TXR_DBG_OPTS :=
tst/tests/013/%: TXR_DBG_OPTS :=
tst/tests/014/%: TXR_DBG_OPTS :=
+tst/tests/015/%: TXR_DBG_OPTS :=
.PRECIOUS: tst/%.out
tst/%.out: %.txr
diff --git a/tests/015/split.tl b/tests/015/split.tl
new file mode 100644
index 00000000..df496170
--- /dev/null
+++ b/tests/015/split.tl
@@ -0,0 +1,123 @@
+(load "../common")
+
+(mtest
+ (split-str "" "") ("")
+ (split-str "a" "") ("a")
+ (split-str "" "a") ("")
+ (split-str "a" "a") ("" ""))
+
+(mtest
+ (split-str "" "" t) ("")
+ (split-str "a" "" t) ("a")
+ (split-str "" "a" t) ("")
+ (split-str "a" "a" t) ("" "a" ""))
+
+(mtest
+ (split-str "" #//) ("")
+ (split-str "a" #//) ("a")
+ (split-str "" #/a/) ("")
+ (split-str "a" #/a/) ("" ""))
+
+(mtest
+ (split-str "" #// t) ("")
+ (split-str "a" #// t) ("a")
+ (split-str "" #/a/ t) ("")
+ (split-str "a" #/a/ t) ("" "a" ""))
+
+(mtest
+ (split-str "ab" "") ("a" "b")
+ (split-str "ab" "a") ("" "b")
+ (split-str "ab" "b") ("a" "")
+ (split-str "ab" "ab") ("" "")
+ (split-str "ab" "abc") ("ab"))
+
+(mtest
+ (split-str "ab" "" t) ("a" "" "b")
+ (split-str "ab" "a" t) ("" "a" "b")
+ (split-str "ab" "b" t) ("a" "b" "")
+ (split-str "ab" "ab" t) ("" "ab" "")
+ (split-str "ab" "abc" t) ("ab"))
+
+(mtest
+ (split-str "ab" #//) ("a" "b")
+ (split-str "ab" #/a/) ("" "b")
+ (split-str "ab" #/b/) ("a" "")
+ (split-str "ab" #/ab/) ("" "")
+ (split-str "ab" #/abc/) ("ab"))
+
+(mtest
+ (split-str "ab" #// t) ("a" "" "b")
+ (split-str "ab" #/a/ t) ("" "a" "b")
+ (split-str "ab" #/b/ t) ("a" "b" "")
+ (split-str "ab" #/ab/ t) ("" "ab" "")
+ (split-str "ab" #/abc/ t) ("ab"))
+
+(mtest
+ (split-str "abc" "") ("a" "b" "c")
+ (split-str "abc" "" t) ("a" "" "b" "" "c")
+ (split-str "abc" #//) ("a" "b" "c")
+ (split-str "abc" #// t) ("a" "" "b" "" "c"))
+
+(mtest
+ (split-str "abc" "a") ("" "bc")
+ (split-str "abc" "b") ("a" "c")
+ (split-str "abc" "c") ("ab" "")
+ (split-str "abc" "a" t) ("" "a" "bc")
+ (split-str "abc" "b" t) ("a" "b" "c")
+ (split-str "abc" "c" t) ("ab" "c" "")
+ (split-str "abc" #/a/) ("" "bc")
+ (split-str "abc" #/b/) ("a" "c")
+ (split-str "abc" #/c/) ("ab" "")
+ (split-str "abc" #/a/ t) ("" "a" "bc")
+ (split-str "abc" #/b/ t) ("a" "b" "c")
+ (split-str "abc" #/c/ t) ("ab" "c" ""))
+
+(mtest
+ (split-str "abc" "ab") ("" "c")
+ (split-str "abc" "bc") ("a" "")
+ (split-str "abc" "abc") ("" "")
+ (split-str "abc" "ab" t) ("" "ab" "c")
+ (split-str "abc" "bc" t) ("a" "bc" "")
+ (split-str "abc" "abc" t) ("" "abc" "")
+ (split-str "abc" #/ab/) ("" "c")
+ (split-str "abc" #/bc/) ("a" "")
+ (split-str "abc" #/abc/) ("" "")
+ (split-str "abc" #/ab/ t) ("" "ab" "c")
+ (split-str "abc" #/bc/ t) ("a" "bc" "")
+ (split-str "abc" #/abc/ t) ("" "abc" ""))
+
+(mtest
+ (split-str "a,b,c" ",") ("a" "b" "c")
+ (split-str ",b,c" ",") ("" "b" "c")
+ (split-str "a,,c" ",") ("a" "" "c")
+ (split-str "a,b," ",") ("a" "b" "")
+ (split-str ",,c" ",") ("" "" "c")
+ (split-str "a,," ",") ("a" "" "")
+ (split-str ",," ",") ("" "" ""))
+
+(mtest
+ (split-str "a,b,c" #/,/ t) ("a" "," "b" "," "c")
+ (split-str ",b,c" #/,/ t) ("" "," "b" "," "c")
+ (split-str "a,,c" #/,/ t) ("a" "," "" "," "c")
+ (split-str "a,b," #/,/ t) ("a" "," "b" "," "")
+ (split-str ",,c" #/,/ t) ("" "," "" "," "c")
+ (split-str "a,," #/,/ t) ("a" "," "" "," "")
+ (split-str ",," #/,/ t) ("" "," "" "," ""))
+
+(mtest
+ (split-str "a,b,c" #/[^,]/) ("" "," "," "")
+ (split-str "a,b,c" #/[^,]/ t) ("" "a" "," "b" "," "c" "")
+ (split-str "a,b,c" #/[^a-c]/) #"a b c"
+ (split-str "a,b,c" #/[^a-c]/ t) #"a , b , c")
+
+(mtest
+ (split-str "abc" #/./) ("" "" "" "")
+ (split-str "abc" #/./ t) ("" "a" "" "b" "" "c" "")
+ (split-str "abc" #/../) ("" "c")
+ (split-str "abc" #/../ t) ("" "ab" "c")
+ (split-str "abc" #/.../) ("" "")
+ (split-str "abc" #/.../ t) ("" "abc" ""))
+
+(mtest
+ (split-str "abcacabcac" #/ab?/) ("" "c" "c" "c" "c")
+ (split-str "abcacabcac" #/ab?/ t) ("" "ab" "c" "a" "c" "ab" "c" "a" "c"))
diff --git a/tests/common.tl b/tests/common.tl
index ea2be1d5..c0dda285 100644
--- a/tests/common.tl
+++ b/tests/common.tl
@@ -20,6 +20,9 @@
(defmacro stest (expr expected)
^(vtest ,^(tostring ,expr) ,expected))
+(defmacro mtest (. pairs)
+ ^(progn ,*(mapcar (op cons 'test) (tuples 2 pairs))))
+
(defun osname ()
(with-stream (u (open-command "(uname -o || uname) 2> /dev/null"))
(get-line u)))