use new logmsg and set --show in tests

This commit is contained in:
Kurtis Rader 2017-08-04 12:51:48 -07:00
parent e198ed0b2d
commit a4ed0837a1
3 changed files with 473 additions and 193 deletions

View file

@ -1,34 +1,293 @@
####################
# string match -r -v "c.*" dog can cat diz
####################
# string match -q -r -v "c.*" dog can cat diz
####################
# string match -v "c*" dog can cat diz
####################
# string match -q -v "c*" dog can cat diz
####################
# string match -v "d*" dog dan dat diz
####################
# string match -q -v "d*" dog dan dat diz
####################
# string match -r -v x y
####################
# string match -r -v x x
####################
# string match -q -r -v x y
####################
# string match -q -r -v x x
####################
# string length "hello, world"
####################
# string length -q ""
####################
# 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 ...
####################
# string trim " abc "
####################
# string trim --right --chars=yz xyzzy zany
####################
# echo \x07 | string escape
####################
# string escape --style=script 'a b#c"\'d'
####################
# string escape --style=url 'a b#c"\'d'
####################
# string escape --style=url \na\nb%c~d\n
####################
# string escape --style=var 'a b#c"\'d'
####################
# string escape --style=script a\nghi_
####################
# string escape --style=var 'abc'
####################
# string escape --style=var '_a_b_c_'
####################
# string escape --style=var -- -
####################
# set x (string unescape (echo \x07 | string escape))
####################
# string unescape --style=script (string escape --style=script 'a b#c"\'d')
####################
# string unescape --style=url (string escape --style=url 'a b#c"\'d')
####################
# string unescape --style=url (string escape --style=url \na\nb%c~d\n)
####################
# string unescape --style=var (string escape --style=var 'a b#c"\'d')
####################
# string unescape --style=var (string escape --style=var a\nghi_)
####################
# string unescape --style=var (string escape --style=var 'abc')
####################
# string unescape --style=var (string escape --style=var '_a_b_c_')
####################
# string unescape --style=var (string escape --style=var -- -)
####################
# 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"
####################
# string replace -r -a "(\w)" "\$1\$1" ab
####################
# string replace --filter x X abc axc x def jkx
####################
# string replace --regex -f "\d" X 1bc axc 2 d3f jk4 xyz
####################
# string match -r "[" "a[sd"
string match: Regular expression compile error: missing terminating ] for character class
string match: [
string match: ^
####################
# string invalidarg
string: Subcommand 'invalidarg' is not valid
Standard input (line 251):
string invalidarg; and echo "unexpected exit 0" >&2
Standard input (line 194):
string invalidarg; and echo "unexpected exit 0"
^
####################
# string length
####################
# string match -r -v "[dcantg].*" dog can cat diz
####################
# string match -v "???" dog can cat diz
####################
# string match -rvn a bbb
####################
# string repeat -n 2 "foo"
####################
# string repeat --count 2 "foo"
####################
# echo foo | string repeat -n 2
####################
# string repeat -n2 -q "foo"
####################
# string repeat -n2 --quiet "foo"
####################
# string repeat -n0 "foo"
####################
# string repeat -n0
####################
# string repeat -m0
####################
# string repeat -n1 -N "there is "
####################
# string repeat -n1 --no-newline "there is "
####################
# string repeat -n10 -m4 "foo"
####################
# string repeat -n10 --max 5 "foo"
####################
# string repeat -n3 -m20 "foo"
####################
# string repeat -m4 "foo"
####################
# string repeat -n-1 "foo"
string repeat: Invalid count value '-1'
####################
# string repeat -m-1 "foo"
string repeat: Invalid max value '-1'
####################
# string repeat -n notanumber "foo"
string repeat: Argument 'notanumber' is not a number
####################
# string repeat -m notanumber "foo"
string repeat: Argument 'notanumber' is not a number
####################
# echo "stdin" | string repeat -n1 "and arg"
string repeat: Too many arguments
####################
# string repeat -n
string repeat: Expected argument
####################
# string repeat -l fakearg 2>&1
string repeat: Unknown option '-l'
Standard input (line 352):
Standard input (line 270):
string repeat -l fakearg
^
####################
# string repeat ""
####################
# string repeat -n3 ""
####################
# string match -e x abc dxf xyz jkx x z
####################
# string match x abc dxf xyz jkx x z
####################
# string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
####################
# string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
####################
# string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
####################
# string match -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz

View file

@ -1,241 +1,185 @@
# Tests for string builtin. Mostly taken from man page examples.
echo '# string match -r -v "c.*" dog can cat diz'
logmsg 'string match -r -v "c.*" dog can cat diz'
string match -r -v "c.*" dog can cat diz; and echo "exit 0"
echo
echo '# string match -q -r -v "c.*" dog can cat diz'
logmsg 'string match -q -r -v "c.*" dog can cat diz'
string match -q -r -v "c.*" dog can cat diz; and echo "exit 0"
echo
echo '# string match -v "c*" dog can cat diz'
logmsg 'string match -v "c*" dog can cat diz'
string match -v "c*" dog can cat diz; and echo "exit 0"
echo
echo '# string match -q -v "c*" dog can cat diz'
logmsg 'string match -q -v "c*" dog can cat diz'
string match -q -v "c*" dog can cat diz; and echo "exit 0"
echo
echo '# string match -v "d*" dog dan dat diz'
logmsg 'string match -v "d*" dog dan dat diz'
string match -v "d*" dog dan dat diz; or echo "exit 1"
echo
echo '# string match -q -v "d*" dog dan dat diz'
logmsg 'string match -q -v "d*" dog dan dat diz'
string match -q -v "d*" dog dan dat diz; or echo "exit 1"
echo
echo '# string match -r -v x y'
logmsg 'string match -r -v x y'
string match -r -v x y; and echo "exit 0"
echo
echo '# string match -r -v x x'
logmsg 'string match -r -v x x'
string match -r -v x x; or echo "exit 1"
echo
echo '# string match -q -r -v x y'
logmsg 'string match -q -r -v x y'
string match -q -r -v x y; and echo "exit 0"
echo
echo '# string match -q -r -v x x'
logmsg 'string match -q -r -v x x'
string match -q -r -v x x; or echo "exit 1"
echo
echo '# string length "hello, world"'
logmsg 'string length "hello, world"'
string length "hello, world"
echo
echo '# string length -q ""'
logmsg 'string length -q ""'
string length -q ""; and echo not zero length; or echo zero length
echo
echo '# string sub --length 2 abcde'
logmsg 'string sub --length 2 abcde'
string sub --length 2 abcde
echo
echo '# string sub -s 2 -l 2 abcde'
logmsg 'string sub -s 2 -l 2 abcde'
string sub -s 2 -l 2 abcde
echo
echo '# string sub --start=-2 abcde'
logmsg 'string sub --start=-2 abcde'
string sub --start=-2 abcde
echo
echo '# string split . example.com'
logmsg 'string split . example.com'
string split . example.com
echo
echo '# string split -r -m1 / /usr/local/bin/fish'
logmsg 'string split -r -m1 / /usr/local/bin/fish'
string split -r -m1 / /usr/local/bin/fish
echo
echo '# string split "" abc'
logmsg 'string split "" abc'
string split "" abc
echo
echo '# seq 3 | string join ...'
logmsg 'seq 3 | string join ...'
seq 3 | string join ...
echo
echo '# string trim " abc "'
logmsg 'string trim " abc "'
string trim " abc "
echo
echo '# string trim --right --chars=yz xyzzy zany'
logmsg 'string trim --right --chars=yz xyzzy zany'
string trim --right --chars=yz xyzzy zany
echo
echo '# echo \x07 | string escape'
logmsg 'echo \x07 | string escape'
echo \x07 | string escape
echo
echo '# string escape --style=script \'a b#c"\\\'d\''
logmsg 'string escape --style=script \'a b#c"\\\'d\''
string escape --style=script 'a b#c"\'d'
echo
echo '# string escape --style=url \'a b#c"\\\'d\''
logmsg 'string escape --style=url \'a b#c"\\\'d\''
string escape --style=url 'a b#c"\'d'
echo
echo '# string escape --style=url \\na\\nb%c~d\\n'
logmsg 'string escape --style=url \\na\\nb%c~d\\n'
string escape --style=url \na\nb%c~d\n
echo
echo '# string escape --style=var \'a b#c"\\\'d\''
logmsg 'string escape --style=var \'a b#c"\\\'d\''
string escape --style=var 'a b#c"\'d'
echo
echo '# string escape --style=script a\nghi_'
logmsg 'string escape --style=script a\nghi_'
string escape --style=var a\nghi_
echo
echo '# string escape --style=var \'abc\''
logmsg 'string escape --style=var \'abc\''
string escape --style=var 'abc'
echo
echo '# string escape --style=var \'_a_b_c_\''
logmsg 'string escape --style=var \'_a_b_c_\''
string escape --style=var '_a_b_c_'
echo
echo '# string escape --style=var -- -'
logmsg 'string escape --style=var -- -'
string escape --style=var -- -
# The following tests verify that we can correctly unescape the same strings
# we tested escaping above.
echo
echo '# set x (string unescape (echo \x07 | string escape))'
logmsg 'set x (string unescape (echo \x07 | string escape))'
set x (string unescape (echo \x07 | string escape))
test $x = \x07
and echo success
echo
echo '# string unescape --style=script (string escape --style=script \'a b#c"\\\'d\')'
logmsg 'string unescape --style=script (string escape --style=script \'a b#c"\\\'d\')'
string unescape --style=script (string escape --style=script 'a b#c"\'d')
echo
echo '# string unescape --style=url (string escape --style=url \'a b#c"\\\'d\')'
logmsg 'string unescape --style=url (string escape --style=url \'a b#c"\\\'d\')'
string unescape --style=url (string escape --style=url 'a b#c"\'d')
echo
echo '# string unescape --style=url (string escape --style=url \na\nb%c~d\n)'
logmsg 'string unescape --style=url (string escape --style=url \na\nb%c~d\n)'
string unescape --style=url (string escape --style=url \na\nb%c~d\n)
echo
echo '# string unescape --style=var (string escape --style=var \'a b#c"\\\'d\')'
logmsg 'string unescape --style=var (string escape --style=var \'a b#c"\\\'d\')'
string unescape --style=var (string escape --style=var 'a b#c"\'d')
echo
echo '# string unescape --style=var (string escape --style=var a\nghi_)'
logmsg 'string unescape --style=var (string escape --style=var a\nghi_)'
string unescape --style=var (string escape --style=var a\nghi_)
echo
echo '# string unescape --style=var (string escape --style=var \'abc\')'
logmsg 'string unescape --style=var (string escape --style=var \'abc\')'
string unescape --style=var (string escape --style=var 'abc')
echo
echo '# string unescape --style=var (string escape --style=var \'_a_b_c_\')'
logmsg 'string unescape --style=var (string escape --style=var \'_a_b_c_\')'
string unescape --style=var (string escape --style=var '_a_b_c_')
echo
echo '# string unescape --style=var (string escape --style=var -- -)'
logmsg 'string unescape --style=var (string escape --style=var -- -)'
string unescape --style=var -- (string escape --style=var -- -)
# The following tests verify that we can correctly match strings.
echo
echo '# string match "?" a'
logmsg 'string match "?" a'
string match "?" a
echo
echo '# string match "a*b" axxb'
logmsg 'string match "a*b" axxb'
string match "a*b" axxb
echo
echo '# string match -i "a??B" Axxb'
logmsg 'string match -i "a??B" Axxb'
string match -i "a??B" Axxb
echo
echo '# echo "ok?" | string match "*\?"'
logmsg 'echo "ok?" | string match "*\?"'
echo "ok?" | string match "*\?"
echo
echo '# string match -r "cat|dog|fish" "nice dog"'
logmsg 'string match -r "cat|dog|fish" "nice dog"'
string match -r "cat|dog|fish" "nice dog"
echo
echo '# string match -r "(\d\d?):(\d\d):(\d\d)" 2:34:56'
logmsg 'string match -r "(\d\d?):(\d\d):(\d\d)" 2:34:56'
string match -r "(\d\d?):(\d\d):(\d\d)" 2:34:56
echo
echo '# string match -r "^(\w{2,4})\g1\$" papa mud murmur'
logmsg 'string match -r "^(\w{2,4})\g1\$" papa mud murmur'
string match -r "^(\w{2,4})\g1\$" papa mud murmur
echo
echo '# string match -r -a -n at ratatat'
logmsg 'string match -r -a -n at ratatat'
string match -r -a -n at ratatat
echo
echo '# string match -r -i "0x[0-9a-f]{1,8}" "int magic = 0xBadC0de;"'
logmsg 'string match -r -i "0x[0-9a-f]{1,8}" "int magic = 0xBadC0de;"'
string match -r -i "0x[0-9a-f]{1,8}" "int magic = 0xBadC0de;"
echo
echo '# string replace is was "blue is my favorite"'
logmsg 'string replace is was "blue is my favorite"'
string replace is was "blue is my favorite"
echo
echo '# string replace 3rd last 1st 2nd 3rd'
logmsg 'string replace 3rd last 1st 2nd 3rd'
string replace 3rd last 1st 2nd 3rd
echo
echo '# string replace -a " " _ "spaces to underscores"'
logmsg 'string replace -a " " _ "spaces to underscores"'
string replace -a " " _ "spaces to underscores"
echo
echo '# string replace -r -a "[^\d.]+" " " "0 one two 3.14 four 5x"'
logmsg 'string replace -r -a "[^\d.]+" " " "0 one two 3.14 four 5x"'
string replace -r -a "[^\d.]+" " " "0 one two 3.14 four 5x"
echo
echo '# string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"'
logmsg 'string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"'
string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"
echo
echo '# string replace -r "\s*newline\s*" "\n" "put a newline here"'
logmsg 'string replace -r "\s*newline\s*" "\n" "put a newline here"'
string replace -r "\s*newline\s*" "\n" "put a newline here"
echo
echo '# string replace -r -a "(\w)" "\$1\$1" ab'
logmsg 'string replace -r -a "(\w)" "\$1\$1" ab'
string replace -r -a "(\w)" "\$1\$1" ab
echo
echo '# string replace --filter x X abc axc x def jkx'
logmsg 'string replace --filter x X abc axc x def jkx'
string replace --filter x X abc axc x def jkx
or echo Unexpected exit status at line (status --current-line-number)
string replace --filter y Y abc axc x def jkx
and echo Unexpected exit status at line (status --current-line-number)
echo
echo '# string replace --regex -f "\d" X 1bc axc 2 d3f jk4 xyz'
logmsg 'string replace --regex -f "\d" X 1bc axc 2 d3f jk4 xyz'
string replace --regex -f "\d" X 1bc axc 2 d3f jk4 xyz
or echo Unexpected exit status at line (status --current-line-number)
@ -243,152 +187,118 @@ string replace --regex -f "Z" X 1bc axc 2 d3f jk4 xyz
and echo Unexpected exit status at line (status --current-line-number)
# test some failure cases
echo '# string match -r "[" "a[sd"' >&2
string match -r "[" "a[sd"; and echo "unexpected exit 0" >&2
logmsg 'string match -r "[" "a[sd"'
string match -r "[" "a[sd"; and echo "unexpected exit 0"
echo >&2
echo '# string invalidarg' >&2
string invalidarg; and echo "unexpected exit 0" >&2
logmsg 'string invalidarg'
string invalidarg; and echo "unexpected exit 0"
echo
echo '# string length'
logmsg 'string length'
string length; or echo "missing argument returns 1"
echo
echo '# string match -r -v "[dcantg].*" dog can cat diz'
logmsg 'string match -r -v "[dcantg].*" dog can cat diz'
string match -r -v "[dcantg].*" dog can cat diz; or echo "no regexp invert match"
echo
echo '# string match -v "???" dog can cat diz'
logmsg 'string match -v "???" dog can cat diz'
string match -v "???" dog can cat diz; or echo "no glob invert match"
echo
echo '# string match -rvn a bbb'
logmsg 'string match -rvn a bbb'
string match -rvn a bbb; or echo "exit 1"
# test repeat subcommand
echo
echo '# string repeat -n 2 "foo"'
logmsg 'string repeat -n 2 "foo"'
string repeat -n 2 "foo"
echo
echo '# string repeat --count 2 "foo"'
logmsg 'string repeat --count 2 "foo"'
string repeat --count 2 "foo"
echo
echo '# echo foo | string repeat -n 2'
logmsg 'echo foo | string repeat -n 2'
echo foo | string repeat -n 2
echo
echo '# string repeat -n2 -q "foo"'
logmsg 'string repeat -n2 -q "foo"'
string repeat -n2 -q "foo"; and echo "exit 0"
echo
echo '# string repeat -n2 --quiet "foo"'
logmsg 'string repeat -n2 --quiet "foo"'
string repeat -n2 --quiet "foo"; and echo "exit 0"
echo
echo '# string repeat -n0 "foo"'
logmsg 'string repeat -n0 "foo"'
string repeat -n0 "foo"; or echo "exit 1"
echo
echo '# string repeat -n0'
logmsg 'string repeat -n0'
string repeat -n0; or echo "exit 1"
echo
echo '# string repeat -m0'
logmsg 'string repeat -m0'
string repeat -m0; or echo "exit 1"
echo
echo '# string repeat -n1 -N "there is "'
logmsg 'string repeat -n1 -N "there is "'
string repeat -n1 -N "there is "; echo "no newline"
echo
echo '# string repeat -n1 --no-newline "there is "'
logmsg 'string repeat -n1 --no-newline "there is "'
string repeat -n1 --no-newline "there is "; echo "no newline"
echo
echo '# string repeat -n10 -m4 "foo"'
logmsg 'string repeat -n10 -m4 "foo"'
string repeat -n10 -m4 "foo"
echo
echo '# string repeat -n10 --max 5 "foo"'
logmsg 'string repeat -n10 --max 5 "foo"'
string repeat -n10 --max 5 "foo"
echo
echo '# string repeat -n3 -m20 "foo"'
logmsg 'string repeat -n3 -m20 "foo"'
string repeat -n3 -m20 "foo"
echo
echo '# string repeat -m4 "foo"'
logmsg 'string repeat -m4 "foo"'
string repeat -m4 "foo"
echo >&2
echo '# string repeat -n-1 "foo"' >&2
string repeat -n-1 "foo"; and echo "exit 0" >&2
logmsg 'string repeat -n-1 "foo"'
string repeat -n-1 "foo"; and echo "exit 0"
echo >&2
echo '# string repeat -m-1 "foo"' >&2
string repeat -m-1 "foo"; and echo "exit 0" >&2
logmsg 'string repeat -m-1 "foo"'
string repeat -m-1 "foo"; and echo "exit 0"
echo >&2
echo '# string repeat -n notanumber "foo"' >&2
string repeat -n notanumber "foo"; and echo "exit 0" >&2
logmsg 'string repeat -n notanumber "foo"'
string repeat -n notanumber "foo"; and echo "exit 0"
echo >&2
echo '# string repeat -m notanumber "foo"' >&2
string repeat -m notanumber "foo"; and echo "exit 0" >&2
logmsg 'string repeat -m notanumber "foo"'
string repeat -m notanumber "foo"; and echo "exit 0"
echo >&2
echo '# echo "stdin" | string repeat -n1 "and arg"' >&2
echo "stdin" | string repeat -n1 "and arg"; and echo "exit 0" >&2
logmsg 'echo "stdin" | string repeat -n1 "and arg"'
echo "stdin" | string repeat -n1 "and arg"; and echo "exit 0"
echo >&2
echo '# string repeat -n' >&2
string repeat -n; and echo "exit 0" >&2
logmsg 'string repeat -n'
string repeat -n; and echo "exit 0"
echo >&2
echo '# string repeat -l fakearg 2>&1' >&2
logmsg 'string repeat -l fakearg 2>&1'
string repeat -l fakearg
echo
echo '# string repeat ""'
logmsg 'string repeat ""'
string repeat ""
or echo string repeat empty string failed
echo
echo '# string repeat -n3 ""'
logmsg 'string repeat -n3 ""'
string repeat -n3 ""
or echo string repeat empty string failed
# Test equivalent matches with/without the --entire, --regex, and --invert flags.
echo
echo '# string match -e x abc dxf xyz jkx x z'
logmsg 'string match -e x abc dxf xyz jkx x z'
string match -e x abc dxf xyz jkx x z
or echo exit 1
echo
echo '# string match x abc dxf xyz jkx x z'
logmsg 'string match x abc dxf xyz jkx x z'
string match x abc dxf xyz jkx x z
echo
echo '# string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
logmsg 'string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
or echo exit 1
echo
echo '# string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
logmsg 'string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
or echo exit 1
# Make sure that groups are handled correct with/without --entire.
echo
echo '# string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
logmsg 'string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
or echo exit 1
echo
echo '# string match -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
logmsg 'string match -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
string match -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
or echo exit 1

View file

@ -1,273 +1,381 @@
####################
# string match -r -v "c.*" dog can cat diz
dog
diz
exit 0
####################
# string match -q -r -v "c.*" dog can cat diz
exit 0
####################
# string match -v "c*" dog can cat diz
dog
diz
exit 0
####################
# string match -q -v "c*" dog can cat diz
exit 0
####################
# string match -v "d*" dog dan dat diz
exit 1
####################
# string match -q -v "d*" dog dan dat diz
exit 1
####################
# string match -r -v x y
y
exit 0
####################
# string match -r -v x x
exit 1
####################
# string match -q -r -v x y
exit 0
####################
# string match -q -r -v x x
exit 1
####################
# string length "hello, world"
12
####################
# string length -q ""
zero length
####################
# string sub --length 2 abcde
ab
####################
# string sub -s 2 -l 2 abcde
bc
####################
# string sub --start=-2 abcde
de
####################
# string split . example.com
example
com
####################
# string split -r -m1 / /usr/local/bin/fish
/usr/local/bin
fish
####################
# string split "" abc
a
b
c
####################
# seq 3 | string join ...
1...2...3
####################
# string trim " abc "
abc
####################
# string trim --right --chars=yz xyzzy zany
x
zan
####################
# echo \x07 | string escape
\cg
####################
# string escape --style=script 'a b#c"\'d'
a\ b\#c\"\'d
####################
# string escape --style=url 'a b#c"\'d'
a%20b%23c%22%27d
####################
# string escape --style=url \na\nb%c~d\n
%0Aa%0Ab%25c~d%0A
####################
# string escape --style=var 'a b#c"\'d'
a_20_b_23_c_22_27_d
####################
# string escape --style=script a\nghi_
a_0A_ghi__
####################
# string escape --style=var 'abc'
abc
####################
# string escape --style=var '_a_b_c_'
__a__b__c__
####################
# string escape --style=var -- -
_2D_
####################
# set x (string unescape (echo \x07 | string escape))
success
####################
# string unescape --style=script (string escape --style=script 'a b#c"\'d')
a b#c"'d
####################
# string unescape --style=url (string escape --style=url 'a b#c"\'d')
a b#c"'d
####################
# string unescape --style=url (string escape --style=url \na\nb%c~d\n)
a
b%c~d
####################
# string unescape --style=var (string escape --style=var 'a b#c"\'d')
a b#c"'d
####################
# string unescape --style=var (string escape --style=var a\nghi_)
a
ghi_
####################
# string unescape --style=var (string escape --style=var 'abc')
abc
####################
# string unescape --style=var (string escape --style=var '_a_b_c_')
_a_b_c_
####################
# string unescape --style=var (string escape --style=var -- -)
-
####################
# string match "?" a
a
####################
# string match "a*b" axxb
axxb
####################
# string match -i "a??B" Axxb
Axxb
####################
# echo "ok?" | string match "*\?"
ok?
####################
# string match -r "cat|dog|fish" "nice dog"
dog
####################
# string match -r "(\d\d?):(\d\d):(\d\d)" 2:34:56
2:34:56
2
34
56
####################
# string match -r "^(\w{2,4})\g1\$" papa mud murmur
papa
pa
murmur
mur
####################
# string match -r -a -n at ratatat
2 2
4 2
6 2
####################
# string match -r -i "0x[0-9a-f]{1,8}" "int magic = 0xBadC0de;"
0xBadC0de
####################
# string replace is was "blue is my favorite"
blue was my favorite
####################
# string replace 3rd last 1st 2nd 3rd
1st
2nd
last
####################
# string replace -a " " _ "spaces to underscores"
spaces_to_underscores
####################
# string replace -r -a "[^\d.]+" " " "0 one two 3.14 four 5x"
0 3.14 5
####################
# string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"
right left $
####################
# string replace -r "\s*newline\s*" "\n" "put a newline here"
put a
here
####################
# string replace -r -a "(\w)" "\$1\$1" ab
aabb
####################
# string replace --filter x X abc axc x def jkx
aXc
X
jkX
####################
# string replace --regex -f "\d" X 1bc axc 2 d3f jk4 xyz
Xbc
X
dXf
jkX
####################
# string match -r "[" "a[sd"
####################
# string invalidarg
####################
# string length
missing argument returns 1
####################
# string match -r -v "[dcantg].*" dog can cat diz
no regexp invert match
####################
# string match -v "???" dog can cat diz
no glob invert match
####################
# string match -rvn a bbb
1 3
####################
# string repeat -n 2 "foo"
foofoo
####################
# string repeat --count 2 "foo"
foofoo
####################
# echo foo | string repeat -n 2
foofoo
####################
# string repeat -n2 -q "foo"
exit 0
####################
# string repeat -n2 --quiet "foo"
exit 0
####################
# string repeat -n0 "foo"
exit 1
####################
# string repeat -n0
exit 1
####################
# string repeat -m0
exit 1
####################
# string repeat -n1 -N "there is "
there is no newline
####################
# string repeat -n1 --no-newline "there is "
there is no newline
####################
# string repeat -n10 -m4 "foo"
foof
####################
# string repeat -n10 --max 5 "foo"
foofo
####################
# string repeat -n3 -m20 "foo"
foofoofoo
####################
# string repeat -m4 "foo"
foof
####################
# string repeat -n-1 "foo"
####################
# string repeat -m-1 "foo"
####################
# string repeat -n notanumber "foo"
####################
# string repeat -m notanumber "foo"
####################
# echo "stdin" | string repeat -n1 "and arg"
####################
# string repeat -n
####################
# string repeat -l fakearg 2>&1
####################
# string repeat ""
string repeat empty string failed
####################
# string repeat -n3 ""
string repeat empty string failed
####################
# string match -e x abc dxf xyz jkx x z
dxf
xyz
jkx
x
####################
# string match x abc dxf xyz jkx x z
x
####################
# string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
abxc
bye
@ -276,6 +384,7 @@ kaabxz
abbxy
caabxyxz
####################
# string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
abx
by
@ -284,6 +393,7 @@ aabx
bxy
aabxyx
####################
# string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
abxc
x
@ -298,6 +408,7 @@ xy
caabxyxz
xyx
####################
# string match -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
abx
x