mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-24 03:51:23 +08:00
4b079e16e5
Variables set in if and while conditions are in the enclosing block, not the if/while statement block. For example: if set -l var (somecommand) ; end echo $var will now work as expected. Fixes #4820. Fixes #1212.
52 lines
1.5 KiB
Fish
52 lines
1.5 KiB
Fish
# Test index ranges
|
|
|
|
logmsg Test variable expand
|
|
set n 10
|
|
set test (seq $n)
|
|
echo $test[1..$n] # normal range
|
|
echo $test[$n..1] # inverted range
|
|
echo $test[2..5 8..6] # several ranges
|
|
echo $test[-1..-2] # range with negative limits
|
|
echo $test[-1..1] # range with mixed limits
|
|
|
|
logmsg Test variable set
|
|
set test1 $test
|
|
set test1[-1..1] $test; echo $test1
|
|
set test1[1..$n] $test; echo $test1
|
|
set test1[$n..1] $test; echo $test1
|
|
set test1[2..4 -2..-4] $test1[4..2 -4..-2]; echo $test1
|
|
|
|
logmsg Test using slices of command substitution
|
|
echo (seq 5)[-1..1]
|
|
echo (seq $n)[3..5 -2..2]
|
|
|
|
logmsg Test more
|
|
echo $test[(count $test)..1]
|
|
echo $test[1..(count $test)]
|
|
|
|
# See issue 1061
|
|
logmsg Verify that if statements swallow failure
|
|
if false ; end ; echo $status
|
|
|
|
logmsg Verify and/or behavior with if and while statements
|
|
if false ; or true ; echo "success1" ; end
|
|
if false ; and false ; echo "failure1" ; end
|
|
while false ; and false ; or true ; echo "success2"; break ; end
|
|
while false; or begin ; false; or true; end; echo "success3"; break ; end
|
|
if false ; else if false ; and true ; else if false ; and false ; else if false; or true; echo "success4"; end
|
|
if false ; else if false ; and true ; else if false ; or false ; else if false; echo "failure 4"; end
|
|
if false ; or true | false ; echo "failure5" ; end
|
|
|
|
logmsg Catch this corner case, which should produce an error
|
|
if false ; or --help ; end
|
|
|
|
logmsg Loop control in conditions
|
|
for i in 1 2 3
|
|
while break; end
|
|
echo $i
|
|
end
|
|
for i in 1 2 3
|
|
while continue; end
|
|
echo $i
|
|
end
|