File: switch.fish

package info (click to toggle)
fish 4.2.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,980 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (121 lines) | stat: -rw-r--r-- 2,526 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# RUN: fish=%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)
#CHECKERR:        ^~~~~~~~~~~~~~~~~^

# 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: Expected a string, but found end of the statement
# CHECKERR: switch
# CHECKERR: ^

set smurf green

switch $smurf
    case "*ee*"
        echo Test 1 pass
    case "*"
        echo Test 1 fail
end
#CHECK: Test 1 pass

switch $smurf
    case *ee*
        echo Test 2 fail
    case red green blue
        echo Test 2 pass
    case "*"
        echo Test 2 fail
end
#CHECKERR: {{.*}}switch.fish (line {{\d+}}): No matches for wildcard '*ee*'. See `help wildcards-globbing`.
#CHECKERR: case *ee*
#CHECKERR:      ^~~^
#CHECK: Test 2 pass

switch $smurf
    case cyan magenta yellow
        echo Test 3 fail
    case "*"
        echo Test 3 pass
end
#CHECK: Test 3 pass

begin
    set -l PATH
    switch (doesnotexist)
        case '*'
            echo Matched!
    end
    # CHECKERR: fish: Unknown command: doesnotexist
    # CHECKERR: {{.*}}checks/switch.fish (line {{\d+}}):
    # CHECKERR: doesnotexist
    # CHECKERR: ^~~~~~~~~~~^
    # 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)
    # CHECKERR:        ^~~~~~~~~~~~~^
end

exit 0