fish-shell/tests/expansion.in
Fabian Homborg 44f2f37bd4 Remove "Array index out of bounds" errors
This just removes every invalid index.

That means with `set foo a b c` and the "show" function from tests/expand.in:

- `show $foo[-5..-1]` prints "3 a b c"
- `show $foo[-10..1]` prints "1 a"
- `show $foo[2..5]` prints "2 b c"
- `show $foo[1 3 7 2]` prints "3 a c b"

and similar for command substitutions.

Fixes #826.
2017-06-20 17:52:23 -07:00

110 lines
1.8 KiB
Fish

# 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
show $foo[-5..2]
show $foo[-2..-1]
show $foo[-10..-5]
show (printf '%s\n' $foo)[-5..2]
show (printf '%s\n' $foo)[-2..-1]
show (printf '%s\n' $foo)[-10..-5]
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]
echo "$foo[d]"
echo $foo[d]
echo ()[1]
echo ()[d]
echo "Catch your breath"
set paren ')'
echo $$paren
# Test tilde expansion
# On OS X, /tmp is symlinked to /private/tmp
# $PWD is our best bet for resolving it
set -l saved $PWD
cd (mktemp -d)
set tmpdir $PWD
cd $saved
mkdir $tmpdir/realhome
ln -s $tmpdir/realhome $tmpdir/linkhome
set expandedtilde (env HOME=$tmpdir/linkhome ../test/root/bin/fish -c 'echo ~')
if test $expandedtilde != $tmpdir/realhome
echo '~ expands to' $expandedtilde ' - expected ' $tmpdir/realhome
end
unlink $tmpdir/linkhome
rmdir $tmpdir/realhome
rmdir $tmpdir