summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-10-05 06:19:02 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-10-05 06:19:02 -0700
commit2d4d37907eb060fc23cc4a9f8ebf6b577db3a18b (patch)
treef3d7a0a522c2ccacde21ab944fb53ec0c7363c85 /tests
parent77f92bd8b4cb96ddae97b2cdec2427fd4c16c6ee (diff)
downloadtxr-2d4d37907eb060fc23cc4a9f8ebf6b577db3a18b.tar.gz
txr-2d4d37907eb060fc23cc4a9f8ebf6b577db3a18b.tar.bz2
txr-2d4d37907eb060fc23cc4a9f8ebf6b577db3a18b.zip
New functions trim-left and trim-right.
* regex.c (trim_left, trim_right): New static functions. (regex_init): New intrinsics registered. * tests/015/trim.tl, tests/015/trim.expected: New files. * txr.1: Documented.
Diffstat (limited to 'tests')
-rw-r--r--tests/015/trim.expected0
-rw-r--r--tests/015/trim.tl41
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/015/trim.expected b/tests/015/trim.expected
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/015/trim.expected
diff --git a/tests/015/trim.tl b/tests/015/trim.tl
new file mode 100644
index 00000000..da1fc0c1
--- /dev/null
+++ b/tests/015/trim.tl
@@ -0,0 +1,41 @@
+(load "../common")
+
+(mtest
+ (trim-left "" "") ""
+ (trim-left 1 "") :error
+ (trim-left "" 1) :error
+ (trim-left 1 1) :error)
+
+(mtest
+ (trim-left "" "abc") "abc"
+ (trim-left "a" "abc") "bc"
+ (trim-left "ab" "abc") "c"
+ (trim-left "abc" "abc") ""
+ (trim-left "abcd" "abc") "abc"
+ (trim-left "z" "abc") "abc")
+
+(mtest
+ (trim-left #// "abc") "abc"
+ (trim-left #/./ "abc") "bc"
+ (trim-left #/../ "abc") "c"
+ (trim-left #/.../ "abc") ""
+ (trim-left #/.*/ "abc") ""
+ (trim-left #/..../ "abc") "abc"
+ (trim-left #/z/ "abc") "abc")
+
+(mtest
+ (trim-right "" "abc") "abc"
+ (trim-right "c" "abc") "ab"
+ (trim-right "bc" "abc") "a"
+ (trim-right "abc" "abc") ""
+ (trim-right "xabc" "abc") "abc"
+ (trim-right "z" "abc") "abc")
+
+(mtest
+ (trim-right #// "abc") "abc"
+ (trim-right #/./ "abc") "ab"
+ (trim-right #/../ "abc") "a"
+ (trim-right #/.../ "abc") ""
+ (trim-right #/.*/ "abc") ""
+ (trim-right #/..../ "abc") "abc"
+ (trim-right #/z/ "abc") "abc")