Commit | Line | Data |
0d863452 |
1 | Check the lexical scoping of the switch keywords. |
2 | (The actual behaviour is tested in t/op/switch.t) |
3 | |
4 | __END__ |
5 | # No switch; given should be a bareword. |
6 | use warnings; |
7 | print STDOUT given; |
8 | EXPECT |
9 | Unquoted string "given" may clash with future reserved word at - line 3. |
10 | given |
11 | ######## |
12 | # No switch; when should be a bareword. |
13 | use warnings; |
14 | print STDOUT when; |
15 | EXPECT |
16 | Unquoted string "when" may clash with future reserved word at - line 3. |
17 | when |
18 | ######## |
19 | # No switch; default should be a bareword. |
20 | use warnings; |
21 | print STDOUT default; |
22 | EXPECT |
23 | Unquoted string "default" may clash with future reserved word at - line 3. |
24 | default |
25 | ######## |
26 | # No switch; break should be a bareword. |
27 | use warnings; |
28 | print STDOUT break; |
29 | EXPECT |
30 | Unquoted string "break" may clash with future reserved word at - line 3. |
31 | break |
32 | ######## |
33 | # No switch; but continue is still a keyword |
34 | print STDOUT continue; |
35 | EXPECT |
36 | syntax error at - line 2, near "STDOUT continue" |
37 | Execution of - aborted due to compilation errors. |
38 | ######## |
39 | # Use switch; so given is a keyword |
40 | use feature 'switch'; |
41 | given("okay\n") { print } |
42 | EXPECT |
43 | okay |
44 | ######## |
45 | # Use switch; so when is a keyword |
46 | use feature 'switch'; |
47 | given(1) { when(1) { print "okay" } } |
48 | EXPECT |
49 | okay |
50 | ######## |
51 | # Use switch; so default is a keyword |
52 | use feature 'switch'; |
53 | given(1) { default { print "okay" } } |
54 | EXPECT |
55 | okay |
56 | ######## |
57 | # Use switch; so break is a keyword |
58 | use feature 'switch'; |
59 | break; |
60 | EXPECT |
61 | Can't "break" outside a given block at - line 3. |
62 | ######## |
63 | # Use switch; so continue is a keyword |
64 | use feature 'switch'; |
65 | continue; |
66 | EXPECT |
67 | Can't "continue" outside a when block at - line 3. |
68 | ######## |
69 | # switch out of scope; given should be a bareword. |
70 | use warnings; |
71 | { use feature 'switch'; |
72 | given (1) {print "Okay here\n";} |
73 | } |
74 | print STDOUT given; |
75 | EXPECT |
76 | Unquoted string "given" may clash with future reserved word at - line 6. |
77 | Okay here |
78 | given |
79 | ######## |
80 | # switch out of scope; when should be a bareword. |
81 | use warnings; |
82 | { use feature 'switch'; |
83 | given (1) { when(1) {print "Okay here\n";} } |
84 | } |
85 | print STDOUT when; |
86 | EXPECT |
87 | Unquoted string "when" may clash with future reserved word at - line 6. |
88 | Okay here |
89 | when |
90 | ######## |
91 | # switch out of scope; default should be a bareword. |
92 | use warnings; |
93 | { use feature 'switch'; |
94 | given (1) { default {print "Okay here\n";} } |
95 | } |
96 | print STDOUT default; |
97 | EXPECT |
98 | Unquoted string "default" may clash with future reserved word at - line 6. |
99 | Okay here |
100 | default |
101 | ######## |
102 | # switch out of scope; break should be a bareword. |
103 | use warnings; |
104 | { use feature 'switch'; |
105 | given (1) { break } |
106 | } |
107 | print STDOUT break; |
108 | EXPECT |
109 | Unquoted string "break" may clash with future reserved word at - line 6. |
110 | break |
111 | ######## |
112 | # switch out of scope; continue should not work |
113 | { use feature 'switch'; |
114 | given (1) { default {continue} } |
115 | } |
116 | print STDOUT continue; |
117 | EXPECT |
118 | syntax error at - line 5, near "STDOUT continue" |
119 | Execution of - aborted due to compilation errors. |
120 | ######## |
121 | # C<no feature 'switch'> should work |
122 | use warnings; |
123 | use feature 'switch'; |
124 | given (1) { when(1) {print "Okay here\n";} } |
125 | no feature 'switch'; |
126 | print STDOUT when; |
127 | EXPECT |
128 | Unquoted string "when" may clash with future reserved word at - line 6. |
129 | Okay here |
130 | when |
131 | ######## |
132 | # C<no feature> should work too |
133 | use warnings; |
134 | use feature 'switch'; |
135 | given (1) { when(1) {print "Okay here\n";} } |
136 | no feature; |
137 | print STDOUT when; |
138 | EXPECT |
139 | Unquoted string "when" may clash with future reserved word at - line 6. |
140 | Okay here |
141 | when |
142 | ######## |
143 | # Without the feature, no 'Unambiguous use of' warning: |
144 | use warnings; |
145 | @break = ($break = "break"); |
146 | print ${break}, ${break[0]}; |
147 | EXPECT |
148 | breakbreak |
149 | ######## |
150 | # With the feature, we get an 'Unambiguous use of' warning: |
151 | use warnings; |
152 | use feature 'switch'; |
153 | @break = ($break = "break"); |
154 | print ${break}, ${break[0]}; |
155 | EXPECT |
156 | Ambiguous use of ${break} resolved to $break at - line 5. |
157 | Ambiguous use of ${break[...]} resolved to $break[...] at - line 5. |
158 | breakbreak |