2014-08-21 04:19:08 +00:00
|
|
|
# Test expansion of variables
|
|
|
|
|
2017-07-20 05:42:52 +00: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.
|
2017-08-04 04:37:02 +00:00
|
|
|
function expansion --description 'Prints argument count followed by arguments'
|
2014-08-21 04:19:08 +00:00
|
|
|
echo (count $argv) $argv
|
|
|
|
end
|
|
|
|
|
|
|
|
set -l foo
|
2017-08-04 04:37:02 +00:00
|
|
|
expansion "$foo"
|
|
|
|
expansion $foo
|
|
|
|
expansion "prefix$foo"
|
|
|
|
expansion prefix$foo
|
2014-08-21 04:19:08 +00:00
|
|
|
|
2017-08-04 04:37:02 +00:00
|
|
|
expansion "$$foo"
|
|
|
|
expansion $$foo
|
|
|
|
expansion "prefix$$foo"
|
|
|
|
expansion prefix$$foo
|
2014-08-21 04:19:08 +00:00
|
|
|
|
|
|
|
set -l foo ''
|
2017-08-04 04:37:02 +00:00
|
|
|
expansion "$foo"
|
|
|
|
expansion $foo
|
|
|
|
expansion "prefix$foo"
|
|
|
|
expansion prefix$foo
|
2014-08-21 04:19:08 +00:00
|
|
|
|
2017-08-04 04:37:02 +00:00
|
|
|
expansion "$$foo"
|
|
|
|
expansion $$foo
|
|
|
|
expansion "prefix$$foo"
|
|
|
|
expansion prefix$$foo
|
2014-08-21 04:19:08 +00:00
|
|
|
|
|
|
|
set -l foo bar
|
|
|
|
set -l bar
|
2017-08-04 04:37:02 +00:00
|
|
|
expansion "$$foo"
|
|
|
|
expansion $$foo
|
|
|
|
expansion "prefix$$foo"
|
|
|
|
expansion prefix$$foo
|
2014-08-21 04:19:08 +00:00
|
|
|
|
|
|
|
set -l bar baz
|
2017-08-04 04:37:02 +00:00
|
|
|
expansion "$$foo"
|
|
|
|
expansion $$foo
|
|
|
|
expansion "prefix$$foo"
|
|
|
|
expansion prefix$$foo
|
2014-08-21 04:19:08 +00:00
|
|
|
|
|
|
|
set -l bar baz quux
|
2017-08-04 04:37:02 +00:00
|
|
|
expansion "$$foo"
|
|
|
|
expansion $$foo
|
|
|
|
expansion "prefix$$foo"
|
|
|
|
expansion prefix$$foo
|
2014-08-21 04:19:08 +00:00
|
|
|
|
|
|
|
set -l foo bar fooer fooest
|
|
|
|
set -l fooer
|
|
|
|
set -l fooest
|
2017-08-04 04:37:02 +00:00
|
|
|
expansion "$$foo"
|
|
|
|
expansion $$foo
|
|
|
|
expansion "prefix$$foo"
|
|
|
|
expansion prefix$$foo
|
2014-08-21 04:19:08 +00:00
|
|
|
|
|
|
|
set -l fooer ''
|
2017-08-04 04:37:02 +00:00
|
|
|
expansion $$foo
|
|
|
|
expansion prefix$$foo
|
2014-08-21 04:19:08 +00:00
|
|
|
|
|
|
|
set -l foo bar '' fooest
|
2017-08-04 04:37:02 +00:00
|
|
|
expansion "$$foo"
|
|
|
|
expansion $$foo
|
|
|
|
expansion "prefix$$foo"
|
|
|
|
expansion prefix$$foo
|
2018-04-26 20:42:48 +00:00
|
|
|
expansion $foo[-5..2] # No result, because the starting index is invalid and we force-reverse.
|
2017-08-04 04:37:02 +00:00
|
|
|
expansion $foo[-2..-1]
|
|
|
|
expansion $foo[-10..-5]
|
|
|
|
expansion (printf '%s\n' $foo)[-5..2]
|
|
|
|
expansion (printf '%s\n' $foo)[-2..-1]
|
|
|
|
expansion (printf '%s\n' $foo)[-10..-5]
|
2018-09-15 09:03:45 +00:00
|
|
|
expansion (echo one)[2..-1]
|
2014-08-21 05:01:24 +00:00
|
|
|
|
2018-09-15 09:03:45 +00:00
|
|
|
echo "# foo = "
|
2014-08-21 05:01:24 +00:00
|
|
|
set -l foo
|
2017-08-04 04:37:02 +00:00
|
|
|
expansion "$foo[1]"
|
|
|
|
expansion $foo[1]
|
|
|
|
expansion "$foo[-1]"
|
|
|
|
expansion $foo[-1]
|
|
|
|
expansion "$foo[2]"
|
|
|
|
expansion $foo[2]
|
|
|
|
expansion "$foo[1 2]"
|
|
|
|
expansion $foo[1 2]
|
|
|
|
expansion "$foo[2 1]"
|
|
|
|
expansion $foo[2 1]
|
2018-09-15 09:03:45 +00:00
|
|
|
echo "# foo = a b c"
|
2017-06-16 12:17:17 +00:00
|
|
|
set -l foo a b c
|
2017-08-04 04:37:02 +00:00
|
|
|
expansion $foo[17]
|
|
|
|
expansion $foo[-17]
|
|
|
|
expansion $foo[17..18]
|
2018-04-26 20:42:48 +00:00
|
|
|
expansion $foo[4..-2]
|
2018-09-15 09:03:45 +00:00
|
|
|
echo "# foo = a"
|
|
|
|
set -l foo a
|
|
|
|
expansion $foo[2..-1]
|
2014-08-21 07:26:14 +00:00
|
|
|
|
|
|
|
echo "$foo[d]"
|
|
|
|
echo $foo[d]
|
|
|
|
|
|
|
|
echo ()[1]
|
|
|
|
echo ()[d]
|
2014-10-25 05:58:52 +00:00
|
|
|
|
2017-08-04 04:37:02 +00:00
|
|
|
logmsg Catch your breath
|
2015-05-16 00:10:29 +00:00
|
|
|
set paren ')'
|
|
|
|
echo $$paren
|
|
|
|
|
2017-08-04 04:37:02 +00:00
|
|
|
logmsg Test tilde expansion
|
2014-10-28 03:48:39 +00:00
|
|
|
# On OS X, /tmp is symlinked to /private/tmp
|
2014-10-31 04:51:23 +00:00
|
|
|
# $PWD is our best bet for resolving it
|
|
|
|
set -l saved $PWD
|
2014-10-28 03:48:39 +00:00
|
|
|
cd (mktemp -d)
|
2014-10-31 04:51:23 +00:00
|
|
|
set tmpdir $PWD
|
|
|
|
cd $saved
|
2014-10-25 05:58:52 +00:00
|
|
|
mkdir $tmpdir/realhome
|
|
|
|
ln -s $tmpdir/realhome $tmpdir/linkhome
|
2016-02-07 02:08:22 +00:00
|
|
|
set expandedtilde (env HOME=$tmpdir/linkhome ../test/root/bin/fish -c 'echo ~')
|
2014-10-25 05:58:52 +00:00
|
|
|
if test $expandedtilde != $tmpdir/realhome
|
|
|
|
echo '~ expands to' $expandedtilde ' - expected ' $tmpdir/realhome
|
|
|
|
end
|
|
|
|
unlink $tmpdir/linkhome
|
|
|
|
rmdir $tmpdir/realhome
|
|
|
|
rmdir $tmpdir
|