summaryrefslogtreecommitdiff
path: root/t/lib/feature/switch
blob: 5e6269ff0e0a84185349f0a4ebcff7cd04fdf2e5 (plain)
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
Check the lexical scoping of the switch keywords.
(The actual behaviour is tested in t/op/switch.t)

__END__
# No switch; given should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
print STDOUT given;
EXPECT
Unquoted string "given" may clash with future reserved word at - line 3.
given
########
# No switch; whereso should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
print STDOUT whereso;
EXPECT
Unquoted string "whereso" may clash with future reserved word at - line 3.
whereso
########
# No switch; but continue is still a keyword
print STDOUT continue;
EXPECT
Can't "continue" outside a whereso block at - line 2.
########
# Use switch; so given is a keyword
use feature 'switch'; no warnings 'experimental::smartmatch';
given("okay\n") { print }
EXPECT
okay
########
# Use switch; so whereso is a keyword
use feature 'switch'; no warnings 'experimental::smartmatch';
given(1) { whereso(1) { print "okay" } }
EXPECT
okay
########
# switch out of scope; given should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
{ use feature 'switch';
  given (1) {print "Okay here\n";}
}
print STDOUT given;
EXPECT
Unquoted string "given" may clash with future reserved word at - line 6.
Okay here
given
########
# switch out of scope; whereso should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
{ use feature 'switch';
  given (1) { whereso(1) {print "Okay here\n";} }
}
print STDOUT whereso;
EXPECT
Unquoted string "whereso" may clash with future reserved word at - line 6.
Okay here
whereso
########
# C<no feature 'switch'> should work
use warnings; no warnings 'experimental::smartmatch';
use feature 'switch';
given (1) { whereso(1) {print "Okay here\n";} }
no feature 'switch';
print STDOUT whereso;
EXPECT
Unquoted string "whereso" may clash with future reserved word at - line 6.
Okay here
whereso
########
# C<no feature> should work too
use warnings; no warnings 'experimental::smartmatch';
use feature 'switch';
given (1) { whereso(1) {print "Okay here\n";} }
no feature;
print STDOUT whereso;
EXPECT
Unquoted string "whereso" may clash with future reserved word at - line 6.
Okay here
whereso