mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
cc49042294
When a variable is parsed as being empty, parse out the slice and validate the indexes anyway, behaving for slicing purposes as if the variable had a single empty value. Besides providing errors when expected, this also fixes the following: set -l foo echo "$foo[1]" This used to print "[1]", now it properly prints nothing.
76 lines
1 KiB
Text
76 lines
1 KiB
Text
# Test expansion of variables
|
|
|
|
function show --description 'Prints argument count followed by arguments'
|
|
echo (count $argv) $argv
|
|
end
|
|
|
|
set -l foo
|
|
show "$foo"
|
|
show $foo
|
|
show "prefix$foo"
|
|
show prefix$foo
|
|
|
|
show "$$foo"
|
|
show $$foo
|
|
show "prefix$$foo"
|
|
show prefix$$foo
|
|
|
|
set -l foo ''
|
|
show "$foo"
|
|
show $foo
|
|
show "prefix$foo"
|
|
show prefix$foo
|
|
|
|
show "$$foo"
|
|
show $$foo
|
|
show "prefix$$foo"
|
|
show prefix$$foo
|
|
|
|
set -l foo bar
|
|
set -l bar
|
|
show "$$foo"
|
|
show $$foo
|
|
show "prefix$$foo"
|
|
show prefix$$foo
|
|
|
|
set -l bar baz
|
|
show "$$foo"
|
|
show $$foo
|
|
show "prefix$$foo"
|
|
show prefix$$foo
|
|
|
|
set -l bar baz quux
|
|
show "$$foo"
|
|
show $$foo
|
|
show "prefix$$foo"
|
|
show prefix$$foo
|
|
|
|
set -l foo bar fooer fooest
|
|
set -l fooer
|
|
set -l fooest
|
|
show "$$foo"
|
|
show $$foo
|
|
show "prefix$$foo"
|
|
show prefix$$foo
|
|
|
|
set -l fooer ''
|
|
show $$foo
|
|
show prefix$$foo
|
|
|
|
set -l foo bar '' fooest
|
|
show "$$foo"
|
|
show $$foo
|
|
show "prefix$$foo"
|
|
show prefix$$foo
|
|
|
|
set -l foo
|
|
show "$foo[1]"
|
|
show $foo[1]
|
|
show "$foo[-1]"
|
|
show $foo[-1]
|
|
show "$foo[2]"
|
|
show $foo[2]
|
|
show "$foo[1 2]"
|
|
show $foo[1 2]
|
|
show "$foo[2 1]"
|
|
show $foo[2 1]
|