2014-08-21 12:19:08 +08:00
|
|
|
# Test expansion of variables
|
|
|
|
|
2017-07-20 13:42:52 +08:00
|
|
|
# We don't use the test utility function of the same name because we want
|
|
|
|
# different behavior. Specifically, that the expansion of any variables or
|
|
|
|
# other strings before we are invoked produce the expected expansion.
|
2014-08-21 12:19:08 +08:00
|
|
|
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
|
2017-04-08 03:48:44 +08:00
|
|
|
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]
|
2014-08-21 13:01:24 +08:00
|
|
|
|
|
|
|
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]
|
2017-06-16 20:17:17 +08:00
|
|
|
set -l foo a b c
|
|
|
|
show $foo[17]
|
|
|
|
show $foo[-17]
|
|
|
|
show $foo[17..18]
|
2014-08-21 15:26:14 +08:00
|
|
|
|
|
|
|
echo "$foo[d]"
|
|
|
|
echo $foo[d]
|
|
|
|
|
|
|
|
echo ()[1]
|
|
|
|
echo ()[d]
|
2014-10-25 13:58:52 +08:00
|
|
|
|
2015-05-16 08:10:29 +08:00
|
|
|
echo "Catch your breath"
|
|
|
|
set paren ')'
|
|
|
|
echo $$paren
|
|
|
|
|
2014-10-25 13:58:52 +08:00
|
|
|
# Test tilde expansion
|
2014-10-28 11:48:39 +08:00
|
|
|
# On OS X, /tmp is symlinked to /private/tmp
|
2014-10-31 12:51:23 +08:00
|
|
|
# $PWD is our best bet for resolving it
|
|
|
|
set -l saved $PWD
|
2014-10-28 11:48:39 +08:00
|
|
|
cd (mktemp -d)
|
2014-10-31 12:51:23 +08:00
|
|
|
set tmpdir $PWD
|
|
|
|
cd $saved
|
2014-10-25 13:58:52 +08:00
|
|
|
mkdir $tmpdir/realhome
|
|
|
|
ln -s $tmpdir/realhome $tmpdir/linkhome
|
2016-02-07 10:08:22 +08:00
|
|
|
set expandedtilde (env HOME=$tmpdir/linkhome ../test/root/bin/fish -c 'echo ~')
|
2014-10-25 13:58:52 +08:00
|
|
|
if test $expandedtilde != $tmpdir/realhome
|
|
|
|
echo '~ expands to' $expandedtilde ' - expected ' $tmpdir/realhome
|
|
|
|
end
|
|
|
|
unlink $tmpdir/linkhome
|
|
|
|
rmdir $tmpdir/realhome
|
|
|
|
rmdir $tmpdir
|