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
|
|
|
|
2018-10-10 21:26:29 +00:00
|
|
|
logmsg Percent self
|
|
|
|
echo %selfNOT NOT%self \%self "%self" '%self'
|
|
|
|
echo %self | string match -qr '^\\d+$'
|
|
|
|
echo "All digits: $status"
|
|
|
|
|
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 ~')
|
2018-09-17 01:03:13 +00:00
|
|
|
if test $expandedtilde != $tmpdir/linkhome
|
|
|
|
echo '~ expands to' $expandedtilde ' - expected ' $tmpdir/linkhome
|
2014-10-25 05:58:52 +00:00
|
|
|
end
|
|
|
|
unlink $tmpdir/linkhome
|
|
|
|
rmdir $tmpdir/realhome
|
|
|
|
rmdir $tmpdir
|
2018-09-30 23:34:01 +00:00
|
|
|
|
2018-10-07 03:22:35 +00:00
|
|
|
logmsg Test path variables
|
2018-09-30 23:34:01 +00:00
|
|
|
set TEST_DELIMITER one two three
|
|
|
|
set TEST_DELIMITER_PATH one two three
|
2018-10-07 03:22:35 +00:00
|
|
|
echo TEST_DELIMITER: $TEST_DELIMITER "$TEST_DELIMITER"
|
|
|
|
echo TEST_DELIMITER_PATH: $TEST_DELIMITER_PATH "$TEST_DELIMITER_PATH"
|
|
|
|
|
|
|
|
set testvar ONE:TWO:THREE
|
|
|
|
echo "Not a path: $testvar" (count $testvar)
|
|
|
|
set --path testvar $testvar
|
|
|
|
echo "As a path: $testvar" (count $testvar)
|
|
|
|
set testvar "$testvar:FOUR"
|
|
|
|
echo "Appended path: $testvar" (count $testvar)
|
|
|
|
set --unpath testvar $testvar
|
|
|
|
echo "Back to normal variable: $testvar" (count $testvar)
|