mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
use new logmsg
and set --show
in tests
This commit is contained in:
parent
e198ed0b2d
commit
a4ed0837a1
3 changed files with 473 additions and 193 deletions
265
tests/string.err
265
tests/string.err
|
@ -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 -r "[" "a[sd"
|
||||||
string match: Regular expression compile error: missing terminating ] for character class
|
string match: Regular expression compile error: missing terminating ] for character class
|
||||||
string match: [
|
string match: [
|
||||||
string match: ^
|
string match: ^
|
||||||
|
|
||||||
|
####################
|
||||||
# string invalidarg
|
# string invalidarg
|
||||||
string: Subcommand 'invalidarg' is not valid
|
string: Subcommand 'invalidarg' is not valid
|
||||||
Standard input (line 251):
|
Standard input (line 194):
|
||||||
string invalidarg; and echo "unexpected exit 0" >&2
|
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 -n-1 "foo"
|
||||||
string repeat: Invalid count value '-1'
|
string repeat: Invalid count value '-1'
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -m-1 "foo"
|
# string repeat -m-1 "foo"
|
||||||
string repeat: Invalid max value '-1'
|
string repeat: Invalid max value '-1'
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -n notanumber "foo"
|
# string repeat -n notanumber "foo"
|
||||||
string repeat: Argument 'notanumber' is not a number
|
string repeat: Argument 'notanumber' is not a number
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -m notanumber "foo"
|
# string repeat -m notanumber "foo"
|
||||||
string repeat: Argument 'notanumber' is not a number
|
string repeat: Argument 'notanumber' is not a number
|
||||||
|
|
||||||
|
####################
|
||||||
# echo "stdin" | string repeat -n1 "and arg"
|
# echo "stdin" | string repeat -n1 "and arg"
|
||||||
string repeat: Too many arguments
|
string repeat: Too many arguments
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -n
|
# string repeat -n
|
||||||
string repeat: Expected argument
|
string repeat: Expected argument
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -l fakearg 2>&1
|
# string repeat -l fakearg 2>&1
|
||||||
string repeat: Unknown option '-l'
|
string repeat: Unknown option '-l'
|
||||||
Standard input (line 352):
|
Standard input (line 270):
|
||||||
string repeat -l fakearg
|
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
|
||||||
|
|
290
tests/string.in
290
tests/string.in
|
@ -1,241 +1,185 @@
|
||||||
# Tests for string builtin. Mostly taken from man page examples.
|
# 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"
|
string match -r -v "c.*" dog can cat diz; and echo "exit 0"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -q -r -v "c.*" dog can cat diz'
|
||||||
echo '# string match -q -r -v "c.*" dog can cat diz'
|
|
||||||
string match -q -r -v "c.*" dog can cat diz; and echo "exit 0"
|
string match -q -r -v "c.*" dog can cat diz; and echo "exit 0"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -v "c*" dog can cat diz'
|
||||||
echo '# string match -v "c*" dog can cat diz'
|
|
||||||
string match -v "c*" dog can cat diz; and echo "exit 0"
|
string match -v "c*" dog can cat diz; and echo "exit 0"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -q -v "c*" dog can cat diz'
|
||||||
echo '# string match -q -v "c*" dog can cat diz'
|
|
||||||
string match -q -v "c*" dog can cat diz; and echo "exit 0"
|
string match -q -v "c*" dog can cat diz; and echo "exit 0"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -v "d*" dog dan dat diz'
|
||||||
echo '# string match -v "d*" dog dan dat diz'
|
|
||||||
string match -v "d*" dog dan dat diz; or echo "exit 1"
|
string match -v "d*" dog dan dat diz; or echo "exit 1"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -q -v "d*" dog dan dat diz'
|
||||||
echo '# string match -q -v "d*" dog dan dat diz'
|
|
||||||
string match -q -v "d*" dog dan dat diz; or echo "exit 1"
|
string match -q -v "d*" dog dan dat diz; or echo "exit 1"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -r -v x y'
|
||||||
echo '# string match -r -v x y'
|
|
||||||
string match -r -v x y; and echo "exit 0"
|
string match -r -v x y; and echo "exit 0"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -r -v x x'
|
||||||
echo '# string match -r -v x x'
|
|
||||||
string match -r -v x x; or echo "exit 1"
|
string match -r -v x x; or echo "exit 1"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -q -r -v x y'
|
||||||
echo '# string match -q -r -v x y'
|
|
||||||
string match -q -r -v x y; and echo "exit 0"
|
string match -q -r -v x y; and echo "exit 0"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -q -r -v x x'
|
||||||
echo '# string match -q -r -v x x'
|
|
||||||
string match -q -r -v x x; or echo "exit 1"
|
string match -q -r -v x x; or echo "exit 1"
|
||||||
|
|
||||||
echo
|
logmsg 'string length "hello, world"'
|
||||||
echo '# string length "hello, world"'
|
|
||||||
string length "hello, world"
|
string length "hello, world"
|
||||||
|
|
||||||
echo
|
logmsg 'string length -q ""'
|
||||||
echo '# string length -q ""'
|
|
||||||
string length -q ""; and echo not zero length; or echo zero length
|
string length -q ""; and echo not zero length; or echo zero length
|
||||||
|
|
||||||
echo
|
logmsg 'string sub --length 2 abcde'
|
||||||
echo '# string sub --length 2 abcde'
|
|
||||||
string sub --length 2 abcde
|
string sub --length 2 abcde
|
||||||
|
|
||||||
echo
|
logmsg 'string sub -s 2 -l 2 abcde'
|
||||||
echo '# string sub -s 2 -l 2 abcde'
|
|
||||||
string sub -s 2 -l 2 abcde
|
string sub -s 2 -l 2 abcde
|
||||||
|
|
||||||
echo
|
logmsg 'string sub --start=-2 abcde'
|
||||||
echo '# string sub --start=-2 abcde'
|
|
||||||
string sub --start=-2 abcde
|
string sub --start=-2 abcde
|
||||||
|
|
||||||
echo
|
logmsg 'string split . example.com'
|
||||||
echo '# string split . example.com'
|
|
||||||
string split . example.com
|
string split . example.com
|
||||||
|
|
||||||
echo
|
logmsg 'string split -r -m1 / /usr/local/bin/fish'
|
||||||
echo '# string split -r -m1 / /usr/local/bin/fish'
|
|
||||||
string split -r -m1 / /usr/local/bin/fish
|
string split -r -m1 / /usr/local/bin/fish
|
||||||
|
|
||||||
echo
|
logmsg 'string split "" abc'
|
||||||
echo '# string split "" abc'
|
|
||||||
string split "" abc
|
string split "" abc
|
||||||
|
|
||||||
echo
|
logmsg 'seq 3 | string join ...'
|
||||||
echo '# seq 3 | string join ...'
|
|
||||||
seq 3 | string join ...
|
seq 3 | string join ...
|
||||||
|
|
||||||
echo
|
logmsg 'string trim " abc "'
|
||||||
echo '# string trim " abc "'
|
|
||||||
string trim " abc "
|
string trim " abc "
|
||||||
|
|
||||||
echo
|
logmsg 'string trim --right --chars=yz xyzzy zany'
|
||||||
echo '# string trim --right --chars=yz xyzzy zany'
|
|
||||||
string trim --right --chars=yz xyzzy zany
|
string trim --right --chars=yz xyzzy zany
|
||||||
|
|
||||||
echo
|
logmsg 'echo \x07 | string escape'
|
||||||
echo '# echo \x07 | string escape'
|
|
||||||
echo \x07 | string escape
|
echo \x07 | string escape
|
||||||
|
|
||||||
echo
|
logmsg 'string escape --style=script \'a b#c"\\\'d\''
|
||||||
echo '# string escape --style=script \'a b#c"\\\'d\''
|
|
||||||
string escape --style=script 'a b#c"\'d'
|
string escape --style=script 'a b#c"\'d'
|
||||||
|
|
||||||
echo
|
logmsg 'string escape --style=url \'a b#c"\\\'d\''
|
||||||
echo '# string escape --style=url \'a b#c"\\\'d\''
|
|
||||||
string escape --style=url 'a b#c"\'d'
|
string escape --style=url 'a b#c"\'d'
|
||||||
|
|
||||||
echo
|
logmsg 'string escape --style=url \\na\\nb%c~d\\n'
|
||||||
echo '# string escape --style=url \\na\\nb%c~d\\n'
|
|
||||||
string escape --style=url \na\nb%c~d\n
|
string escape --style=url \na\nb%c~d\n
|
||||||
|
|
||||||
echo
|
logmsg 'string escape --style=var \'a b#c"\\\'d\''
|
||||||
echo '# string escape --style=var \'a b#c"\\\'d\''
|
|
||||||
string escape --style=var 'a b#c"\'d'
|
string escape --style=var 'a b#c"\'d'
|
||||||
|
|
||||||
echo
|
logmsg 'string escape --style=script a\nghi_'
|
||||||
echo '# string escape --style=script a\nghi_'
|
|
||||||
string escape --style=var a\nghi_
|
string escape --style=var a\nghi_
|
||||||
|
|
||||||
echo
|
logmsg 'string escape --style=var \'abc\''
|
||||||
echo '# string escape --style=var \'abc\''
|
|
||||||
string escape --style=var 'abc'
|
string escape --style=var 'abc'
|
||||||
|
|
||||||
echo
|
logmsg 'string escape --style=var \'_a_b_c_\''
|
||||||
echo '# string escape --style=var \'_a_b_c_\''
|
|
||||||
string escape --style=var '_a_b_c_'
|
string escape --style=var '_a_b_c_'
|
||||||
|
|
||||||
echo
|
logmsg 'string escape --style=var -- -'
|
||||||
echo '# string escape --style=var -- -'
|
|
||||||
string escape --style=var -- -
|
string escape --style=var -- -
|
||||||
|
|
||||||
# The following tests verify that we can correctly unescape the same strings
|
# The following tests verify that we can correctly unescape the same strings
|
||||||
# we tested escaping above.
|
# we tested escaping above.
|
||||||
|
|
||||||
echo
|
logmsg 'set x (string unescape (echo \x07 | string escape))'
|
||||||
echo '# set x (string unescape (echo \x07 | string escape))'
|
|
||||||
set x (string unescape (echo \x07 | string escape))
|
set x (string unescape (echo \x07 | string escape))
|
||||||
test $x = \x07
|
test $x = \x07
|
||||||
and echo success
|
and echo success
|
||||||
|
|
||||||
echo
|
logmsg 'string unescape --style=script (string escape --style=script \'a b#c"\\\'d\')'
|
||||||
echo '# string unescape --style=script (string escape --style=script \'a b#c"\\\'d\')'
|
|
||||||
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
|
logmsg 'string unescape --style=url (string escape --style=url \'a b#c"\\\'d\')'
|
||||||
echo '# string unescape --style=url (string escape --style=url \'a b#c"\\\'d\')'
|
|
||||||
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
|
logmsg 'string unescape --style=url (string escape --style=url \na\nb%c~d\n)'
|
||||||
echo '# 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)
|
string unescape --style=url (string escape --style=url \na\nb%c~d\n)
|
||||||
|
|
||||||
echo
|
logmsg 'string unescape --style=var (string escape --style=var \'a b#c"\\\'d\')'
|
||||||
echo '# string unescape --style=var (string escape --style=var \'a b#c"\\\'d\')'
|
|
||||||
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
|
logmsg 'string unescape --style=var (string escape --style=var a\nghi_)'
|
||||||
echo '# string unescape --style=var (string escape --style=var a\nghi_)'
|
|
||||||
string unescape --style=var (string escape --style=var a\nghi_)
|
string unescape --style=var (string escape --style=var a\nghi_)
|
||||||
|
|
||||||
echo
|
logmsg 'string unescape --style=var (string escape --style=var \'abc\')'
|
||||||
echo '# string unescape --style=var (string escape --style=var \'abc\')'
|
|
||||||
string unescape --style=var (string escape --style=var 'abc')
|
string unescape --style=var (string escape --style=var 'abc')
|
||||||
|
|
||||||
echo
|
logmsg 'string unescape --style=var (string escape --style=var \'_a_b_c_\')'
|
||||||
echo '# string unescape --style=var (string escape --style=var \'_a_b_c_\')'
|
|
||||||
string unescape --style=var (string escape --style=var '_a_b_c_')
|
string unescape --style=var (string escape --style=var '_a_b_c_')
|
||||||
|
|
||||||
echo
|
logmsg 'string unescape --style=var (string escape --style=var -- -)'
|
||||||
echo '# string unescape --style=var (string escape --style=var -- -)'
|
|
||||||
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.
|
# The following tests verify that we can correctly match strings.
|
||||||
|
|
||||||
echo
|
logmsg 'string match "?" a'
|
||||||
echo '# string match "?" a'
|
|
||||||
string match "?" a
|
string match "?" a
|
||||||
|
|
||||||
echo
|
logmsg 'string match "a*b" axxb'
|
||||||
echo '# string match "a*b" axxb'
|
|
||||||
string match "a*b" axxb
|
string match "a*b" axxb
|
||||||
|
|
||||||
echo
|
logmsg 'string match -i "a??B" Axxb'
|
||||||
echo '# string match -i "a??B" Axxb'
|
|
||||||
string match -i "a??B" Axxb
|
string match -i "a??B" Axxb
|
||||||
|
|
||||||
echo
|
logmsg 'echo "ok?" | string match "*\?"'
|
||||||
echo '# echo "ok?" | string match "*\?"'
|
|
||||||
echo "ok?" | string match "*\?"
|
echo "ok?" | string match "*\?"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -r "cat|dog|fish" "nice dog"'
|
||||||
echo '# string match -r "cat|dog|fish" "nice dog"'
|
|
||||||
string match -r "cat|dog|fish" "nice dog"
|
string match -r "cat|dog|fish" "nice dog"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -r "(\d\d?):(\d\d):(\d\d)" 2:34:56'
|
||||||
echo '# string match -r "(\d\d?):(\d\d):(\d\d)" 2:34:56'
|
|
||||||
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
|
logmsg 'string match -r "^(\w{2,4})\g1\$" papa mud murmur'
|
||||||
echo '# string match -r "^(\w{2,4})\g1\$" papa mud murmur'
|
|
||||||
string match -r "^(\w{2,4})\g1\$" papa mud murmur
|
string match -r "^(\w{2,4})\g1\$" papa mud murmur
|
||||||
|
|
||||||
echo
|
logmsg 'string match -r -a -n at ratatat'
|
||||||
echo '# string match -r -a -n at ratatat'
|
|
||||||
string match -r -a -n at ratatat
|
string match -r -a -n at ratatat
|
||||||
|
|
||||||
echo
|
logmsg 'string match -r -i "0x[0-9a-f]{1,8}" "int magic = 0xBadC0de;"'
|
||||||
echo '# 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;"
|
string match -r -i "0x[0-9a-f]{1,8}" "int magic = 0xBadC0de;"
|
||||||
|
|
||||||
echo
|
logmsg 'string replace is was "blue is my favorite"'
|
||||||
echo '# string replace is was "blue is my favorite"'
|
|
||||||
string replace is was "blue is my favorite"
|
string replace is was "blue is my favorite"
|
||||||
|
|
||||||
echo
|
logmsg 'string replace 3rd last 1st 2nd 3rd'
|
||||||
echo '# string replace 3rd last 1st 2nd 3rd'
|
|
||||||
string replace 3rd last 1st 2nd 3rd
|
string replace 3rd last 1st 2nd 3rd
|
||||||
|
|
||||||
echo
|
logmsg 'string replace -a " " _ "spaces to underscores"'
|
||||||
echo '# string replace -a " " _ "spaces to underscores"'
|
|
||||||
string replace -a " " _ "spaces to underscores"
|
string replace -a " " _ "spaces to underscores"
|
||||||
|
|
||||||
echo
|
logmsg 'string replace -r -a "[^\d.]+" " " "0 one two 3.14 four 5x"'
|
||||||
echo '# string replace -r -a "[^\d.]+" " " "0 one two 3.14 four 5x"'
|
|
||||||
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
|
logmsg 'string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"'
|
||||||
echo '# string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"'
|
|
||||||
string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"
|
string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"
|
||||||
|
|
||||||
echo
|
logmsg 'string replace -r "\s*newline\s*" "\n" "put a newline here"'
|
||||||
echo '# string replace -r "\s*newline\s*" "\n" "put a newline here"'
|
|
||||||
string replace -r "\s*newline\s*" "\n" "put a newline here"
|
string replace -r "\s*newline\s*" "\n" "put a newline here"
|
||||||
|
|
||||||
echo
|
logmsg 'string replace -r -a "(\w)" "\$1\$1" ab'
|
||||||
echo '# string replace -r -a "(\w)" "\$1\$1" ab'
|
|
||||||
string replace -r -a "(\w)" "\$1\$1" ab
|
string replace -r -a "(\w)" "\$1\$1" ab
|
||||||
|
|
||||||
echo
|
logmsg 'string replace --filter x X abc axc x def jkx'
|
||||||
echo '# string replace --filter x X abc axc x def jkx'
|
|
||||||
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)
|
or echo Unexpected exit status at line (status --current-line-number)
|
||||||
|
|
||||||
string replace --filter y Y abc axc x def jkx
|
string replace --filter y Y abc axc x def jkx
|
||||||
and echo Unexpected exit status at line (status --current-line-number)
|
and echo Unexpected exit status at line (status --current-line-number)
|
||||||
|
|
||||||
echo
|
logmsg 'string replace --regex -f "\d" X 1bc axc 2 d3f jk4 xyz'
|
||||||
echo '# string replace --regex -f "\d" X 1bc axc 2 d3f jk4 xyz'
|
|
||||||
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)
|
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)
|
and echo Unexpected exit status at line (status --current-line-number)
|
||||||
|
|
||||||
# test some failure cases
|
# test some failure cases
|
||||||
echo '# string match -r "[" "a[sd"' >&2
|
logmsg 'string match -r "[" "a[sd"'
|
||||||
string match -r "[" "a[sd"; and echo "unexpected exit 0" >&2
|
string match -r "[" "a[sd"; and echo "unexpected exit 0"
|
||||||
|
|
||||||
echo >&2
|
logmsg 'string invalidarg'
|
||||||
echo '# string invalidarg' >&2
|
string invalidarg; and echo "unexpected exit 0"
|
||||||
string invalidarg; and echo "unexpected exit 0" >&2
|
|
||||||
|
|
||||||
echo
|
logmsg 'string length'
|
||||||
echo '# string length'
|
|
||||||
string length; or echo "missing argument returns 1"
|
string length; or echo "missing argument returns 1"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -r -v "[dcantg].*" dog can cat diz'
|
||||||
echo '# string match -r -v "[dcantg].*" dog can cat diz'
|
|
||||||
string match -r -v "[dcantg].*" dog can cat diz; or echo "no regexp invert match"
|
string match -r -v "[dcantg].*" dog can cat diz; or echo "no regexp invert match"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -v "???" dog can cat diz'
|
||||||
echo '# string match -v "???" dog can cat diz'
|
|
||||||
string match -v "???" dog can cat diz; or echo "no glob invert match"
|
string match -v "???" dog can cat diz; or echo "no glob invert match"
|
||||||
|
|
||||||
echo
|
logmsg 'string match -rvn a bbb'
|
||||||
echo '# string match -rvn a bbb'
|
|
||||||
string match -rvn a bbb; or echo "exit 1"
|
string match -rvn a bbb; or echo "exit 1"
|
||||||
|
|
||||||
# test repeat subcommand
|
# test repeat subcommand
|
||||||
echo
|
logmsg 'string repeat -n 2 "foo"'
|
||||||
echo '# string repeat -n 2 "foo"'
|
|
||||||
string repeat -n 2 "foo"
|
string repeat -n 2 "foo"
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat --count 2 "foo"'
|
||||||
echo '# string repeat --count 2 "foo"'
|
|
||||||
string repeat --count 2 "foo"
|
string repeat --count 2 "foo"
|
||||||
|
|
||||||
echo
|
logmsg 'echo foo | string repeat -n 2'
|
||||||
echo '# echo foo | string repeat -n 2'
|
|
||||||
echo foo | string repeat -n 2
|
echo foo | string repeat -n 2
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat -n2 -q "foo"'
|
||||||
echo '# string repeat -n2 -q "foo"'
|
|
||||||
string repeat -n2 -q "foo"; and echo "exit 0"
|
string repeat -n2 -q "foo"; and echo "exit 0"
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat -n2 --quiet "foo"'
|
||||||
echo '# string repeat -n2 --quiet "foo"'
|
|
||||||
string repeat -n2 --quiet "foo"; and echo "exit 0"
|
string repeat -n2 --quiet "foo"; and echo "exit 0"
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat -n0 "foo"'
|
||||||
echo '# string repeat -n0 "foo"'
|
|
||||||
string repeat -n0 "foo"; or echo "exit 1"
|
string repeat -n0 "foo"; or echo "exit 1"
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat -n0'
|
||||||
echo '# string repeat -n0'
|
|
||||||
string repeat -n0; or echo "exit 1"
|
string repeat -n0; or echo "exit 1"
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat -m0'
|
||||||
echo '# string repeat -m0'
|
|
||||||
string repeat -m0; or echo "exit 1"
|
string repeat -m0; or echo "exit 1"
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat -n1 -N "there is "'
|
||||||
echo '# string repeat -n1 -N "there is "'
|
|
||||||
string repeat -n1 -N "there is "; echo "no newline"
|
string repeat -n1 -N "there is "; echo "no newline"
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat -n1 --no-newline "there is "'
|
||||||
echo '# string repeat -n1 --no-newline "there is "'
|
|
||||||
string repeat -n1 --no-newline "there is "; echo "no newline"
|
string repeat -n1 --no-newline "there is "; echo "no newline"
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat -n10 -m4 "foo"'
|
||||||
echo '# string repeat -n10 -m4 "foo"'
|
|
||||||
string repeat -n10 -m4 "foo"
|
string repeat -n10 -m4 "foo"
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat -n10 --max 5 "foo"'
|
||||||
echo '# string repeat -n10 --max 5 "foo"'
|
|
||||||
string repeat -n10 --max 5 "foo"
|
string repeat -n10 --max 5 "foo"
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat -n3 -m20 "foo"'
|
||||||
echo '# string repeat -n3 -m20 "foo"'
|
|
||||||
string repeat -n3 -m20 "foo"
|
string repeat -n3 -m20 "foo"
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat -m4 "foo"'
|
||||||
echo '# string repeat -m4 "foo"'
|
|
||||||
string repeat -m4 "foo"
|
string repeat -m4 "foo"
|
||||||
|
|
||||||
echo >&2
|
logmsg 'string repeat -n-1 "foo"'
|
||||||
echo '# string repeat -n-1 "foo"' >&2
|
string repeat -n-1 "foo"; and echo "exit 0"
|
||||||
string repeat -n-1 "foo"; and echo "exit 0" >&2
|
|
||||||
|
|
||||||
echo >&2
|
logmsg 'string repeat -m-1 "foo"'
|
||||||
echo '# string repeat -m-1 "foo"' >&2
|
string repeat -m-1 "foo"; and echo "exit 0"
|
||||||
string repeat -m-1 "foo"; and echo "exit 0" >&2
|
|
||||||
|
|
||||||
echo >&2
|
logmsg 'string repeat -n notanumber "foo"'
|
||||||
echo '# string repeat -n notanumber "foo"' >&2
|
string repeat -n notanumber "foo"; and echo "exit 0"
|
||||||
string repeat -n notanumber "foo"; and echo "exit 0" >&2
|
|
||||||
|
|
||||||
echo >&2
|
logmsg 'string repeat -m notanumber "foo"'
|
||||||
echo '# string repeat -m notanumber "foo"' >&2
|
string repeat -m notanumber "foo"; and echo "exit 0"
|
||||||
string repeat -m notanumber "foo"; and echo "exit 0" >&2
|
|
||||||
|
|
||||||
echo >&2
|
logmsg 'echo "stdin" | string repeat -n1 "and arg"'
|
||||||
echo '# echo "stdin" | string repeat -n1 "and arg"' >&2
|
echo "stdin" | string repeat -n1 "and arg"; and echo "exit 0"
|
||||||
echo "stdin" | string repeat -n1 "and arg"; and echo "exit 0" >&2
|
|
||||||
|
|
||||||
echo >&2
|
logmsg 'string repeat -n'
|
||||||
echo '# string repeat -n' >&2
|
string repeat -n; and echo "exit 0"
|
||||||
string repeat -n; and echo "exit 0" >&2
|
|
||||||
|
|
||||||
echo >&2
|
logmsg 'string repeat -l fakearg 2>&1'
|
||||||
echo '# string repeat -l fakearg 2>&1' >&2
|
|
||||||
string repeat -l fakearg
|
string repeat -l fakearg
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat ""'
|
||||||
echo '# string repeat ""'
|
|
||||||
string repeat ""
|
string repeat ""
|
||||||
or echo string repeat empty string failed
|
or echo string repeat empty string failed
|
||||||
|
|
||||||
echo
|
logmsg 'string repeat -n3 ""'
|
||||||
echo '# string repeat -n3 ""'
|
|
||||||
string repeat -n3 ""
|
string repeat -n3 ""
|
||||||
or echo string repeat empty string failed
|
or echo string repeat empty string failed
|
||||||
|
|
||||||
# Test equivalent matches with/without the --entire, --regex, and --invert flags.
|
# Test equivalent matches with/without the --entire, --regex, and --invert flags.
|
||||||
echo
|
logmsg 'string match -e x abc dxf xyz jkx x z'
|
||||||
echo '# string match -e x abc dxf xyz jkx x z'
|
|
||||||
string match -e x abc dxf xyz jkx x z
|
string match -e x abc dxf xyz jkx x z
|
||||||
or echo exit 1
|
or echo exit 1
|
||||||
|
|
||||||
echo
|
logmsg 'string match x abc dxf xyz jkx x z'
|
||||||
echo '# string match x abc dxf xyz jkx x z'
|
|
||||||
string match x abc dxf xyz jkx x z
|
string match x abc dxf xyz jkx x z
|
||||||
|
|
||||||
echo
|
logmsg 'string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
|
||||||
echo '# 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
|
string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
||||||
or echo exit 1
|
or echo exit 1
|
||||||
|
|
||||||
echo
|
logmsg 'string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
|
||||||
echo '# 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
|
string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
||||||
or echo exit 1
|
or echo exit 1
|
||||||
|
|
||||||
# Make sure that groups are handled correct with/without --entire.
|
# Make sure that groups are handled correct with/without --entire.
|
||||||
echo
|
logmsg 'string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
|
||||||
echo '# 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
|
string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
||||||
or echo exit 1
|
or echo exit 1
|
||||||
|
|
||||||
echo
|
logmsg 'string match -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
|
||||||
echo '# 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
|
string match -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
||||||
or echo exit 1
|
or echo exit 1
|
||||||
|
|
||||||
|
|
111
tests/string.out
111
tests/string.out
|
@ -1,273 +1,381 @@
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -r -v "c.*" dog can cat diz
|
# string match -r -v "c.*" dog can cat diz
|
||||||
dog
|
dog
|
||||||
diz
|
diz
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -q -r -v "c.*" dog can cat diz
|
# string match -q -r -v "c.*" dog can cat diz
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -v "c*" dog can cat diz
|
# string match -v "c*" dog can cat diz
|
||||||
dog
|
dog
|
||||||
diz
|
diz
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -q -v "c*" dog can cat diz
|
# string match -q -v "c*" dog can cat diz
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -v "d*" dog dan dat diz
|
# string match -v "d*" dog dan dat diz
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -q -v "d*" dog dan dat diz
|
# string match -q -v "d*" dog dan dat diz
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -r -v x y
|
# string match -r -v x y
|
||||||
y
|
y
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -r -v x x
|
# string match -r -v x x
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -q -r -v x y
|
# string match -q -r -v x y
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -q -r -v x x
|
# string match -q -r -v x x
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
|
####################
|
||||||
# string length "hello, world"
|
# string length "hello, world"
|
||||||
12
|
12
|
||||||
|
|
||||||
|
####################
|
||||||
# string length -q ""
|
# string length -q ""
|
||||||
zero length
|
zero length
|
||||||
|
|
||||||
|
####################
|
||||||
# string sub --length 2 abcde
|
# string sub --length 2 abcde
|
||||||
ab
|
ab
|
||||||
|
|
||||||
|
####################
|
||||||
# string sub -s 2 -l 2 abcde
|
# string sub -s 2 -l 2 abcde
|
||||||
bc
|
bc
|
||||||
|
|
||||||
|
####################
|
||||||
# string sub --start=-2 abcde
|
# string sub --start=-2 abcde
|
||||||
de
|
de
|
||||||
|
|
||||||
|
####################
|
||||||
# string split . example.com
|
# string split . example.com
|
||||||
example
|
example
|
||||||
com
|
com
|
||||||
|
|
||||||
|
####################
|
||||||
# string split -r -m1 / /usr/local/bin/fish
|
# string split -r -m1 / /usr/local/bin/fish
|
||||||
/usr/local/bin
|
/usr/local/bin
|
||||||
fish
|
fish
|
||||||
|
|
||||||
|
####################
|
||||||
# string split "" abc
|
# string split "" abc
|
||||||
a
|
a
|
||||||
b
|
b
|
||||||
c
|
c
|
||||||
|
|
||||||
|
####################
|
||||||
# seq 3 | string join ...
|
# seq 3 | string join ...
|
||||||
1...2...3
|
1...2...3
|
||||||
|
|
||||||
|
####################
|
||||||
# string trim " abc "
|
# string trim " abc "
|
||||||
abc
|
abc
|
||||||
|
|
||||||
|
####################
|
||||||
# string trim --right --chars=yz xyzzy zany
|
# string trim --right --chars=yz xyzzy zany
|
||||||
x
|
x
|
||||||
zan
|
zan
|
||||||
|
|
||||||
|
####################
|
||||||
# echo \x07 | string escape
|
# echo \x07 | string escape
|
||||||
\cg
|
\cg
|
||||||
|
|
||||||
|
####################
|
||||||
# string escape --style=script 'a b#c"\'d'
|
# string escape --style=script 'a b#c"\'d'
|
||||||
a\ b\#c\"\'d
|
a\ b\#c\"\'d
|
||||||
|
|
||||||
|
####################
|
||||||
# string escape --style=url 'a b#c"\'d'
|
# string escape --style=url 'a b#c"\'d'
|
||||||
a%20b%23c%22%27d
|
a%20b%23c%22%27d
|
||||||
|
|
||||||
|
####################
|
||||||
# string escape --style=url \na\nb%c~d\n
|
# string escape --style=url \na\nb%c~d\n
|
||||||
%0Aa%0Ab%25c~d%0A
|
%0Aa%0Ab%25c~d%0A
|
||||||
|
|
||||||
|
####################
|
||||||
# string escape --style=var 'a b#c"\'d'
|
# string escape --style=var 'a b#c"\'d'
|
||||||
a_20_b_23_c_22_27_d
|
a_20_b_23_c_22_27_d
|
||||||
|
|
||||||
|
####################
|
||||||
# string escape --style=script a\nghi_
|
# string escape --style=script a\nghi_
|
||||||
a_0A_ghi__
|
a_0A_ghi__
|
||||||
|
|
||||||
|
####################
|
||||||
# string escape --style=var 'abc'
|
# string escape --style=var 'abc'
|
||||||
abc
|
abc
|
||||||
|
|
||||||
|
####################
|
||||||
# string escape --style=var '_a_b_c_'
|
# string escape --style=var '_a_b_c_'
|
||||||
__a__b__c__
|
__a__b__c__
|
||||||
|
|
||||||
|
####################
|
||||||
# string escape --style=var -- -
|
# string escape --style=var -- -
|
||||||
_2D_
|
_2D_
|
||||||
|
|
||||||
|
####################
|
||||||
# set x (string unescape (echo \x07 | string escape))
|
# set x (string unescape (echo \x07 | string escape))
|
||||||
success
|
success
|
||||||
|
|
||||||
|
####################
|
||||||
# string unescape --style=script (string escape --style=script 'a b#c"\'d')
|
# string unescape --style=script (string escape --style=script 'a b#c"\'d')
|
||||||
a b#c"'d
|
a b#c"'d
|
||||||
|
|
||||||
|
####################
|
||||||
# string unescape --style=url (string escape --style=url 'a b#c"\'d')
|
# string unescape --style=url (string escape --style=url 'a b#c"\'d')
|
||||||
a b#c"'d
|
a b#c"'d
|
||||||
|
|
||||||
|
####################
|
||||||
# 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)
|
||||||
|
|
||||||
a
|
a
|
||||||
b%c~d
|
b%c~d
|
||||||
|
|
||||||
|
|
||||||
|
####################
|
||||||
# string unescape --style=var (string escape --style=var 'a b#c"\'d')
|
# string unescape --style=var (string escape --style=var 'a b#c"\'d')
|
||||||
a b#c"'d
|
a b#c"'d
|
||||||
|
|
||||||
|
####################
|
||||||
# string unescape --style=var (string escape --style=var a\nghi_)
|
# string unescape --style=var (string escape --style=var a\nghi_)
|
||||||
a
|
a
|
||||||
ghi_
|
ghi_
|
||||||
|
|
||||||
|
####################
|
||||||
# string unescape --style=var (string escape --style=var 'abc')
|
# string unescape --style=var (string escape --style=var 'abc')
|
||||||
abc
|
abc
|
||||||
|
|
||||||
|
####################
|
||||||
# string unescape --style=var (string escape --style=var '_a_b_c_')
|
# string unescape --style=var (string escape --style=var '_a_b_c_')
|
||||||
_a_b_c_
|
_a_b_c_
|
||||||
|
|
||||||
|
####################
|
||||||
# string unescape --style=var (string escape --style=var -- -)
|
# string unescape --style=var (string escape --style=var -- -)
|
||||||
-
|
-
|
||||||
|
|
||||||
|
####################
|
||||||
# string match "?" a
|
# string match "?" a
|
||||||
a
|
a
|
||||||
|
|
||||||
|
####################
|
||||||
# string match "a*b" axxb
|
# string match "a*b" axxb
|
||||||
axxb
|
axxb
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -i "a??B" Axxb
|
# string match -i "a??B" Axxb
|
||||||
Axxb
|
Axxb
|
||||||
|
|
||||||
|
####################
|
||||||
# echo "ok?" | string match "*\?"
|
# echo "ok?" | string match "*\?"
|
||||||
ok?
|
ok?
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -r "cat|dog|fish" "nice dog"
|
# string match -r "cat|dog|fish" "nice dog"
|
||||||
dog
|
dog
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -r "(\d\d?):(\d\d):(\d\d)" 2:34:56
|
# string match -r "(\d\d?):(\d\d):(\d\d)" 2:34:56
|
||||||
2:34:56
|
2:34:56
|
||||||
2
|
2
|
||||||
34
|
34
|
||||||
56
|
56
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -r "^(\w{2,4})\g1\$" papa mud murmur
|
# string match -r "^(\w{2,4})\g1\$" papa mud murmur
|
||||||
papa
|
papa
|
||||||
pa
|
pa
|
||||||
murmur
|
murmur
|
||||||
mur
|
mur
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -r -a -n at ratatat
|
# string match -r -a -n at ratatat
|
||||||
2 2
|
2 2
|
||||||
4 2
|
4 2
|
||||||
6 2
|
6 2
|
||||||
|
|
||||||
|
####################
|
||||||
# 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;"
|
||||||
0xBadC0de
|
0xBadC0de
|
||||||
|
|
||||||
|
####################
|
||||||
# string replace is was "blue is my favorite"
|
# string replace is was "blue is my favorite"
|
||||||
blue was my favorite
|
blue was my favorite
|
||||||
|
|
||||||
|
####################
|
||||||
# string replace 3rd last 1st 2nd 3rd
|
# string replace 3rd last 1st 2nd 3rd
|
||||||
1st
|
1st
|
||||||
2nd
|
2nd
|
||||||
last
|
last
|
||||||
|
|
||||||
|
####################
|
||||||
# string replace -a " " _ "spaces to underscores"
|
# string replace -a " " _ "spaces to underscores"
|
||||||
spaces_to_underscores
|
spaces_to_underscores
|
||||||
|
|
||||||
|
####################
|
||||||
# string replace -r -a "[^\d.]+" " " "0 one two 3.14 four 5x"
|
# string replace -r -a "[^\d.]+" " " "0 one two 3.14 four 5x"
|
||||||
0 3.14 5
|
0 3.14 5
|
||||||
|
|
||||||
|
####################
|
||||||
# string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"
|
# string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"
|
||||||
right left $
|
right left $
|
||||||
|
|
||||||
|
####################
|
||||||
# string replace -r "\s*newline\s*" "\n" "put a newline here"
|
# string replace -r "\s*newline\s*" "\n" "put a newline here"
|
||||||
put a
|
put a
|
||||||
here
|
here
|
||||||
|
|
||||||
|
####################
|
||||||
# string replace -r -a "(\w)" "\$1\$1" ab
|
# string replace -r -a "(\w)" "\$1\$1" ab
|
||||||
aabb
|
aabb
|
||||||
|
|
||||||
|
####################
|
||||||
# string replace --filter x X abc axc x def jkx
|
# string replace --filter x X abc axc x def jkx
|
||||||
aXc
|
aXc
|
||||||
X
|
X
|
||||||
jkX
|
jkX
|
||||||
|
|
||||||
|
####################
|
||||||
# string replace --regex -f "\d" X 1bc axc 2 d3f jk4 xyz
|
# string replace --regex -f "\d" X 1bc axc 2 d3f jk4 xyz
|
||||||
Xbc
|
Xbc
|
||||||
X
|
X
|
||||||
dXf
|
dXf
|
||||||
jkX
|
jkX
|
||||||
|
|
||||||
|
####################
|
||||||
|
# string match -r "[" "a[sd"
|
||||||
|
|
||||||
|
####################
|
||||||
|
# string invalidarg
|
||||||
|
|
||||||
|
####################
|
||||||
# string length
|
# string length
|
||||||
missing argument returns 1
|
missing argument returns 1
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -r -v "[dcantg].*" dog can cat diz
|
# string match -r -v "[dcantg].*" dog can cat diz
|
||||||
no regexp invert match
|
no regexp invert match
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -v "???" dog can cat diz
|
# string match -v "???" dog can cat diz
|
||||||
no glob invert match
|
no glob invert match
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -rvn a bbb
|
# string match -rvn a bbb
|
||||||
1 3
|
1 3
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -n 2 "foo"
|
# string repeat -n 2 "foo"
|
||||||
foofoo
|
foofoo
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat --count 2 "foo"
|
# string repeat --count 2 "foo"
|
||||||
foofoo
|
foofoo
|
||||||
|
|
||||||
|
####################
|
||||||
# echo foo | string repeat -n 2
|
# echo foo | string repeat -n 2
|
||||||
foofoo
|
foofoo
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -n2 -q "foo"
|
# string repeat -n2 -q "foo"
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -n2 --quiet "foo"
|
# string repeat -n2 --quiet "foo"
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -n0 "foo"
|
# string repeat -n0 "foo"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -n0
|
# string repeat -n0
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -m0
|
# string repeat -m0
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -n1 -N "there is "
|
# string repeat -n1 -N "there is "
|
||||||
there is no newline
|
there is no newline
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -n1 --no-newline "there is "
|
# string repeat -n1 --no-newline "there is "
|
||||||
there is no newline
|
there is no newline
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -n10 -m4 "foo"
|
# string repeat -n10 -m4 "foo"
|
||||||
foof
|
foof
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -n10 --max 5 "foo"
|
# string repeat -n10 --max 5 "foo"
|
||||||
foofo
|
foofo
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -n3 -m20 "foo"
|
# string repeat -n3 -m20 "foo"
|
||||||
foofoofoo
|
foofoofoo
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -m4 "foo"
|
# string repeat -m4 "foo"
|
||||||
foof
|
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 ""
|
||||||
string repeat empty string failed
|
string repeat empty string failed
|
||||||
|
|
||||||
|
####################
|
||||||
# string repeat -n3 ""
|
# string repeat -n3 ""
|
||||||
string repeat empty string failed
|
string repeat empty string failed
|
||||||
|
|
||||||
|
####################
|
||||||
# string match -e x abc dxf xyz jkx x z
|
# string match -e x abc dxf xyz jkx x z
|
||||||
dxf
|
dxf
|
||||||
xyz
|
xyz
|
||||||
jkx
|
jkx
|
||||||
x
|
x
|
||||||
|
|
||||||
|
####################
|
||||||
# string match x abc dxf xyz jkx x z
|
# string match x abc dxf xyz jkx x z
|
||||||
x
|
x
|
||||||
|
|
||||||
|
####################
|
||||||
# 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
|
||||||
abxc
|
abxc
|
||||||
bye
|
bye
|
||||||
|
@ -276,6 +384,7 @@ kaabxz
|
||||||
abbxy
|
abbxy
|
||||||
caabxyxz
|
caabxyxz
|
||||||
|
|
||||||
|
####################
|
||||||
# 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
|
||||||
abx
|
abx
|
||||||
by
|
by
|
||||||
|
@ -284,6 +393,7 @@ aabx
|
||||||
bxy
|
bxy
|
||||||
aabxyx
|
aabxyx
|
||||||
|
|
||||||
|
####################
|
||||||
# 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
|
||||||
abxc
|
abxc
|
||||||
x
|
x
|
||||||
|
@ -298,6 +408,7 @@ xy
|
||||||
caabxyxz
|
caabxyxz
|
||||||
xyx
|
xyx
|
||||||
|
|
||||||
|
####################
|
||||||
# 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
|
||||||
abx
|
abx
|
||||||
x
|
x
|
||||||
|
|
Loading…
Reference in a new issue