2017-04-25 04:05:51 +00:00
|
|
|
# Tests for string builtin. Mostly taken from man page examples.
|
2016-04-08 02:18:58 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -r -v "c.*" dog can cat diz'
|
2016-04-08 02:18:58 +00:00
|
|
|
string match -r -v "c.*" dog can cat diz; and echo "exit 0"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -q -r -v "c.*" dog can cat diz'
|
2016-04-08 02:18:58 +00:00
|
|
|
string match -q -r -v "c.*" dog can cat diz; and echo "exit 0"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -v "c*" dog can cat diz'
|
2016-04-08 02:18:58 +00:00
|
|
|
string match -v "c*" dog can cat diz; and echo "exit 0"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -q -v "c*" dog can cat diz'
|
2016-04-08 02:18:58 +00:00
|
|
|
string match -q -v "c*" dog can cat diz; and echo "exit 0"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -v "d*" dog dan dat diz'
|
2016-04-08 02:18:58 +00:00
|
|
|
string match -v "d*" dog dan dat diz; or echo "exit 1"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -q -v "d*" dog dan dat diz'
|
2016-04-08 02:18:58 +00:00
|
|
|
string match -q -v "d*" dog dan dat diz; or echo "exit 1"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -r -v x y'
|
2016-04-08 02:18:58 +00:00
|
|
|
string match -r -v x y; and echo "exit 0"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -r -v x x'
|
2016-04-08 02:18:58 +00:00
|
|
|
string match -r -v x x; or echo "exit 1"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -q -r -v x y'
|
2016-04-08 02:18:58 +00:00
|
|
|
string match -q -r -v x y; and echo "exit 0"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -q -r -v x x'
|
2016-04-08 02:18:58 +00:00
|
|
|
string match -q -r -v x x; or echo "exit 1"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string length "hello, world"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string length "hello, world"
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string length -q ""'
|
2017-04-25 04:05:51 +00:00
|
|
|
string length -q ""; and echo not zero length; or echo zero length
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string sub --length 2 abcde'
|
2015-10-09 03:27:18 +00:00
|
|
|
string sub --length 2 abcde
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string sub -s 2 -l 2 abcde'
|
2015-10-09 03:27:18 +00:00
|
|
|
string sub -s 2 -l 2 abcde
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string sub --start=-2 abcde'
|
2015-10-09 03:27:18 +00:00
|
|
|
string sub --start=-2 abcde
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string split . example.com'
|
2015-10-09 03:27:18 +00:00
|
|
|
string split . example.com
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string split -r -m1 / /usr/local/bin/fish'
|
2015-10-09 03:27:18 +00:00
|
|
|
string split -r -m1 / /usr/local/bin/fish
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string split "" abc'
|
2017-04-25 04:05:51 +00:00
|
|
|
string split "" abc
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'seq 3 | string join ...'
|
2015-10-09 03:27:18 +00:00
|
|
|
seq 3 | string join ...
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string trim " abc "'
|
2017-04-25 04:05:51 +00:00
|
|
|
string trim " abc "
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string trim --right --chars=yz xyzzy zany'
|
2015-10-09 03:27:18 +00:00
|
|
|
string trim --right --chars=yz xyzzy zany
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'echo \x07 | string escape'
|
2015-10-09 03:27:18 +00:00
|
|
|
echo \x07 | string escape
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string escape --style=script \'a b#c"\\\'d\''
|
2017-06-21 04:55:16 +00:00
|
|
|
string escape --style=script 'a b#c"\'d'
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string escape --style=url \'a b#c"\\\'d\''
|
2017-06-21 04:55:16 +00:00
|
|
|
string escape --style=url 'a b#c"\'d'
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string escape --style=url \\na\\nb%c~d\\n'
|
2017-06-21 04:55:16 +00:00
|
|
|
string escape --style=url \na\nb%c~d\n
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string escape --style=var \'a b#c"\\\'d\''
|
2017-06-21 04:55:16 +00:00
|
|
|
string escape --style=var 'a b#c"\'d'
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string escape --style=script a\nghi_'
|
2017-06-21 04:55:16 +00:00
|
|
|
string escape --style=var a\nghi_
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string escape --style=var \'abc\''
|
2017-06-21 04:55:16 +00:00
|
|
|
string escape --style=var 'abc'
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string escape --style=var \'_a_b_c_\''
|
2017-06-21 04:55:16 +00:00
|
|
|
string escape --style=var '_a_b_c_'
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string escape --style=var -- -'
|
2017-06-21 04:55:16 +00:00
|
|
|
string escape --style=var -- -
|
|
|
|
|
2018-11-07 11:37:47 +00:00
|
|
|
logmsg 'string escape with multibyte chars'
|
|
|
|
string escape --style=url aöb
|
|
|
|
string escape --style=url 中
|
|
|
|
string escape --style=url aöb | string unescape --style=url
|
|
|
|
string escape --style=url 中 | string unescape --style=url
|
|
|
|
|
|
|
|
string escape --style=var aöb
|
|
|
|
string escape --style=var 中
|
|
|
|
string escape --style=var aöb | string unescape --style=var
|
|
|
|
string escape --style=var 中 | string unescape --style=var
|
|
|
|
|
2018-11-15 05:30:11 +00:00
|
|
|
# test regex escaping
|
|
|
|
logmsg 'string escape for literal pcre2 searching'
|
2018-11-17 02:21:05 +00:00
|
|
|
string escape --style=regex ".ext"
|
|
|
|
string escape --style=regex "bonjour, amigo"
|
|
|
|
string escape --style=regex "^this is a literal string"
|
2018-11-15 05:30:11 +00:00
|
|
|
|
2017-06-23 03:47:54 +00:00
|
|
|
# The following tests verify that we can correctly unescape the same strings
|
|
|
|
# we tested escaping above.
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'set x (string unescape (echo \x07 | string escape))'
|
2017-06-23 03:47:54 +00:00
|
|
|
set x (string unescape (echo \x07 | string escape))
|
|
|
|
test $x = \x07
|
|
|
|
and echo success
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string unescape --style=script (string escape --style=script \'a b#c"\\\'d\')'
|
2017-06-23 03:47:54 +00:00
|
|
|
string unescape --style=script (string escape --style=script 'a b#c"\'d')
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string unescape --style=url (string escape --style=url \'a b#c"\\\'d\')'
|
2017-06-23 03:47:54 +00:00
|
|
|
string unescape --style=url (string escape --style=url 'a b#c"\'d')
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string unescape --style=url (string escape --style=url \na\nb%c~d\n)'
|
2017-06-23 03:47:54 +00:00
|
|
|
string unescape --style=url (string escape --style=url \na\nb%c~d\n)
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string unescape --style=var (string escape --style=var \'a b#c"\\\'d\')'
|
2017-06-23 03:47:54 +00:00
|
|
|
string unescape --style=var (string escape --style=var 'a b#c"\'d')
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string unescape --style=var (string escape --style=var a\nghi_)'
|
2017-06-23 03:47:54 +00:00
|
|
|
string unescape --style=var (string escape --style=var a\nghi_)
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string unescape --style=var (string escape --style=var \'abc\')'
|
2017-06-23 03:47:54 +00:00
|
|
|
string unescape --style=var (string escape --style=var 'abc')
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string unescape --style=var (string escape --style=var \'_a_b_c_\')'
|
2017-06-23 03:47:54 +00:00
|
|
|
string unescape --style=var (string escape --style=var '_a_b_c_')
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string unescape --style=var (string escape --style=var -- -)'
|
2017-06-23 03:47:54 +00:00
|
|
|
string unescape --style=var -- (string escape --style=var -- -)
|
|
|
|
|
|
|
|
# The following tests verify that we can correctly match strings.
|
|
|
|
|
2018-03-31 23:48:57 +00:00
|
|
|
logmsg 'string match "*" a'
|
|
|
|
string match "*" a
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match "a*b" axxb'
|
2017-04-25 04:05:51 +00:00
|
|
|
string match "a*b" axxb
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2018-03-31 23:48:57 +00:00
|
|
|
logmsg 'string match -i "a**B" Axxb'
|
|
|
|
string match -i "a**B" Axxb
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2018-03-31 23:48:57 +00:00
|
|
|
logmsg 'echo "ok?" | string match "*?"'
|
|
|
|
echo "ok?" | string match "*?"
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -r "cat|dog|fish" "nice dog"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string match -r "cat|dog|fish" "nice dog"
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -r "(\d\d?):(\d\d):(\d\d)" 2:34:56'
|
2017-04-25 04:05:51 +00:00
|
|
|
string match -r "(\d\d?):(\d\d):(\d\d)" 2:34:56
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -r "^(\w{2,4})\g1\$" papa mud murmur'
|
2017-04-25 04:05:51 +00:00
|
|
|
string match -r "^(\w{2,4})\g1\$" papa mud murmur
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -r -a -n at ratatat'
|
2015-10-09 03:27:18 +00:00
|
|
|
string match -r -a -n at ratatat
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -r -i "0x[0-9a-f]{1,8}" "int magic = 0xBadC0de;"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string match -r -i "0x[0-9a-f]{1,8}" "int magic = 0xBadC0de;"
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string replace is was "blue is my favorite"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string replace is was "blue is my favorite"
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string replace 3rd last 1st 2nd 3rd'
|
2015-10-09 03:27:18 +00:00
|
|
|
string replace 3rd last 1st 2nd 3rd
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string replace -a " " _ "spaces to underscores"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string replace -a " " _ "spaces to underscores"
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string replace -r -a "[^\d.]+" " " "0 one two 3.14 four 5x"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string replace -r -a "[^\d.]+" " " "0 one two 3.14 four 5x"
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string replace -r "\s*newline\s*" "\n" "put a newline here"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string replace -r "\s*newline\s*" "\n" "put a newline here"
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string replace -r -a "(\w)" "\$1\$1" ab'
|
2017-04-25 04:05:51 +00:00
|
|
|
string replace -r -a "(\w)" "\$1\$1" ab
|
2016-02-21 21:59:03 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string replace --filter x X abc axc x def jkx'
|
2017-04-28 04:53:39 +00:00
|
|
|
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)
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string replace --regex -f "\d" X 1bc axc 2 d3f jk4 xyz'
|
2017-04-28 04:53:39 +00:00
|
|
|
string replace --regex -f "\d" X 1bc axc 2 d3f jk4 xyz
|
|
|
|
or echo Unexpected exit status at line (status --current-line-number)
|
|
|
|
|
|
|
|
string replace --regex -f "Z" X 1bc axc 2 d3f jk4 xyz
|
|
|
|
and echo Unexpected exit status at line (status --current-line-number)
|
|
|
|
|
2019-05-29 15:14:19 +00:00
|
|
|
# From https://github.com/fish-shell/fish-shell/issues/5201
|
|
|
|
logmsg 'string match -r with empty capture groups'
|
|
|
|
string match -r '^([ugoa]*)([=+-]?)([rwx]*)$' '=r'
|
|
|
|
|
2015-10-09 03:27:18 +00:00
|
|
|
# test some failure cases
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -r "[" "a[sd"'
|
|
|
|
string match -r "[" "a[sd"; and echo "unexpected exit 0"
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string invalidarg'
|
|
|
|
string invalidarg; and echo "unexpected exit 0"
|
2015-10-09 03:27:18 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string length'
|
2017-04-25 04:05:51 +00:00
|
|
|
string length; or echo "missing argument returns 1"
|
2016-04-08 02:18:58 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -r -v "[dcantg].*" dog can cat diz'
|
2016-04-08 02:18:58 +00:00
|
|
|
string match -r -v "[dcantg].*" dog can cat diz; or echo "no regexp invert match"
|
|
|
|
|
2018-03-31 23:48:57 +00:00
|
|
|
logmsg 'string match -v "*" dog can cat diz'
|
|
|
|
string match -v "*" dog can cat diz; or echo "no glob invert match"
|
2016-05-31 21:14:03 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -rvn a bbb'
|
2017-04-25 04:05:51 +00:00
|
|
|
string match -rvn a bbb; or echo "exit 1"
|
2017-03-07 14:39:21 +00:00
|
|
|
|
|
|
|
# test repeat subcommand
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n 2 "foo"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat -n 2 "foo"
|
2017-03-07 14:39:21 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat --count 2 "foo"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat --count 2 "foo"
|
2017-03-07 14:39:21 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'echo foo | string repeat -n 2'
|
2017-03-07 14:39:21 +00:00
|
|
|
echo foo | string repeat -n 2
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n2 -q "foo"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat -n2 -q "foo"; and echo "exit 0"
|
2017-03-07 14:39:21 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n2 --quiet "foo"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat -n2 --quiet "foo"; and echo "exit 0"
|
2017-03-07 14:39:21 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n0 "foo"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat -n0 "foo"; or echo "exit 1"
|
2017-03-07 14:39:21 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n0'
|
2017-03-07 14:39:21 +00:00
|
|
|
string repeat -n0; or echo "exit 1"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -m0'
|
2017-03-07 14:39:21 +00:00
|
|
|
string repeat -m0; or echo "exit 1"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n1 -N "there is "'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat -n1 -N "there is "; echo "no newline"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n1 --no-newline "there is "'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat -n1 --no-newline "there is "; echo "no newline"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n10 -m4 "foo"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat -n10 -m4 "foo"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n10 --max 5 "foo"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat -n10 --max 5 "foo"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n3 -m20 "foo"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat -n3 -m20 "foo"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -m4 "foo"'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat -m4 "foo"
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n-1 "foo"'
|
|
|
|
string repeat -n-1 "foo"; and echo "exit 0"
|
2017-04-25 04:05:51 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -m-1 "foo"'
|
|
|
|
string repeat -m-1 "foo"; and echo "exit 0"
|
2017-04-25 04:05:51 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n notanumber "foo"'
|
|
|
|
string repeat -n notanumber "foo"; and echo "exit 0"
|
2017-04-25 04:05:51 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -m notanumber "foo"'
|
|
|
|
string repeat -m notanumber "foo"; and echo "exit 0"
|
2017-04-25 04:05:51 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'echo "stdin" | string repeat -n1 "and arg"'
|
|
|
|
echo "stdin" | string repeat -n1 "and arg"; and echo "exit 0"
|
2017-04-25 04:05:51 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n'
|
|
|
|
string repeat -n; and echo "exit 0"
|
2017-04-25 04:05:51 +00:00
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -l fakearg 2>&1'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat -l fakearg
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat ""'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat ""
|
|
|
|
or echo string repeat empty string failed
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string repeat -n3 ""'
|
2017-04-25 04:05:51 +00:00
|
|
|
string repeat -n3 ""
|
|
|
|
or echo string repeat empty string failed
|
|
|
|
|
2017-05-02 05:19:58 +00:00
|
|
|
# Test equivalent matches with/without the --entire, --regex, and --invert flags.
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -e x abc dxf xyz jkx x z'
|
2017-05-02 05:19:58 +00:00
|
|
|
string match -e x abc dxf xyz jkx x z
|
2017-04-25 04:05:51 +00:00
|
|
|
or echo exit 1
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match x abc dxf xyz jkx x z'
|
2017-04-25 04:05:51 +00:00
|
|
|
string match x abc dxf xyz jkx x z
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
|
2017-05-02 05:19:58 +00:00
|
|
|
string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
2017-04-25 04:05:51 +00:00
|
|
|
or echo exit 1
|
|
|
|
|
2018-09-16 11:03:15 +00:00
|
|
|
logmsg 'string match --entire "" -- banana'
|
|
|
|
string match --entire "" -- banana
|
|
|
|
or echo exit 1
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
|
2017-04-25 04:05:51 +00:00
|
|
|
string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
|
|
|
or echo exit 1
|
|
|
|
|
2017-05-02 05:19:58 +00:00
|
|
|
# Make sure that groups are handled correct with/without --entire.
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
|
2017-05-02 05:19:58 +00:00
|
|
|
string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
2017-04-25 04:05:51 +00:00
|
|
|
or echo exit 1
|
|
|
|
|
2017-08-04 19:51:48 +00:00
|
|
|
logmsg 'string match -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
|
2017-04-25 04:05:51 +00:00
|
|
|
string match -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
|
|
|
or echo exit 1
|
2017-03-15 20:55:53 +00:00
|
|
|
|
2017-06-11 00:35:25 +00:00
|
|
|
# Test `string lower` and `string upper`.
|
|
|
|
set x (string lower abc DEF gHi)
|
|
|
|
or echo string lower exit 1
|
|
|
|
test $x[1] = 'abc' -a $x[2] = 'def' -a $x[3] = 'ghi'
|
|
|
|
or echo strings not converted to lowercase
|
|
|
|
|
|
|
|
set x (echo abc DEF gHi | string lower)
|
|
|
|
or echo string lower exit 1
|
|
|
|
test $x[1] = 'abc def ghi'
|
|
|
|
or echo strings not converted to lowercase
|
|
|
|
|
|
|
|
string lower -q abc
|
|
|
|
and echo lowercasing a lowercase string did not fail as expected
|
|
|
|
|
|
|
|
set x (string upper abc DEF gHi)
|
|
|
|
or echo string upper exit 1
|
|
|
|
test $x[1] = 'ABC' -a $x[2] = 'DEF' -a $x[3] = 'GHI'
|
|
|
|
or echo strings not converted to uppercase
|
|
|
|
|
|
|
|
set x (echo abc DEF gHi | string upper)
|
|
|
|
or echo string upper exit 1
|
|
|
|
test $x[1] = 'ABC DEF GHI'
|
|
|
|
or echo strings not converted to uppercase
|
|
|
|
|
|
|
|
string upper -q ABC DEF
|
|
|
|
and echo uppercasing a uppercase string did not fail as expected
|
|
|
|
|
2018-05-11 14:47:29 +00:00
|
|
|
logmsg 'Check NUL'
|
|
|
|
# Note: We do `string escape` at the end to make a `\0` literal visible.
|
|
|
|
printf 'a\0b' | string escape
|
|
|
|
printf 'a\0c' | string match -e 'a' | string escape
|
|
|
|
printf 'a\0d' | string split '' | string escape
|
|
|
|
printf 'a\0b' | string match -r '.*b$' | string escape
|
|
|
|
printf 'a\0b' | string replace b g | string escape
|
|
|
|
printf 'a\0b' | string replace -r b g | string escape
|
|
|
|
# TODO: These do not yet work!
|
|
|
|
# printf 'a\0b' | string match '*b' | string escape
|
|
|
|
|
2018-05-30 04:11:50 +00:00
|
|
|
logmsg string split0
|
|
|
|
count (echo -ne 'abcdefghi' | string split0)
|
|
|
|
count (echo -ne 'abc\x00def\x00ghi\x00' | string split0)
|
|
|
|
count (echo -ne 'abc\x00def\x00ghi\x00\x00' | string split0)
|
|
|
|
count (echo -ne 'abc\x00def\x00ghi' | string split0)
|
|
|
|
count (echo -ne 'abc\ndef\x00ghi\x00' | string split0)
|
|
|
|
count (echo -ne 'abc\ndef\nghi' | string split0)
|
2019-02-26 18:50:53 +00:00
|
|
|
# #5701 - split0 always returned 1
|
|
|
|
echo -ne 'a\x00b' | string split0
|
|
|
|
and echo Split something
|
2018-05-30 04:11:50 +00:00
|
|
|
|
2018-06-24 21:03:13 +00:00
|
|
|
logmsg string join0
|
|
|
|
set tmp beta alpha\ngamma
|
|
|
|
count (string join \n $tmp)
|
|
|
|
count (string join0 $tmp)
|
|
|
|
count (string join0 $tmp | string split0)
|
|
|
|
|
2018-05-30 04:11:50 +00:00
|
|
|
logmsg string split0 in functions
|
|
|
|
# This function outputs some newline-separated content, and some
|
|
|
|
# explicitly separated content.
|
|
|
|
function dualsplit
|
|
|
|
echo alpha
|
|
|
|
echo beta
|
|
|
|
echo -ne 'gamma\x00delta' | string split0
|
|
|
|
end
|
|
|
|
count (dualsplit)
|
|
|
|
|
2019-06-16 05:30:31 +00:00
|
|
|
logmsg string collect
|
|
|
|
count (echo one\ntwo\nthree\nfour | string collect)
|
|
|
|
count (echo one | string collect)
|
|
|
|
echo [(echo one\ntwo\nthree | string collect)]
|
2019-06-16 23:40:14 +00:00
|
|
|
echo [(echo one\ntwo\nthree | string collect -N)]
|
2019-06-16 05:30:31 +00:00
|
|
|
printf '[%s]\n' (string collect one\n\n two\n)
|
2019-06-16 23:40:14 +00:00
|
|
|
printf '[%s]\n' (string collect -N one\n\n two\n)
|
|
|
|
printf '[%s]\n' (string collect --no-trim-newlines one\n\n two\n)
|
2019-06-16 05:30:31 +00:00
|
|
|
# string collect returns 0 when it has any output, otherwise 1
|
|
|
|
string collect >/dev/null; and echo unexpected success; or echo expected failure
|
|
|
|
echo -n | string collect >/dev/null; and echo unexpected success; or echo expected failure
|
2019-06-16 23:40:14 +00:00
|
|
|
echo | string collect -N >/dev/null; and echo expected success; or echo unexpected failure
|
|
|
|
echo | string collect >/dev/null; and echo unexpected success; or echo expected failure
|
2019-06-16 05:30:31 +00:00
|
|
|
string collect a >/dev/null; and echo expected success; or echo unexpected failure
|
2019-06-16 23:40:14 +00:00
|
|
|
string collect -N '' >/dev/null; and echo unexpected success; or echo expected failure
|
|
|
|
string collect \n\n >/dev/null; and echo unexpected success; or echo expected failure
|
2019-06-16 05:30:31 +00:00
|
|
|
|
|
|
|
logmsg string collect in functions
|
|
|
|
# This function outputs some newline-separated content, and some
|
|
|
|
# explicitly un-separated content.
|
|
|
|
function dualcollect
|
|
|
|
echo alpha
|
|
|
|
echo beta
|
|
|
|
echo gamma\ndelta\nomega | string collect
|
|
|
|
end
|
|
|
|
count (dualcollect)
|
|
|
|
|
2017-03-15 20:55:53 +00:00
|
|
|
exit 0
|