aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar David Adam <zanchey@ucc.gu.uwa.edu.au>2015-10-09 11:27:18 +0800
committerGravatar David Adam <zanchey@ucc.gu.uwa.edu.au>2015-10-09 11:27:18 +0800
commit0b3406bdc0049ac560921c3a0b23516989ab153e (patch)
tree541f1fe5a2b0e185b2cae0a9340d1546572c264a /tests
parent74cd9775661a378c13d533fd8b432eefd916f0e3 (diff)
tests/string.in: add tests for string builtin
Diffstat (limited to 'tests')
-rw-r--r--tests/string.err0
-rw-r--r--tests/string.in63
-rw-r--r--tests/string.out46
-rw-r--r--tests/string.status1
4 files changed, 110 insertions, 0 deletions
diff --git a/tests/string.err b/tests/string.err
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/string.err
diff --git a/tests/string.in b/tests/string.in
new file mode 100644
index 00000000..1c78e2b3
--- /dev/null
+++ b/tests/string.in
@@ -0,0 +1,63 @@
+# tests for string builtin
+# mostly taken from examples
+string length 'hello, world'
+
+string length -q ""; and echo not zero length
+
+string sub --length 2 abcde
+
+string sub -s 2 -l 2 abcde
+
+string sub --start=-2 abcde
+
+string split . example.com
+
+string split -r -m1 / /usr/local/bin/fish
+
+string split '' abc
+
+seq 3 | string join ...
+
+echo ' abc '
+string trim ' abc '
+
+string trim --right --chars=yz xyzzy zany
+
+echo \x07 | string escape
+
+string match '?' a
+
+string match 'a*b' axxb
+
+string match -i 'a??B' Axxb
+
+echo 'ok?' | string match '*\?'
+
+string match -r 'cat|dog|fish' 'nice dog'
+
+string match -r '(\d\d?):(\d\d):(\d\d)' 2:34:56
+
+string match -r '^(\w{2,4})\g1$' papa mud murmur
+
+string match -r -a -n at ratatat
+
+string match -r -i '0x[0-9a-f]{1,8}' 'int magic = 0xBadC0de;'
+
+string replace is was 'blue is my favorite'
+
+string replace 3rd last 1st 2nd 3rd
+
+string replace -a ' ' _ 'spaces to underscores'
+
+string replace -r -a '[^\d.]+' ' ' '0 one two 3.14 four 5x'
+
+string replace -r '(\w+)\s+(\w+)' '$2 $1 $$' 'left right'
+
+string replace -r '\s*newline\s*' '\n' 'put a newline here'
+
+# test some failure cases
+string match -r '[' 'a[sd' 2>/dev/null; or echo "invalid expression error"
+
+string invalidarg 2>/dev/null; or echo "invalid argument error"
+
+string length 2>/dev/null; or echo "missing argument returns 0"
diff --git a/tests/string.out b/tests/string.out
new file mode 100644
index 00000000..64b956e3
--- /dev/null
+++ b/tests/string.out
@@ -0,0 +1,46 @@
+12
+ab
+bc
+de
+example
+com
+/usr/local/bin
+fish
+a
+b
+c
+1...2...3
+ abc
+abc
+x
+zan
+\cg
+a
+axxb
+Axxb
+ok?
+dog
+2:34:56
+2
+34
+56
+papa
+pa
+murmur
+mur
+2 2
+4 2
+6 2
+0xBadC0de
+blue was my favorite
+1st
+2nd
+last
+spaces_to_underscores
+0 3.14 5
+right left $
+put a
+here
+invalid expression error
+invalid argument error
+missing argument returns 0
diff --git a/tests/string.status b/tests/string.status
new file mode 100644
index 00000000..573541ac
--- /dev/null
+++ b/tests/string.status
@@ -0,0 +1 @@
+0