mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 15:31:51 +08:00
Remove ported tests
This commit is contained in:
parent
21667850b3
commit
b9c1f4b122
|
@ -1,128 +0,0 @@
|
|||
|
||||
####################
|
||||
# No args is an error
|
||||
argparse: No option specs were provided
|
||||
|
||||
####################
|
||||
# Missing -- is an error
|
||||
argparse: Missing -- separator
|
||||
|
||||
####################
|
||||
# Flags but no option specs is an error
|
||||
argparse: No option specs were provided
|
||||
|
||||
####################
|
||||
# Invalid option specs
|
||||
argparse: Invalid option spec 'h-' at char '-'
|
||||
argparse: Short flag '+' invalid, must be alphanum or '#'
|
||||
argparse: Invalid option spec 'h/help:' at char ':'
|
||||
argparse: Invalid option spec 'h-help::' at char ':'
|
||||
argparse: Invalid option spec 'h-help=x' at char 'x'
|
||||
|
||||
####################
|
||||
# --max-args and --min-args work
|
||||
min-max: Expected at least 1 args, got only 0
|
||||
min-max: Expected at most 3 args, got 4
|
||||
min-max: Expected at most 1 args, got 2
|
||||
|
||||
####################
|
||||
# Invalid "#-val" spec
|
||||
argparse: Implicit int short flag '#' does not allow modifiers like '='
|
||||
|
||||
####################
|
||||
# Invalid arg in the face of a "#-val" spec
|
||||
argparse: Unknown option '-x'
|
||||
Standard input (line 41):
|
||||
argparse '#-val' -- abc -x def
|
||||
^
|
||||
|
||||
####################
|
||||
# Defining a short flag more than once
|
||||
argparse: Short flag 's' already defined
|
||||
|
||||
####################
|
||||
# Defining a long flag more than once
|
||||
argparse: Long flag 'short' already defined
|
||||
|
||||
####################
|
||||
# Defining an implicit int flag more than once
|
||||
argparse: Implicit int flag '#' already defined
|
||||
|
||||
####################
|
||||
# Defining an implicit int flag with modifiers
|
||||
argparse: Implicit int short flag 'v' does not allow modifiers like '='
|
||||
|
||||
####################
|
||||
# No args
|
||||
|
||||
####################
|
||||
# One arg and no matching flags
|
||||
|
||||
####################
|
||||
# Five args with two matching a flag
|
||||
|
||||
####################
|
||||
# Required, optional, and multiple flags
|
||||
|
||||
####################
|
||||
# --stop-nonopt works
|
||||
|
||||
####################
|
||||
# Implicit int flags work
|
||||
|
||||
####################
|
||||
# Should be set to 987
|
||||
|
||||
####################
|
||||
# Should be set to 765
|
||||
|
||||
####################
|
||||
# Bool short flag only
|
||||
|
||||
####################
|
||||
# Value taking short flag only
|
||||
|
||||
####################
|
||||
# Implicit int short flag only
|
||||
|
||||
####################
|
||||
# Implicit int short flag only with custom validation passes
|
||||
|
||||
####################
|
||||
# Implicit int short flag only with custom validation fails
|
||||
argparse: Value '499' for flag 'x' less than min allowed of '500'
|
||||
|
||||
####################
|
||||
# Implicit int flag validation fails
|
||||
argparse: Value '765x' for flag 'max' is not an integer
|
||||
argparse: Value 'a1' for flag 'm' is not an integer
|
||||
|
||||
####################
|
||||
# Check the exit status from argparse validation
|
||||
|
||||
####################
|
||||
# Explicit int flag validation
|
||||
argparse: Value '2' for flag 'm' greater than max allowed of '1'
|
||||
argparse: Value '-1' for flag 'max' less than min allowed of '0'
|
||||
|
||||
####################
|
||||
# Errors use function name by default
|
||||
notargparse: Unknown option '--banana'
|
||||
Standard input (line 353):
|
||||
argparse a/alpha -- --banana
|
||||
^
|
||||
in function 'notargparse'
|
||||
|
||||
####################
|
||||
# Ignoring unknown options
|
||||
|
||||
####################
|
||||
# Check for crash when last option is unknown
|
||||
|
||||
####################
|
||||
# Checking arguments after --
|
||||
|
||||
####################
|
||||
# Checking validation for short flags only
|
||||
argparse: Value 'banana' for flag 'o' is not an integer
|
||||
argparse: Value '-o' for flag 'i' is not an integer
|
|
@ -1,206 +0,0 @@
|
|||
# Test the `argparse` builtin.
|
||||
|
||||
##########
|
||||
# Start by verifying a bunch of error conditions.
|
||||
|
||||
logmsg No args is an error
|
||||
argparse
|
||||
|
||||
logmsg Missing -- is an error
|
||||
argparse h/help
|
||||
|
||||
logmsg Flags but no option specs is an error
|
||||
argparse -s -- hello
|
||||
|
||||
logmsg Invalid option specs
|
||||
argparse h-
|
||||
argparse +help
|
||||
argparse h/help:
|
||||
argparse h-help::
|
||||
argparse h-help=x
|
||||
|
||||
logmsg --max-args and --min-args work
|
||||
begin
|
||||
argparse --name min-max --min-args 1 h/help --
|
||||
argparse --name min-max --min-args 1 --max-args 3 h/help -- arg1
|
||||
argparse --name min-max --min-args 1 --max-args 3 h/help -- arg1 arg2
|
||||
argparse --name min-max --min-args 1 --max-args 3 h/help -- --help arg1 arg2 arg3
|
||||
argparse --name min-max --min-args 1 --max-args 3 h/help -- arg1 arg2 -h arg3 arg4
|
||||
argparse --name min-max --max-args 1 h/help --
|
||||
argparse --name min-max --max-args 1 h/help -- arg1
|
||||
argparse --name min-max --max-args 1 h/help -- arg1 arg2
|
||||
end
|
||||
|
||||
logmsg Invalid \"#-val\" spec
|
||||
begin
|
||||
argparse '#-val=' -- abc -x def
|
||||
end
|
||||
|
||||
logmsg Invalid arg in the face of a \"#-val\" spec
|
||||
begin
|
||||
argparse '#-val' -- abc -x def
|
||||
end
|
||||
|
||||
logmsg Defining a short flag more than once
|
||||
begin
|
||||
argparse 's/short' 'x/xray' 's/long' -- -s -x --long
|
||||
end
|
||||
|
||||
logmsg Defining a long flag more than once
|
||||
begin
|
||||
argparse 's/short' 'x/xray' 'l/short' -- -s -x --long
|
||||
end
|
||||
|
||||
logmsg Defining an implicit int flag more than once
|
||||
begin
|
||||
argparse '#-val' 'x/xray' 'v#val' -- -s -x --long
|
||||
end
|
||||
|
||||
logmsg Defining an implicit int flag with modifiers
|
||||
begin
|
||||
argparse 'v#val=' --
|
||||
end
|
||||
|
||||
##########
|
||||
# Now verify that validly formed invocations work as expected.
|
||||
|
||||
logmsg No args
|
||||
begin
|
||||
argparse h/help --
|
||||
end
|
||||
|
||||
logmsg One arg and no matching flags
|
||||
begin
|
||||
argparse h/help -- help
|
||||
set -l
|
||||
end
|
||||
|
||||
logmsg Five args with two matching a flag
|
||||
begin
|
||||
argparse h/help -- help --help me -h 'a lot more'
|
||||
set -l
|
||||
end
|
||||
|
||||
logmsg Required, optional, and multiple flags
|
||||
begin
|
||||
argparse 'h/help' 'a/abc=' 'd/def=?' 'g/ghk=+' -- help --help me --ghk=g1 --abc=ABC --ghk g2 --d -g g3
|
||||
set -l
|
||||
end
|
||||
|
||||
logmsg --stop-nonopt works
|
||||
begin
|
||||
argparse --stop-nonopt 'h/help' 'a/abc=' -- -a A1 -h --abc A2 non-opt 'second non-opt' --help
|
||||
set -l
|
||||
end
|
||||
|
||||
logmsg Implicit int flags work
|
||||
begin
|
||||
argparse '#-val' -- abc -123 def
|
||||
set -l
|
||||
end
|
||||
begin
|
||||
argparse 'v/verbose' '#-val' 't/token=' -- -123 a1 --token woohoo --234 -v a2 --verbose
|
||||
set -l
|
||||
end
|
||||
|
||||
logmsg Should be set to 987
|
||||
begin
|
||||
argparse 'm#max' -- argle -987 bargle
|
||||
set -l
|
||||
end
|
||||
|
||||
logmsg Should be set to 765
|
||||
begin
|
||||
argparse 'm#max' -- argle -987 bargle --max 765
|
||||
set -l
|
||||
end
|
||||
|
||||
logmsg Bool short flag only
|
||||
begin
|
||||
argparse 'C' 'v' -- -C -v arg1 -v arg2
|
||||
set -l
|
||||
end
|
||||
|
||||
logmsg Value taking short flag only
|
||||
begin
|
||||
argparse 'x=' 'v/verbose' -- --verbose arg1 -v -x arg2
|
||||
set -l
|
||||
end
|
||||
|
||||
logmsg Implicit int short flag only
|
||||
begin
|
||||
argparse 'x#' 'v/verbose' -- -v -v argle -v -x 321 bargle
|
||||
set -l
|
||||
end
|
||||
|
||||
logmsg Implicit int short flag only with custom validation passes
|
||||
begin
|
||||
argparse 'x#!_validate_int --max 500' 'v/verbose' -- -v -v -x 499 -v
|
||||
set -l
|
||||
end
|
||||
|
||||
logmsg Implicit int short flag only with custom validation fails
|
||||
begin
|
||||
argparse 'x#!_validate_int --min 500' 'v/verbose' -- -v -v -x 499 -v
|
||||
set -l
|
||||
end
|
||||
|
||||
##########
|
||||
# Verify that flag value validation works.
|
||||
|
||||
logmsg Implicit int flag validation fails
|
||||
argparse 'm#max' -- argle --max 765x bargle
|
||||
and echo unxpected argparse return status >&2
|
||||
argparse 'm#max' -- argle -ma1 bargle
|
||||
and echo unxpected argparse return status >&2
|
||||
|
||||
logmsg Check the exit status from argparse validation
|
||||
argparse 'm#max!set | grep _flag_; function x; return 57; end; x' -- argle --max=83 bargle 2>&1
|
||||
set -l saved_status $status
|
||||
test $saved_status -eq 57
|
||||
and echo expected argparse return status $saved_status
|
||||
|
||||
logmsg Explicit int flag validation
|
||||
# These should fail
|
||||
argparse 'm#max!_validate_int --min 1 --max 1' -- argle -m2 bargle
|
||||
and echo unexpected argparse return status $status >&2
|
||||
argparse 'm#max!_validate_int --min 0 --max 1' -- argle --max=-1 bargle
|
||||
and echo unexpected argparse return status $status >&2
|
||||
# These should succeed
|
||||
argparse 'm/max=!_validate_int --min 0 --max 1' -- argle --max=0 bargle
|
||||
or echo unexpected argparse return status $status >&2
|
||||
argparse 'm/max=!_validate_int --min 0 --max 1' -- argle --max=1 bargle
|
||||
or echo unexpected argparse return status $status >&2
|
||||
|
||||
logmsg Errors use function name by default
|
||||
function notargparse
|
||||
argparse a/alpha -- --banana
|
||||
end
|
||||
notargparse
|
||||
|
||||
true
|
||||
|
||||
logmsg Ignoring unknown options
|
||||
argparse -i a=+ b=+ -- -a alpha -b bravo -t tango -a aaaa --wurst
|
||||
or echo unexpected argparse return status $status >&2
|
||||
# The unknown options are removed _entirely_.
|
||||
echo $argv
|
||||
echo $_flag_a
|
||||
|
||||
logmsg Check for crash when last option is unknown
|
||||
argparse -i b/break -- "-b kubectl get pods -l name=foo"
|
||||
|
||||
begin
|
||||
logmsg Checking arguments after "--"
|
||||
argparse a/alpha -- a --alpha -- b -a
|
||||
printf '%s\n' $argv
|
||||
end
|
||||
|
||||
# #5864 - short flag only with same validation function.
|
||||
logmsg Checking validation for short flags only
|
||||
argparse 'i=!_validate_int' 'o=!_validate_int' -- -i 2 -o banana
|
||||
argparse 'i=!_validate_int' 'o=!_validate_int' -- -i -o banana
|
||||
begin
|
||||
argparse 'i=!_validate_int' 'o=!_validate_int' -- -i 2 -o 3
|
||||
set -l
|
||||
end
|
|
@ -1,160 +0,0 @@
|
|||
|
||||
####################
|
||||
# No args is an error
|
||||
|
||||
####################
|
||||
# Missing -- is an error
|
||||
|
||||
####################
|
||||
# Flags but no option specs is an error
|
||||
|
||||
####################
|
||||
# Invalid option specs
|
||||
|
||||
####################
|
||||
# --max-args and --min-args work
|
||||
|
||||
####################
|
||||
# Invalid "#-val" spec
|
||||
|
||||
####################
|
||||
# Invalid arg in the face of a "#-val" spec
|
||||
|
||||
####################
|
||||
# Defining a short flag more than once
|
||||
|
||||
####################
|
||||
# Defining a long flag more than once
|
||||
|
||||
####################
|
||||
# Defining an implicit int flag more than once
|
||||
|
||||
####################
|
||||
# Defining an implicit int flag with modifiers
|
||||
|
||||
####################
|
||||
# No args
|
||||
|
||||
####################
|
||||
# One arg and no matching flags
|
||||
argv help
|
||||
|
||||
####################
|
||||
# Five args with two matching a flag
|
||||
_flag_h '--help' '-h'
|
||||
_flag_help '--help' '-h'
|
||||
argv 'help' 'me' 'a lot more'
|
||||
|
||||
####################
|
||||
# Required, optional, and multiple flags
|
||||
_flag_a ABC
|
||||
_flag_abc ABC
|
||||
_flag_d
|
||||
_flag_def
|
||||
_flag_g 'g1' 'g2' 'g3'
|
||||
_flag_ghk 'g1' 'g2' 'g3'
|
||||
_flag_h --help
|
||||
_flag_help --help
|
||||
argv 'help' 'me'
|
||||
|
||||
####################
|
||||
# --stop-nonopt works
|
||||
_flag_a A2
|
||||
_flag_abc A2
|
||||
_flag_h -h
|
||||
_flag_help -h
|
||||
argv 'non-opt' 'second non-opt' '--help'
|
||||
|
||||
####################
|
||||
# Implicit int flags work
|
||||
_flag_val 123
|
||||
argv 'abc' 'def'
|
||||
_flag_t woohoo
|
||||
_flag_token woohoo
|
||||
_flag_v '-v' '--verbose'
|
||||
_flag_val -234
|
||||
_flag_verbose '-v' '--verbose'
|
||||
argv 'a1' 'a2'
|
||||
|
||||
####################
|
||||
# Should be set to 987
|
||||
_flag_m 987
|
||||
_flag_max 987
|
||||
argv 'argle' 'bargle'
|
||||
|
||||
####################
|
||||
# Should be set to 765
|
||||
_flag_m 765
|
||||
_flag_max 765
|
||||
argv 'argle' 'bargle'
|
||||
|
||||
####################
|
||||
# Bool short flag only
|
||||
_flag_C -C
|
||||
_flag_v '-v' '-v'
|
||||
argv 'arg1' 'arg2'
|
||||
|
||||
####################
|
||||
# Value taking short flag only
|
||||
_flag_v '--verbose' '-v'
|
||||
_flag_verbose '--verbose' '-v'
|
||||
_flag_x arg2
|
||||
argv arg1
|
||||
|
||||
####################
|
||||
# Implicit int short flag only
|
||||
_flag_v '-v' '-v' '-v'
|
||||
_flag_verbose '-v' '-v' '-v'
|
||||
_flag_x 321
|
||||
argv 'argle' 'bargle'
|
||||
|
||||
####################
|
||||
# Implicit int short flag only with custom validation passes
|
||||
_flag_v '-v' '-v' '-v'
|
||||
_flag_verbose '-v' '-v' '-v'
|
||||
_flag_x 499
|
||||
argv
|
||||
|
||||
####################
|
||||
# Implicit int short flag only with custom validation fails
|
||||
|
||||
####################
|
||||
# Implicit int flag validation fails
|
||||
|
||||
####################
|
||||
# Check the exit status from argparse validation
|
||||
_flag_name max
|
||||
_flag_value 83
|
||||
expected argparse return status 57
|
||||
|
||||
####################
|
||||
# Explicit int flag validation
|
||||
|
||||
####################
|
||||
# Errors use function name by default
|
||||
|
||||
####################
|
||||
# Ignoring unknown options
|
||||
-t tango --wurst
|
||||
alpha aaaa
|
||||
|
||||
####################
|
||||
# Check for crash when last option is unknown
|
||||
|
||||
####################
|
||||
# Checking arguments after --
|
||||
a
|
||||
b
|
||||
-a
|
||||
|
||||
####################
|
||||
# Checking validation for short flags only
|
||||
_flag_a 'alpha' 'aaaa'
|
||||
_flag_b -b
|
||||
_flag_break -b
|
||||
_flag_i 2
|
||||
_flag_m 1
|
||||
_flag_max 1
|
||||
_flag_o 3
|
||||
argv
|
||||
saved_status 57
|
|
@ -1 +0,0 @@
|
|||
-c "echo 1.2.3.4."
|
|
@ -1 +0,0 @@
|
|||
1.2.3.4.
|
|
@ -1 +0,0 @@
|
|||
-c "echo 1.2.3.4." -c "echo 5.6.7.8."
|
|
@ -1,2 +0,0 @@
|
|||
1.2.3.4.
|
||||
5.6.7.8.
|
|
@ -1 +0,0 @@
|
|||
-c 'set foo bar' -c 'echo $foo'
|
|
@ -1 +0,0 @@
|
|||
bar
|
|
@ -1 +0,0 @@
|
|||
--features 'no-stderr-nocaret' -c 'status test-feature stderr-nocaret; echo nocaret: $status'
|
|
@ -1 +0,0 @@
|
|||
nocaret: 1
|
|
@ -1 +0,0 @@
|
|||
--features 'stderr-nocaret' -c 'status test-feature stderr-nocaret; echo nocaret: $status'
|
|
@ -1 +0,0 @@
|
|||
nocaret: 0
|
|
@ -1 +0,0 @@
|
|||
--features 'no-stderr-nocaret' -c 'echo -n careton:; echo ^/dev/null'
|
|
@ -1 +0,0 @@
|
|||
careton:
|
|
@ -1 +0,0 @@
|
|||
--features ' stderr-nocaret' -c 'echo -n "caretoff: "; echo ^/dev/null'
|
|
@ -1 +0,0 @@
|
|||
caretoff: ^/dev/null
|
|
@ -1 +0,0 @@
|
|||
--features 'qmark-noglob' -C 'string match --quiet "??" ab ; echo "qmarkoff: $status"'
|
|
@ -1 +0,0 @@
|
|||
qmarkoff: 1
|
|
@ -1 +0,0 @@
|
|||
--features 'no-string-replace-fewer-backslashes' -C 'string replace -ra "\\\\" "\\\\\\\\" -- "a\b\c"'
|
|
@ -1 +0,0 @@
|
|||
a\b\c
|
|
@ -1 +0,0 @@
|
|||
--features 'string-replace-fewer-backslashes' -C 'string replace -ra "\\\\" "\\\\\\\\" -- "a\b\c"'
|
|
@ -1 +0,0 @@
|
|||
a\\b\\c
|
|
@ -1 +0,0 @@
|
|||
-C 'echo init-command' -C 'echo 2nd init-command'
|
|
@ -1,2 +0,0 @@
|
|||
init-command
|
||||
2nd init-command
|
|
@ -1 +0,0 @@
|
|||
-c 'echo command' -C 'echo init-command'
|
|
@ -1,2 +0,0 @@
|
|||
init-command
|
||||
command
|
|
@ -1 +0,0 @@
|
|||
-C 'echo init-command' -c 'echo command'
|
|
@ -1,2 +0,0 @@
|
|||
init-command
|
||||
command
|
|
@ -1 +0,0 @@
|
|||
-C 'echo init-command'
|
|
@ -1 +0,0 @@
|
|||
init-command
|
|
@ -1,3 +0,0 @@
|
|||
-c 'if status --is-login ; echo login shell ; else ; echo not login shell ; end'
|
||||
-c 'if status --is-interactive ; echo interactive ; else ; echo not interactive ; end'
|
||||
-i
|
|
@ -1,2 +0,0 @@
|
|||
not login shell
|
||||
interactive
|
|
@ -1,4 +0,0 @@
|
|||
-c 'if status --is-login ; echo login shell ; else ; echo not login shell ; end'
|
||||
-c 'if status --is-interactive ; echo interactive ; else ; echo not interactive ; end'
|
||||
-l
|
||||
-i
|
|
@ -1,2 +0,0 @@
|
|||
login shell
|
||||
interactive
|
|
@ -1,3 +0,0 @@
|
|||
-c 'if status --is-login ; echo login shell ; else ; echo not login shell ; end'
|
||||
-c 'if status --is-interactive ; echo interactive ; else ; echo not interactive ; end'
|
||||
-l
|
|
@ -1,2 +0,0 @@
|
|||
login shell
|
||||
not interactive
|
|
@ -1,2 +0,0 @@
|
|||
-c 'if status --is-login ; echo login shell ; else ; echo not login shell ; end'
|
||||
-c 'if status --is-interactive ; echo interactive ; else ; echo not interactive ; end'
|
|
@ -1,2 +0,0 @@
|
|||
not login shell
|
||||
not interactive
|
|
@ -1 +0,0 @@
|
|||
RC: 1
|
|
@ -1 +0,0 @@
|
|||
-c 'false'
|
|
@ -1 +0,0 @@
|
|||
^fish, version
|
|
@ -1 +0,0 @@
|
|||
-v
|
|
@ -1 +0,0 @@
|
|||
fish, version
|
329
tests/string.err
329
tests/string.err
|
@ -1,329 +0,0 @@
|
|||
|
||||
####################
|
||||
# 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 -- -
|
||||
|
||||
####################
|
||||
# string escape with multibyte chars
|
||||
|
||||
####################
|
||||
# string escape for literal pcre2 searching
|
||||
|
||||
####################
|
||||
# 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 with empty capture groups
|
||||
|
||||
####################
|
||||
# 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 215):
|
||||
string invalidarg; and echo "unexpected exit 0"
|
||||
^
|
||||
|
||||
(Type 'help string' for related documentation)
|
||||
|
||||
####################
|
||||
# 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 291):
|
||||
string repeat -l fakearg
|
||||
^
|
||||
|
||||
(Type 'help string' for related documentation)
|
||||
|
||||
####################
|
||||
# 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 --entire "" -- banana
|
||||
|
||||
####################
|
||||
# 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
|
||||
|
||||
####################
|
||||
# Check NUL
|
||||
|
||||
####################
|
||||
# string split0
|
||||
|
||||
####################
|
||||
# string join0
|
||||
|
||||
####################
|
||||
# string split0 in functions
|
||||
|
||||
####################
|
||||
# string collect
|
||||
|
||||
####################
|
||||
# string collect in functions
|
422
tests/string.in
422
tests/string.in
|
@ -1,422 +0,0 @@
|
|||
# Tests for string builtin. Mostly taken from man page examples.
|
||||
|
||||
logmsg 'string match -r -v "c.*" dog can cat diz'
|
||||
string match -r -v "c.*" dog can cat diz; and echo "exit 0"
|
||||
|
||||
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"
|
||||
|
||||
logmsg 'string match -v "c*" dog can cat diz'
|
||||
string match -v "c*" dog can cat diz; and echo "exit 0"
|
||||
|
||||
logmsg 'string match -q -v "c*" dog can cat diz'
|
||||
string match -q -v "c*" dog can cat diz; and echo "exit 0"
|
||||
|
||||
logmsg 'string match -v "d*" dog dan dat diz'
|
||||
string match -v "d*" dog dan dat diz; or echo "exit 1"
|
||||
|
||||
logmsg 'string match -q -v "d*" dog dan dat diz'
|
||||
string match -q -v "d*" dog dan dat diz; or echo "exit 1"
|
||||
|
||||
logmsg 'string match -r -v x y'
|
||||
string match -r -v x y; and echo "exit 0"
|
||||
|
||||
logmsg 'string match -r -v x x'
|
||||
string match -r -v x x; or echo "exit 1"
|
||||
|
||||
logmsg 'string match -q -r -v x y'
|
||||
string match -q -r -v x y; and echo "exit 0"
|
||||
|
||||
logmsg 'string match -q -r -v x x'
|
||||
string match -q -r -v x x; or echo "exit 1"
|
||||
|
||||
logmsg 'string length "hello, world"'
|
||||
string length "hello, world"
|
||||
|
||||
logmsg 'string length -q ""'
|
||||
string length -q ""; and echo not zero length; or echo zero length
|
||||
|
||||
logmsg 'string sub --length 2 abcde'
|
||||
string sub --length 2 abcde
|
||||
|
||||
logmsg 'string sub -s 2 -l 2 abcde'
|
||||
string sub -s 2 -l 2 abcde
|
||||
|
||||
logmsg 'string sub --start=-2 abcde'
|
||||
string sub --start=-2 abcde
|
||||
|
||||
logmsg 'string split . example.com'
|
||||
string split . example.com
|
||||
|
||||
logmsg 'string split -r -m1 / /usr/local/bin/fish'
|
||||
string split -r -m1 / /usr/local/bin/fish
|
||||
|
||||
logmsg 'string split "" abc'
|
||||
string split "" abc
|
||||
|
||||
logmsg 'seq 3 | string join ...'
|
||||
seq 3 | string join ...
|
||||
|
||||
logmsg 'string trim " abc "'
|
||||
string trim " abc "
|
||||
|
||||
logmsg 'string trim --right --chars=yz xyzzy zany'
|
||||
string trim --right --chars=yz xyzzy zany
|
||||
|
||||
logmsg 'echo \x07 | string escape'
|
||||
echo \x07 | string escape
|
||||
|
||||
logmsg 'string escape --style=script \'a b#c"\\\'d\''
|
||||
string escape --style=script 'a b#c"\'d'
|
||||
|
||||
logmsg 'string escape --style=url \'a b#c"\\\'d\''
|
||||
string escape --style=url 'a b#c"\'d'
|
||||
|
||||
logmsg 'string escape --style=url \\na\\nb%c~d\\n'
|
||||
string escape --style=url \na\nb%c~d\n
|
||||
|
||||
logmsg 'string escape --style=var \'a b#c"\\\'d\''
|
||||
string escape --style=var 'a b#c"\'d'
|
||||
|
||||
logmsg 'string escape --style=script a\nghi_'
|
||||
string escape --style=var a\nghi_
|
||||
|
||||
logmsg 'string escape --style=var \'abc\''
|
||||
string escape --style=var 'abc'
|
||||
|
||||
logmsg 'string escape --style=var \'_a_b_c_\''
|
||||
string escape --style=var '_a_b_c_'
|
||||
|
||||
logmsg 'string escape --style=var -- -'
|
||||
string escape --style=var -- -
|
||||
|
||||
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
|
||||
|
||||
# test regex escaping
|
||||
logmsg 'string escape for literal pcre2 searching'
|
||||
string escape --style=regex ".ext"
|
||||
string escape --style=regex "bonjour, amigo"
|
||||
string escape --style=regex "^this is a literal string"
|
||||
|
||||
# The following tests verify that we can correctly unescape the same strings
|
||||
# we tested escaping above.
|
||||
|
||||
logmsg 'set x (string unescape (echo \x07 | string escape))'
|
||||
set x (string unescape (echo \x07 | string escape))
|
||||
test $x = \x07
|
||||
and echo success
|
||||
|
||||
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')
|
||||
|
||||
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')
|
||||
|
||||
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)
|
||||
|
||||
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')
|
||||
|
||||
logmsg 'string unescape --style=var (string escape --style=var a\nghi_)'
|
||||
string unescape --style=var (string escape --style=var a\nghi_)
|
||||
|
||||
logmsg 'string unescape --style=var (string escape --style=var \'abc\')'
|
||||
string unescape --style=var (string escape --style=var 'abc')
|
||||
|
||||
logmsg 'string unescape --style=var (string escape --style=var \'_a_b_c_\')'
|
||||
string unescape --style=var (string escape --style=var '_a_b_c_')
|
||||
|
||||
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.
|
||||
|
||||
logmsg 'string match "*" a'
|
||||
string match "*" a
|
||||
|
||||
logmsg 'string match "a*b" axxb'
|
||||
string match "a*b" axxb
|
||||
|
||||
logmsg 'string match -i "a**B" Axxb'
|
||||
string match -i "a**B" Axxb
|
||||
|
||||
logmsg 'echo "ok?" | string match "*?"'
|
||||
echo "ok?" | string match "*?"
|
||||
|
||||
logmsg 'string match -r "cat|dog|fish" "nice dog"'
|
||||
string match -r "cat|dog|fish" "nice dog"
|
||||
|
||||
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
|
||||
|
||||
logmsg 'string match -r "^(\w{2,4})\g1\$" papa mud murmur'
|
||||
string match -r "^(\w{2,4})\g1\$" papa mud murmur
|
||||
|
||||
logmsg 'string match -r -a -n at ratatat'
|
||||
string match -r -a -n at ratatat
|
||||
|
||||
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;"
|
||||
|
||||
logmsg 'string replace is was "blue is my favorite"'
|
||||
string replace is was "blue is my favorite"
|
||||
|
||||
logmsg 'string replace 3rd last 1st 2nd 3rd'
|
||||
string replace 3rd last 1st 2nd 3rd
|
||||
|
||||
logmsg 'string replace -a " " _ "spaces to underscores"'
|
||||
string replace -a " " _ "spaces to underscores"
|
||||
|
||||
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"
|
||||
|
||||
logmsg 'string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"'
|
||||
string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"
|
||||
|
||||
logmsg 'string replace -r "\s*newline\s*" "\n" "put a newline here"'
|
||||
string replace -r "\s*newline\s*" "\n" "put a newline here"
|
||||
|
||||
logmsg 'string replace -r -a "(\w)" "\$1\$1" ab'
|
||||
string replace -r -a "(\w)" "\$1\$1" ab
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
string replace --regex -f "Z" X 1bc axc 2 d3f jk4 xyz
|
||||
and echo Unexpected exit status at line (status --current-line-number)
|
||||
|
||||
# From https://github.com/fish-shell/fish-shell/issues/5201
|
||||
logmsg 'string match -r with empty capture groups'
|
||||
string match -r '^([ugoa]*)([=+-]?)([rwx]*)$' '=r'
|
||||
|
||||
# test some failure cases
|
||||
logmsg 'string match -r "[" "a[sd"'
|
||||
string match -r "[" "a[sd"; and echo "unexpected exit 0"
|
||||
|
||||
logmsg 'string invalidarg'
|
||||
string invalidarg; and echo "unexpected exit 0"
|
||||
|
||||
logmsg 'string length'
|
||||
string length; or echo "missing argument returns 1"
|
||||
|
||||
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"
|
||||
|
||||
logmsg 'string match -v "*" dog can cat diz'
|
||||
string match -v "*" dog can cat diz; or echo "no glob invert match"
|
||||
|
||||
logmsg 'string match -rvn a bbb'
|
||||
string match -rvn a bbb; or echo "exit 1"
|
||||
|
||||
# test repeat subcommand
|
||||
logmsg 'string repeat -n 2 "foo"'
|
||||
string repeat -n 2 "foo"
|
||||
|
||||
logmsg 'string repeat --count 2 "foo"'
|
||||
string repeat --count 2 "foo"
|
||||
|
||||
logmsg 'echo foo | string repeat -n 2'
|
||||
echo foo | string repeat -n 2
|
||||
|
||||
logmsg 'string repeat -n2 -q "foo"'
|
||||
string repeat -n2 -q "foo"; and echo "exit 0"
|
||||
|
||||
logmsg 'string repeat -n2 --quiet "foo"'
|
||||
string repeat -n2 --quiet "foo"; and echo "exit 0"
|
||||
|
||||
logmsg 'string repeat -n0 "foo"'
|
||||
string repeat -n0 "foo"; or echo "exit 1"
|
||||
|
||||
logmsg 'string repeat -n0'
|
||||
string repeat -n0; or echo "exit 1"
|
||||
|
||||
logmsg 'string repeat -m0'
|
||||
string repeat -m0; or echo "exit 1"
|
||||
|
||||
logmsg 'string repeat -n1 -N "there is "'
|
||||
string repeat -n1 -N "there is "; echo "no newline"
|
||||
|
||||
logmsg 'string repeat -n1 --no-newline "there is "'
|
||||
string repeat -n1 --no-newline "there is "; echo "no newline"
|
||||
|
||||
logmsg 'string repeat -n10 -m4 "foo"'
|
||||
string repeat -n10 -m4 "foo"
|
||||
|
||||
logmsg 'string repeat -n10 --max 5 "foo"'
|
||||
string repeat -n10 --max 5 "foo"
|
||||
|
||||
logmsg 'string repeat -n3 -m20 "foo"'
|
||||
string repeat -n3 -m20 "foo"
|
||||
|
||||
logmsg 'string repeat -m4 "foo"'
|
||||
string repeat -m4 "foo"
|
||||
|
||||
logmsg 'string repeat -n-1 "foo"'
|
||||
string repeat -n-1 "foo"; and echo "exit 0"
|
||||
|
||||
logmsg 'string repeat -m-1 "foo"'
|
||||
string repeat -m-1 "foo"; and echo "exit 0"
|
||||
|
||||
logmsg 'string repeat -n notanumber "foo"'
|
||||
string repeat -n notanumber "foo"; and echo "exit 0"
|
||||
|
||||
logmsg 'string repeat -m notanumber "foo"'
|
||||
string repeat -m notanumber "foo"; and echo "exit 0"
|
||||
|
||||
logmsg 'echo "stdin" | string repeat -n1 "and arg"'
|
||||
echo "stdin" | string repeat -n1 "and arg"; and echo "exit 0"
|
||||
|
||||
logmsg 'string repeat -n'
|
||||
string repeat -n; and echo "exit 0"
|
||||
|
||||
logmsg 'string repeat -l fakearg 2>&1'
|
||||
string repeat -l fakearg
|
||||
|
||||
logmsg 'string repeat ""'
|
||||
string repeat ""
|
||||
or echo string repeat empty string failed
|
||||
|
||||
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.
|
||||
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
|
||||
|
||||
logmsg 'string match x abc dxf xyz jkx x z'
|
||||
string match x abc dxf xyz jkx x z
|
||||
|
||||
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
|
||||
|
||||
logmsg 'string match --entire "" -- banana'
|
||||
string match --entire "" -- banana
|
||||
or echo exit 1
|
||||
|
||||
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.
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
# 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
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
# #5701 - split0 always returned 1
|
||||
echo -ne 'a\x00b' | string split0
|
||||
and echo Split something
|
||||
|
||||
logmsg string join0
|
||||
set tmp beta alpha\ngamma
|
||||
count (string join \n $tmp)
|
||||
count (string join0 $tmp)
|
||||
count (string join0 $tmp | string split0)
|
||||
|
||||
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)
|
||||
|
||||
logmsg string collect
|
||||
count (echo one\ntwo\nthree\nfour | string collect)
|
||||
count (echo one | string collect)
|
||||
echo [(echo one\ntwo\nthree | string collect)]
|
||||
echo [(echo one\ntwo\nthree | string collect -N)]
|
||||
printf '[%s]\n' (string collect one\n\n two\n)
|
||||
printf '[%s]\n' (string collect -N one\n\n two\n)
|
||||
printf '[%s]\n' (string collect --no-trim-newlines one\n\n two\n)
|
||||
# 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
|
||||
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
|
||||
string collect a >/dev/null; and echo expected success; or echo unexpected failure
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
exit 0
|
520
tests/string.out
520
tests/string.out
|
@ -1,520 +0,0 @@
|
|||
|
||||
####################
|
||||
# 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_
|
||||
|
||||
####################
|
||||
# string escape with multibyte chars
|
||||
a%C3%B6b
|
||||
%E4%B8%AD
|
||||
aöb
|
||||
中
|
||||
a_C3_B6_b
|
||||
_E4_B8_AD_
|
||||
aöb
|
||||
中
|
||||
|
||||
####################
|
||||
# string escape for literal pcre2 searching
|
||||
\.ext
|
||||
bonjour, amigo
|
||||
\^this is a literal string
|
||||
|
||||
####################
|
||||
# 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 with empty capture groups
|
||||
=r
|
||||
|
||||
=
|
||||
r
|
||||
|
||||
####################
|
||||
# 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
|
||||
aaabyz
|
||||
kaabxz
|
||||
abbxy
|
||||
caabxyxz
|
||||
|
||||
####################
|
||||
# string match --entire "" -- banana
|
||||
banana
|
||||
|
||||
####################
|
||||
# string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
||||
abx
|
||||
by
|
||||
aaaby
|
||||
aabx
|
||||
bxy
|
||||
aabxyx
|
||||
|
||||
####################
|
||||
# string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
||||
abxc
|
||||
x
|
||||
bye
|
||||
y
|
||||
aaabyz
|
||||
y
|
||||
kaabxz
|
||||
x
|
||||
abbxy
|
||||
xy
|
||||
caabxyxz
|
||||
xyx
|
||||
|
||||
####################
|
||||
# string match -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
||||
abx
|
||||
x
|
||||
by
|
||||
y
|
||||
aaaby
|
||||
y
|
||||
aabx
|
||||
x
|
||||
bxy
|
||||
xy
|
||||
aabxyx
|
||||
xyx
|
||||
|
||||
####################
|
||||
# Check NUL
|
||||
a\x00b
|
||||
a\x00c
|
||||
a
|
||||
\x00
|
||||
d
|
||||
a\x00b
|
||||
a\x00g
|
||||
a\x00g
|
||||
|
||||
####################
|
||||
# string split0
|
||||
1
|
||||
3
|
||||
4
|
||||
3
|
||||
2
|
||||
1
|
||||
a
|
||||
b
|
||||
Split something
|
||||
|
||||
####################
|
||||
# string join0
|
||||
3
|
||||
2
|
||||
2
|
||||
|
||||
####################
|
||||
# string split0 in functions
|
||||
4
|
||||
|
||||
####################
|
||||
# string collect
|
||||
1
|
||||
1
|
||||
[one
|
||||
two
|
||||
three]
|
||||
[one
|
||||
two
|
||||
three
|
||||
]
|
||||
[one]
|
||||
[two]
|
||||
[one
|
||||
|
||||
]
|
||||
[two
|
||||
]
|
||||
[one
|
||||
|
||||
]
|
||||
[two
|
||||
]
|
||||
expected failure
|
||||
expected failure
|
||||
expected success
|
||||
expected failure
|
||||
expected success
|
||||
expected failure
|
||||
expected failure
|
||||
|
||||
####################
|
||||
# string collect in functions
|
||||
3
|
Loading…
Reference in New Issue
Block a user