2019-07-31 14:04:24 +02:00
#RUN: %fish -C "set fish %fish" %s
# Check that switch with an argument expanding to nothing still works.
switch $foo
case a
echo a
case ''
echo very little
case '*'
echo Nothin
case ''
echo banana
end
#CHECK: very little
switch ( true )
case a
echo a
case ''
echo very little
case '*'
echo Nothin
case ''
echo banana
end
#CHECK: very little
switch ( echo )
case a
echo a
case ''
echo very little
case '*'
echo Nothin
case ''
echo banana
end
#CHECK: very little
# Multiple arguments is still an error, we've not decided on good behavior for this.
switch ( echo ; echo ; echo )
case a
echo a
case ""
echo very little
case "*"
echo Nothin
case ""
echo banana
end
#CHECKERR: {{.*/?}}switch.fish (line {{\d+}}): switch: Expected at most one argument, got 3
#CHECKERR:
#CHECKERR: switch (echo; echo; echo)
2022-08-11 17:22:03 +02:00
#CHECKERR: ^~~~~~~~~~~~~~~~~^
2019-07-31 14:04:24 +02:00
# As is no argument at all.
# Because this is a syntax error, we need to start a sub-fish or we wouldn't execute anything else.
$fish -c '
switch
case a
echo a
case ""
echo very little
case "*"
echo Nothin
case ""
echo banana
end
'
#CHECKERR: fish: 'case' builtin not inside of switch block
#CHECKERR: case a
2022-08-11 17:22:03 +02:00
#CHECKERR: ^~~^
2020-02-08 10:43:40 +01:00
set smurf green
2020-03-09 19:36:12 +01:00
switch $smurf
case "*ee*"
echo Test 1 pass
case "*"
echo Test 1 fail
end
2020-02-08 10:43:40 +01:00
#CHECK: Test 1 pass
switch $smurf
2020-03-09 19:36:12 +01:00
case *ee*
echo Test 2 fail
case red green blue
echo Test 2 pass
case "*"
echo Test 2 fail
2020-02-08 10:43:40 +01:00
end
2021-08-11 18:40:37 +02:00
#CHECKERR: {{.*}}switch.fish (line {{\d+}}): No matches for wildcard '*ee*'. See `help wildcards-globbing`.
2020-02-08 10:43:40 +01:00
#CHECKERR: case *ee*
2022-08-11 17:22:03 +02:00
#CHECKERR: ^~~^
2020-02-08 10:43:40 +01:00
#CHECK: Test 2 pass
switch $smurf
2020-03-09 19:36:12 +01:00
case cyan magenta yellow
echo Test 3 fail
case "*"
echo Test 3 pass
2020-02-08 10:43:40 +01:00
end
#CHECK: Test 3 pass
2021-04-19 16:47:17 +02:00
begin
set -l PATH
switch ( doesnotexist )
case '*'
echo Matched!
end
# CHECKERR: fish: Unknown command: doesnotexist
# CHECKERR: checks/switch.fish (line {{\d+}}):
# CHECKERR: doesnotexist
2022-08-11 17:22:03 +02:00
# CHECKERR: ^~~~~~~~~~~^
2021-04-19 16:47:17 +02:00
# CHECKERR: in command substitution
# CHECKERR: {{\t}}called on line {{\d+}} of file checks/switch.fish
# CHECKERR: checks/switch.fish (line {{\d+}}): Unknown command
# CHECKERR: switch (doesnotexist)
2022-08-11 17:22:03 +02:00
# CHECKERR: ^~~~~~~~~~~~~^
2021-04-19 16:47:17 +02:00
end