Skip to content
Newer
Older
100644 165 lines (143 sloc) 3.14 KB
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
1 use v6;
2
3 use Test;
4
5 plan 13;
6
4e5f604 [t/spec] fix some smartlinks
moritz authored Nov 6, 2009
7 # L<S04/Phasers/NEXT executes "only if"
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
8 # "end of the loop block" or "explicit next">
9 {
10 my $str = '';
11 for 1..5 {
12 NEXT { $str ~= ':' }
13 next if $_ % 2 == 1;
14 $str ~= $_;
15 }
16 is $str, ':2::4::', 'NEXT called by both next and normal falling out';
17 }
18
19 # NEXT is positioned at the bottom:
20 {
21 my $str = '';
22 for 1..5 {
23 next if $_ % 2 == 1;
24 $str ~= $_;
25 NEXT { $str ~= ':' }
26 }
27 is $str, ':2::4::', 'NEXT called by both next and normal falling out';
28 }
29
30 # NEXT is positioned in the middle:
31 {
32 my $str = '';
33 for 1..5 {
34 next if $_ % 2 == 1;
35 NEXT { $str ~= ':' }
36 $str ~= $_;
37 }
38 is $str, ':2::4::', 'NEXT called by both next and normal falling out';
39 }
40
41 # NEXT is evaluated even at the last iteration
42 {
43 my $str = '';
44 for 1..2 {
45 NEXT { $str ~= 'n'; }
46 LAST { $str ~= 'l'; }
47 }
a842b80 @coke pugs fudge
coke authored Feb 20, 2012
48 #?pugs todo
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
49 is $str, 'nnl', 'NEXT are LAST blocks may not be exclusive';
50 }
51
4e5f604 [t/spec] fix some smartlinks
moritz authored Nov 6, 2009
52 # L<S04/Phasers/NEXT "not executed" if exited
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
53 # "via any exception other than" next>
54
55 {
56 my $str = '';
57 try {
58 for 1..5 {
59 NEXT { $str ~= $_ }
60 die if $_ > 3;
61 }
62 }
63 is $str, '123', "die didn't trigger NEXT \{}";
64 }
65
a553a91 @jnthn Fudge for Rakudo.
jnthn authored Mar 6, 2012
66 #?rakudo skip 'leave NYI'
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
67 {
68 my $str = '';
69 try {
70 for 1..5 {
71 NEXT { $str ~= $_ }
72 leave if $_ > 3;
73 }
74 }
a842b80 @coke pugs fudge
coke authored Feb 21, 2012
75 #?pugs todo
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
76 is $str, '123', "leave didn't trigger NEXT \{}";
77 }
78
79 {
80 my $str = '';
81 my sub foo {
82 for 1..5 {
83 NEXT { $str ~= $_ }
84 return if $_ > 3;
85 }
86 }
87 foo();
88 is $str, '123', "return didn't trigger NEXT \{}";
89 }
90
832f178 [t/spec] fix more smartlinks; down to 33 broken links
moritz authored Mar 18, 2010
91 # L<S04/Phasers/last bypasses evaluation of NEXT phasers>
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
92 {
93 my $str = '';
94 for 1..5 {
95 NEXT { $str ~= $_; }
96 last if $_ > 3;
97 }
98 is $str, '123', "last bypass NEXT \{}";
99 }
100
4e5f604 [t/spec] fix some smartlinks
moritz authored Nov 6, 2009
101 # L<S04/Phasers/NEXT "before any LEAVE">
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
102
a553a91 @jnthn Fudge for Rakudo.
jnthn authored Mar 6, 2012
103 #?rakudo todo 'NEXT/LEAVE ordering'
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
104 {
105 my $str = '';
106 for 1..2 {
107 NEXT { $str ~= 'n' }
108 LEAVE { $str ~= 'l' }
109 }
a842b80 @coke pugs fudge
coke authored Feb 21, 2012
110 #?pugs todo
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
111 is $str, 'nlnl', 'NEXT {} ran before LEAVE {} (1)';
112 }
113
114 # reversed order
a553a91 @jnthn Fudge for Rakudo.
jnthn authored Mar 6, 2012
115 #?rakudo todo 'NEXT/LEAVE ordering'
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
116 {
117 my $str = '';
118 for 1..2 {
119 LEAVE { $str ~= 'l' }
120 NEXT { $str ~= 'n' }
121 }
a842b80 @coke pugs fudge
coke authored Feb 21, 2012
122 #?pugs todo
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
123 is $str, 'nlnl', 'NEXT {} ran before LEAVE {} (2)';
124 }
125
4e5f604 [t/spec] fix some smartlinks
moritz authored Nov 6, 2009
126 # L<S04/Phasers/NEXT "at loop continuation time">
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
127
128 # L<http://groups.google.com/group/perl.perl6.language/msg/07370316d32890dd>
129
a553a91 @jnthn Fudge for Rakudo.
jnthn authored Mar 6, 2012
130 #?rakudo todo 'NEXT with while'
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
131 {
132 my $str = '';
133 my $n = 0;
134 my $i;
135 while $n < 5 {
136 NEXT { ++$n } # this gets run second (LIFO)
137 NEXT { $str ~= $n } # this gets run first (LIFO)
138 last if $i++ > 100; # recursion prevension
139 }
a842b80 @coke pugs fudge
coke authored Feb 21, 2012
140 #?pugs todo
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
141 is $str, '01234', 'NEXT {} ran in reversed order';
142 }
143
a553a91 @jnthn Fudge for Rakudo.
jnthn authored Mar 6, 2012
144 #?rakudo todo 'NEXT with loop'
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
145 {
146 my $str = '';
147 loop (my $n = 0; $n < 5; ++$n) {
148 NEXT { $str ~= $n }
149 }
150 is $str, '01234', 'NEXT {} works in loop (;;) {}';
151 }
152
153 {
154 my @x = 0..4;
155 my $str = '';
156 for @x {
157 NEXT { $str ~= $_; }
158 }
159
a842b80 @coke pugs fudge
coke authored Feb 21, 2012
160 #?pugs todo
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored Oct 5, 2008
161 is($str, '01234', 'NEXT {} works in for loop');
162 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored Aug 8, 2009
163
164 # vim: ft=perl6
Something went wrong with that request. Please try again.