This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Capitalise magic descriptions consistently
[perl5.git] / t / cmd / switch.t
CommitLineData
a687059c
LW
1#!./perl
2
a687059c
LW
3print "1..18\n";
4
5sub foo1 {
6 $_ = shift(@_);
7 $a = 0;
8 until ($a++) {
9 next if $_ eq 1;
10 next if $_ eq 2;
11 next if $_ eq 3;
12 next if $_ eq 4;
13 return 20;
14 }
15 continue {
16 return $_;
17 }
18}
19
2a70d4f6
NC
20print foo1(0) == 20 ? "ok 1\n" : "not ok 1\n";
21print foo1(1) == 1 ? "ok 2\n" : "not ok 2\n";
22print foo1(2) == 2 ? "ok 3\n" : "not ok 3\n";
23print foo1(3) == 3 ? "ok 4\n" : "not ok 4\n";
24print foo1(4) == 4 ? "ok 5\n" : "not ok 5\n";
25print foo1(5) == 20 ? "ok 6\n" : "not ok 6\n";
a687059c
LW
26
27sub foo2 {
28 $_ = shift(@_);
29 {
30 last if $_ == 1;
31 last if $_ == 2;
32 last if $_ == 3;
33 last if $_ == 4;
34 }
35 continue {
36 return 20;
37 }
38 return $_;
39}
40
2a70d4f6
NC
41print foo2(0) == 20 ? "ok 7\n" : "not ok 7\n";
42print foo2(1) == 1 ? "ok 8\n" : "not ok 8\n";
43print foo2(2) == 2 ? "ok 9\n" : "not ok 9\n";
44print foo2(3) == 3 ? "ok 10\n" : "not ok 10\n";
45print foo2(4) == 4 ? "ok 11\n" : "not ok 11\n";
46print foo2(5) == 20 ? "ok 12\n" : "not ok 12\n";
a687059c
LW
47
48sub foo3 {
49 $_ = shift(@_);
50 if (/^1/) {
51 return 1;
52 }
53 elsif (/^2/) {
54 return 2;
55 }
56 elsif (/^3/) {
57 return 3;
58 }
59 elsif (/^4/) {
60 return 4;
61 }
62 else {
63 return 20;
64 }
65 return 40;
66}
67
2a70d4f6
NC
68print foo3(0) == 20 ? "ok 13\n" : "not ok 13\n";
69print foo3(1) == 1 ? "ok 14\n" : "not ok 14\n";
70print foo3(2) == 2 ? "ok 15\n" : "not ok 15\n";
71print foo3(3) == 3 ? "ok 16\n" : "not ok 16\n";
72print foo3(4) == 4 ? "ok 17\n" : "not ok 17\n";
73print foo3(5) == 20 ? "ok 18\n" : "not ok 18\n";