Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 166 lines (144 sloc) 3.181 kb
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
1 use v6;
2
3 use Test;
4
5 plan 13;
6
4e5f6047 »
2009-11-06 [t/spec] fix some smartlinks
7 # L<S04/Phasers/NEXT executes "only if"
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
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 }
a842b805 »
2012-02-20 pugs fudge
48 #?pugs todo
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
49 is $str, 'nnl', 'NEXT are LAST blocks may not be exclusive';
50 }
51
4e5f6047 »
2009-11-06 [t/spec] fix some smartlinks
52 # L<S04/Phasers/NEXT "not executed" if exited
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
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 }
4677a6f3 »
2012-12-10 make S04-phasers/next.t robuster wrt laziness
62 0;
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
63 }
64 is $str, '123', "die didn't trigger NEXT \{}";
65 }
66
a553a91e »
2012-03-06 Fudge for Rakudo.
67 #?rakudo skip 'leave NYI'
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
68 {
69 my $str = '';
70 try {
71 for 1..5 {
72 NEXT { $str ~= $_ }
73 leave if $_ > 3;
74 }
4677a6f3 »
2012-12-10 make S04-phasers/next.t robuster wrt laziness
75 0;
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
76 }
a842b805 »
2012-02-20 pugs fudge
77 #?pugs todo
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
78 is $str, '123', "leave didn't trigger NEXT \{}";
79 }
80
81 {
82 my $str = '';
83 my sub foo {
84 for 1..5 {
85 NEXT { $str ~= $_ }
86 return if $_ > 3;
87 }
4677a6f3 »
2012-12-10 make S04-phasers/next.t robuster wrt laziness
88 0;
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
89 }
90 foo();
91 is $str, '123', "return didn't trigger NEXT \{}";
92 }
93
832f178c »
2010-03-18 [t/spec] fix more smartlinks; down to 33 broken links
94 # L<S04/Phasers/last bypasses evaluation of NEXT phasers>
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
95 {
96 my $str = '';
97 for 1..5 {
98 NEXT { $str ~= $_; }
99 last if $_ > 3;
100 }
101 is $str, '123', "last bypass NEXT \{}";
102 }
103
4e5f6047 »
2009-11-06 [t/spec] fix some smartlinks
104 # L<S04/Phasers/NEXT "before any LEAVE">
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
105
a553a91e »
2012-03-06 Fudge for Rakudo.
106 #?rakudo todo 'NEXT/LEAVE ordering'
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
107 {
108 my $str = '';
109 for 1..2 {
110 NEXT { $str ~= 'n' }
111 LEAVE { $str ~= 'l' }
112 }
a842b805 »
2012-02-20 pugs fudge
113 #?pugs todo
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
114 is $str, 'nlnl', 'NEXT {} ran before LEAVE {} (1)';
115 }
116
117 # reversed order
a553a91e »
2012-03-06 Fudge for Rakudo.
118 #?rakudo todo 'NEXT/LEAVE ordering'
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
119 {
120 my $str = '';
121 for 1..2 {
122 LEAVE { $str ~= 'l' }
123 NEXT { $str ~= 'n' }
124 }
a842b805 »
2012-02-20 pugs fudge
125 #?pugs todo
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
126 is $str, 'nlnl', 'NEXT {} ran before LEAVE {} (2)';
127 }
128
4e5f6047 »
2009-11-06 [t/spec] fix some smartlinks
129 # L<S04/Phasers/NEXT "at loop continuation time">
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
130
131 # L<http://groups.google.com/group/perl.perl6.language/msg/07370316d32890dd>
132
133 {
134 my $str = '';
135 my $n = 0;
136 my $i;
137 while $n < 5 {
138 NEXT { ++$n } # this gets run second (LIFO)
139 NEXT { $str ~= $n } # this gets run first (LIFO)
140 last if $i++ > 100; # recursion prevension
141 }
a842b805 »
2012-02-20 pugs fudge
142 #?pugs todo
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
143 is $str, '01234', 'NEXT {} ran in reversed order';
144 }
145
146 {
147 my $str = '';
148 loop (my $n = 0; $n < 5; ++$n) {
149 NEXT { $str ~= $n }
150 }
151 is $str, '01234', 'NEXT {} works in loop (;;) {}';
152 }
153
154 {
155 my @x = 0..4;
156 my $str = '';
157 for @x {
158 NEXT { $str ~= $_; }
159 }
160
a842b805 »
2012-02-20 pugs fudge
161 #?pugs todo
e7ca07b1 »
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
162 is($str, '01234', 'NEXT {} works in for loop');
163 }
7f29bc53 »
2009-08-08 [t/spec] Add vim: lines everywhere.
164
165 # vim: ft=perl6
Something went wrong with that request. Please try again.