Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 532 lines (432 sloc) 11.165 kB
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
1 use v6;
2
db4bde7 [t/spec] add 'use MONKEY_TYPING' where appropriate
lwall authored
3 use MONKEY_TYPING;
4
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
5 use Test;
6
7 =begin description
8
9 Tests the "for" statement
10
11 This attempts to test as many variations of the
12 for statement as possible
13
14 =end description
15
87f3d51 @moritz RT #74060, statment modifying "for" in list comprehension
moritz authored
16 plan 71;
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
17
18 ## No foreach
19 # L<S04/The C<for> statement/"no foreach statement any more">
20 {
21 my $times_run = 0;
22 eval_dies_ok 'foreach 1..10 { $times_run++ }; 1', "foreach is gone";
23 eval_dies_ok 'foreach (1..10) { $times_run++}; 1',
24 "foreach is gone, even with parens";
25 is $times_run, 0, "foreach doesn't work";
26 }
27
28 ## for with plain old range operator w/out parens
29
30 {
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
31 my $a = "";
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
32 for 0 .. 5 { $a = $a ~ $_; };
33 is($a, '012345', 'for 0..5 {} works');
34 }
35
36 # ... with pointy blocks
37
38 {
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
39 my $b = "";
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
40 for 0 .. 5 -> $_ { $b = $b ~ $_; };
41 is($b, '012345', 'for 0 .. 5 -> {} works');
42 }
43
44 #?pugs eval 'todo: slice context'
4e5c79c @sorear Fudge S04-statements/for.t for niecza
sorear authored
45 #?niecza skip 'slice context'
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
46 {
47 my $str;
48 my @a = 1..3;
3c9d437 @felher [S04-statements/for.t] fix test: 'for zip(@a; @b) -> $x, $y'
felher authored
49 my @b = 4..6;
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
50 for zip(@a; @b) -> $x, $y {
51 $str ~= "($x $y)";
52 }
3c9d437 @felher [S04-statements/for.t] fix test: 'for zip(@a; @b) -> $x, $y'
felher authored
53 is $str, "(1 4)(2 5)(3 6)", 'for zip(@a; @b) -> $x, $y works';
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
54 }
55
56 # ... with referential sub
57 {
1888ab6 @felliott [for.t] fix and unfudge test that was failing due to range bug
felliott authored
58 my $d = "";
59 for -2 .. 2 { $d ~= .sign };
60 is($d, '-1-1011', 'for 0 .. 5 { .some_sub } works');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
61 }
62
63 ## and now with parens around the range operator
64 {
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
65 my $e = "";
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
66 for (0 .. 5) { $e = $e ~ $_; };
67 is($e, '012345', 'for () {} works');
68 }
69
70 # ... with pointy blocks
71 {
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
72 my $f = "";
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
73 for (0 .. 5) -> $_ { $f = $f ~ $_; };
74 is($f, '012345', 'for () -> {} works');
75 }
76
77 # ... with implicit topic
78
79 {
80 $_ = "GLOBAL VALUE";
81 for "INNER VALUE" {
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
82 is( .lc, "inner value", "Implicit default topic is seen by lc()");
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
83 };
84 is($_,"GLOBAL VALUE","After the loop the implicit topic gets restored");
5a882b3 [spectest] Unskip a test for Rakudo, and remove some tests for the no…
jnthn authored
85 }
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
86
5a882b3 [spectest] Unskip a test for Rakudo, and remove some tests for the no…
jnthn authored
87 {
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
88 # as statement modifier
89 $_ = "GLOBAL VALUE";
90 is( .lc, "inner value", "Implicit default topic is seen by lc()" )
91 for "INNER VALUE";
92 is($_,"GLOBAL VALUE","After the loop the implicit topic gets restored");
93 }
94
95 ## and now for with 'topical' variables
96
97 # ... w/out parens
98
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
99 my $i = "";
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
100 for 0 .. 5 -> $topic { $i = $i ~ $topic; };
101 is($i, '012345', 'for 0 .. 5 -> $topic {} works');
102
103 # ... with parens
104
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
105 my $j = "";
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
106 for (0 .. 5) -> $topic { $j = $j ~ $topic; };
107 is($j, '012345', 'for () -> $topic {} works');
108
109
110 ## for with @array operator w/out parens
111
112 my @array_k = (0 .. 5);
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
113 my $k = "";
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
114 for @array_k { $k = $k ~ $_; };
115 is($k, '012345', 'for @array {} works');
116
117 # ... with pointy blocks
118
119 my @array_l = (0 .. 5);
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
120 my $l = "";
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
121 for @array_l -> $_ { $l = $l ~ $_; };
122 is($l, '012345', 'for @array -> {} works');
123
124 ## and now with parens around the @array
125
126 my @array_o = (0 .. 5);
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
127 my $o = "";
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
128 for (@array_o) { $o = $o ~ $_; };
129 is($o, '012345', 'for (@array) {} works');
130
131 # ... with pointy blocks
132 {
133 my @array_p = (0 .. 5);
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
134 my $p = "";
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
135 for (@array_p) -> $_ { $p = $p ~ $_; };
136 is($p, '012345', 'for (@array) -> {} works');
137 }
138
139 my @elems = <a b c d e>;
140
141 {
142 my @a;
143 for (@elems) {
144 push @a, $_;
145 }
146 my @e = <a b c d e>;
147 is(@a, @e, 'for (@a) { ... $_ ... } iterates all elems');
148 }
149
150 {
151 my @a;
152 for (@elems) -> $_ { push @a, $_ };
153 my @e = @elems;
154 is(@a, @e, 'for (@a)->$_ { ... $_ ... } iterates all elems' );
155 }
156
157 {
158 my @a;
159 for (@elems) { push @a, $_, $_; }
160 my @e = <a a b b c c d d e e>;
161 is(@a, @e, 'for (@a) { ... $_ ... $_ ... } iterates all elems, not just odd');
162 }
163
912dda9 [gsoc_spectest] added tests to for.t and fudged it for rakudo. (added…
Auzon authored
164 # "for @a -> $var" is ro by default.
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
165 #?rakudo skip "<-> is confusing the parser, I think"
912dda9 [gsoc_spectest] added tests to for.t and fudged it for rakudo. (added…
Auzon authored
166 {
167 my @a = <1 2 3 4>;
168
169 eval_dies_ok('for @a -> $elem {$elem = 5}', '-> $var is ro by default');
170
171 for @a <-> $elem {$elem++;}
172 is(@a, <2 3 4 5>, '<-> $var is rw');
173
174 for @a <-> $first, $second {$first++; $second++}
175 is(@a, <3 4 5 6>, '<-> $var, $var2 works');
176 }
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
177
178 # for with "is rw"
179 {
180 my @array_s = (0..2);
181 my @s = (1..3);
182 for @array_s { $_++ };
183 is(@array_s, @s, 'for @array { $_++ }');
184 }
185
186 {
985603b [t/spec] merge mis-placed mutating_listops.t into S04-statements/for.t
moritz authored
187 my @array = <a b c d>;
188 for @array { $_ ~= "c" }
189 is ~@array, "ac bc cc dc",
190 'mutating $_ in for works';
191 }
192
193 {
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
194 my @array_t = (0..2);
195 my @t = (1..3);
196 for @array_t -> $val is rw { $val++ };
197 is(@array_t, @t, 'for @array -> $val is rw { $val++ }');
198 }
199
200 #?pugs eval 'todo'
201 {
202 my @array_v = (0..2);
203 my @v = (1..3);
204 for @array_v.values -> $val is rw { $val++ };
ea2ee24 [STD] various bugs
lwall authored
205 is(@array_v, @v, 'for @array.values -> $val is rw { $val++ }');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
206 }
207
208 #?pugs eval 'todo'
209 {
210 my @array_kv = (0..2);
211 my @kv = (1..3);
212 for @array_kv.kv -> $key, $val is rw { $val++ };
213 is(@array_kv, @kv, 'for @array.kv -> $key, $val is rw { $val++ }');
214 }
215
216 #?pugs eval 'todo'
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
217 #?rakudo skip "is rw NYI"
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
218 {
219 my %hash_v = ( a => 1, b => 2, c => 3 );
220 my %v = ( a => 2, b => 3, c => 4 );
221 for %hash_v.values -> $val is rw { $val++ };
222 is(%hash_v, %v, 'for %hash.values -> $val is rw { $val++ }');
223 }
224
225 #?pugs eval 'todo'
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
226 #?rakudo skip "is rw NYI"
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
227 {
228 my %hash_kv = ( a => 1, b => 2, c => 3 );
229 my %kv = ( a => 2, b => 3, c => 4 );
230 try { for %hash_kv.kv -> $key, $val is rw { $val++ }; };
83474c3 [t/spec]: Clean up a few tests.
pmichaud authored
231 is( %hash_kv, %kv, 'for %hash.kv -> $key, $val is rw { $val++ }');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
232 }
233
234 # .key //= ++$i for @array1;
734bc95 [t/spec]
moritz authored
235 class TestClass{ has $.key is rw };
236
b7e8250 [t/spec] fixed unfudge mistake
bbkr authored
237 #?rakudo skip '[+] NYI'
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
238 {
734bc95 [t/spec]
moritz authored
239 my @array1 = (TestClass.new(:key<1>),TestClass.new());
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
240 my $i = 0;
4e5c79c @sorear Fudge S04-statements/for.t for niecza
sorear authored
241 for @array1 { .key //= ++$i }
734bc95 [t/spec]
moritz authored
242 my $sum1 = [+] @array1.map: { $_.key };
ba8e84a [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
243 #?pugs todo 'bug'
244 is( $sum1, 2, '.key //= ++$i for @array1;' );
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
245
246 }
247
248 # .key = 1 for @array1;
249 {
250 my @array1 = (TestClass.new(),TestClass.new(:key<2>));
251
734bc95 [t/spec]
moritz authored
252 .key = 1 for @array1;
253 my $sum1 = [+] @array1.map: { $_.key };
254 is($sum1, 2, '.key = 1 for @array1;');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
255 }
256
257 # $_.key = 1 for @array1;
258 {
259 my @array1 = (TestClass.new(),TestClass.new(:key<2>));
260
4837029 [spec] fudged for.t. Fails with 'Null PMC access in type()'
moritz authored
261 $_.key = 1 for @array1;
734bc95 [t/spec]
moritz authored
262 my $sum1 = [+] @array1.map: { $_.key };
263 is( $sum1, 2, '$_.key = 1 for @array1;');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
264
265 }
266
267 # rw scalars
268 #L<S04/The C<for> statement/implicit parameter to block read/write "by default">
269 {
270 my ($a, $b, $c) = 0..2;
271 try { for ($a, $b, $c) { $_++ } };
272 is( [$a,$b,$c], [1,2,3], 'for ($a,$b,$c) { $_++ }');
273
274 ($a, $b, $c) = 0..2;
275 try { for ($a, $b, $c) -> $x is rw { $x++ } };
276 is( [$a,$b,$c], [1,2,3], 'for ($a,$b,$c) -> $x is rw { $x++ }');
277 }
278
279 # list context
280
281 {
4837029 [spec] fudged for.t. Fails with 'Null PMC access in type()'
moritz authored
282 my $a = '';
afa3b69 Fix tests to concat the gist of the type object instead of the type o…
kboga authored
283 for 1..3, 4..6 { $a ~= $_.WHAT.gist };
a524b51 [t/spec]: protoobjects stringify to shortname plus parens (S12)
pmichaud authored
284 is($a, 'Int()Int()Int()Int()Int()Int()', 'List context');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
285
286 $a = '';
afa3b69 Fix tests to concat the gist of the type object instead of the type o…
kboga authored
287 for [1..3, 4..6] { $a ~= $_.WHAT.gist };
a524b51 [t/spec]: protoobjects stringify to shortname plus parens (S12)
pmichaud authored
288 is($a, 'Array()', 'List context');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
289
290 $a = '';
afa3b69 Fix tests to concat the gist of the type object instead of the type o…
kboga authored
291 for [1..3], [4..6] { $a ~= $_.WHAT.gist };
a524b51 [t/spec]: protoobjects stringify to shortname plus parens (S12)
pmichaud authored
292 is($a, 'Array()Array()', 'List context');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
293 }
033e98b [t/spec] test for RT #58392, masak++
moritz authored
294
295 {
296 # this was a rakudo bug with mixed 'for' and recursion, which seems to
919fc4f [t/spec] unfudge passing rakudo test after lex branch merge (in for.t)
moritz authored
297 # confuse some lexical pads or the like, see RT #58392
033e98b [t/spec] test for RT #58392, masak++
moritz authored
298 my $gather = '';
299 sub f($l) {
300 if $l <= 0 {
301 return $l;
302 }
303 $gather ~= $l;
304 for 1..3 {
305 f($l-1);
306 $gather ~= '.';
307 }
308 }
309 f(2);
310
311 is $gather, '21....1....1....', 'Can mix recursion and for';
312 }
313
fe4c35b @moritz RT #103332, for loops, lexicals and recursion
moritz authored
314 # another variation
315 {
316 my $t = '';
317 my $c;
318 sub r($x) {
319 my $h = $c++;
320 r $x-1 if $x;
321 for 1 { $t ~= $h };
322 };
323 r 3;
324 is $t, '3210', 'can mix recursion and for (RT 103332)';
325 }
326
764328f [t] merged statements/grepa-and-sort-in-for.t into spec/S04-statement…
moritz authored
327 # grep and sort in for - these were pugs bugs once, so let's
328 # keep them as regression tests
329
330 {
331 my @array = <1 2 3 4>;
332 my $output = '';
333
334 for (grep { 1 }, @array) -> $elem {
335 $output ~= "$elem,";
336 }
337
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
338 is $output, "1,2,3,4,", "grep works in for";
764328f [t] merged statements/grepa-and-sort-in-for.t into spec/S04-statement…
moritz authored
339 }
340
341 {
342 my @array = <1 2 3 4>;
343 my $output = '';
344
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
345 for @array.sort -> $elem {
764328f [t] merged statements/grepa-and-sort-in-for.t into spec/S04-statement…
moritz authored
346 $output ~= "$elem,";
347 }
348
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
349 is $output, "1,2,3,4,", "sort works in for";
764328f [t] merged statements/grepa-and-sort-in-for.t into spec/S04-statement…
moritz authored
350 }
351
352 {
353 my @array = <1 2 3 4>;
959cd56 [t/spec] initialize a variable to make rakudo happy
moritz authored
354 my $output = '';
764328f [t] merged statements/grepa-and-sort-in-for.t into spec/S04-statement…
moritz authored
355
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
356 for (grep { 1 }, @array.sort) -> $elem {
764328f [t] merged statements/grepa-and-sort-in-for.t into spec/S04-statement…
moritz authored
357 $output ~= "$elem,";
358 }
359
360 is $output, "1,2,3,4,", "grep and sort work in for";
361 }
362
94226b4 t/spec more smartlink fixes
szabgab authored
363 # L<S04/Statement parsing/keywords require whitespace>
abbd86a [t/spec] Added test for required whitespace after a built-in statemen…
azawawi authored
364 eval_dies_ok('for(0..5) { }','keyword needs at least one whitespace after it');
365
6e27257 test for loop with two varibles
szabgab authored
366 # looping with more than one loop variables
367 {
368 my @a = <1 2 3 4>;
369 my $str = '';
370 for @a -> $x, $y {
371 $str ~= $x+$y;
372 }
373 is $str, "37", "for loop with two variables";
374 }
375
e681f59 for test
szabgab authored
376 {
377 #my $str = '';
4e5c79c @sorear Fudge S04-statements/for.t for niecza
sorear authored
378 eval_dies_ok('for 1..5 -> $x, $y { $str ~= "$x$y" }', 'Should throw exception, no value for parameter $y');
e681f59 for test
szabgab authored
379 #is $str, "1234", "loop ran before throwing exception";
380 #diag ">$str<";
381 }
382
68b11e4 [t/spec] label existing RT #63994 test
kyle authored
383 #?rakudo skip 'optional variable in for loop (RT #63994)'
42626ba @coke niecza (auto)unfudge
coke authored
384 #?niecza 2 todo 'NYI'
628aa1e more for related test
szabgab authored
385 {
386 my $str = '';
387 for 1..5 -> $x, $y? {
388 $str ~= " " ~ $x*$y;
389 }
390 is $str, " 2 12 0";
391 }
392
21ee055 test for loop with default value
szabgab authored
393 {
394 my $str = '';
395 for 1..5 -> $x, $y = 7 {
396 $str ~= " " ~ $x*$y;
397 }
82c7ae0 [t/spec] tests for :a[...] and :a{...} colonpair syntax
moritz authored
398 is $str, " 2 12 35", 'default values in for-loops';
21ee055 test for loop with default value
szabgab authored
399 }
400
401
e681f59 for test
szabgab authored
402 {
403 my @a = <1 2 3>;
404 my @b = <4 5 6>;
405 my $res = '';
406 for @a Z @b -> $x, $y {
407 $res ~= " " ~ $x * $y;
408 }
409 is $res, " 4 10 18", "Z -ed for loop";
410 }
411
628aa1e more for related test
szabgab authored
412 {
413 my @a = <1 2 3>;
414 my $str = '';
415
416 for @a Z @a Z @a Z @a Z @a -> $q, $w, $e, $r, $t {
417 $str ~= " " ~ $q*$w*$e*$r*$t;
418 }
419 is $str, " 1 {2**5} {3**5}", "Z-ed for loop with 5 arrays";
420 }
e681f59 for test
szabgab authored
421
5faff5e testing infinite for loops
szabgab authored
422 {
423 eval_dies_ok 'for 1.. { };', "Please use ..* for indefinite range";
424 eval_dies_ok 'for 1... { };', "1... does not exist";
425 }
426
427 {
428 my $c;
429 for 1..8 {
430 $c = $_;
431 last if $_ == 6;
432 }
433 is $c, 6, 'for loop ends in time using last';
434 }
435
436 {
437 my $c;
438 for 1..* {
439 $c = $_;
440 last if $_ == 6;
441 }
442 is $c, 6, 'infinte for loop ends in time using last';
443 }
444
445 {
446 my $c;
447 for 1..Inf {
448 $c = $_;
449 last if $_ == 6;
450 }
451 is $c, 6, 'infinte for loop ends in time using last';
452 }
453
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
454 # RT #62478
455 {
001e798 @moritz &eval does not catch exceptions.
moritz authored
456 try { eval('for (my $ii = 1; $ii <= 3; $ii++) { say $ii; }') };
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
457 ok "$!" ~~ /C\-style/, 'mentions C-style';
458 ok "$!" ~~ /for/, 'mentions for';
459 ok "$!" ~~ /loop/, 'mentions loop';
460 }
461
4856f9e [t/spec] Test for RT #65212
kyle authored
462 # RT #65212
463 {
464 my $parsed = 0;
001e798 @moritz &eval does not catch exceptions.
moritz authored
465 try { eval '$parsed = 1; for (1..3)->$n { last }' };
4856f9e [t/spec] Test for RT #65212
kyle authored
466 ok ! $parsed, 'for (1..3)->$n fails to parse';
467 }
e681f59 for test
szabgab authored
468
1c97b6e [t/spec] Test for RT 71268: NPMCA from accessing result of "for ^1 {}"
kyle authored
469 # RT #71268
470 {
471 sub rt71268 { for ^1 {} }
472 lives_ok { ~(rt71268) }, 'can stringify "for ^1 {}" without death';
feebd08 [t/spec]: Update some Nil-related tests for undefined Nil.
pmichaud authored
473 ok rt71268() ~~ (), 'result of "for ^1 {}" is ()';
1c97b6e [t/spec] Test for RT 71268: NPMCA from accessing result of "for ^1 {}"
kyle authored
474 }
475
6991d96 RT62478 Unsupported use of C-style "for (;;)" loop
vamped authored
476 # RT 62478
477 {
29fe361 [t/spec] remove a say() that would confuse the TAP parser when the te…
moritz authored
478 eval_dies_ok 'for (my $i; $i <=3; $i++) { $i; }', 'Unsupported use of C-style "for (;;)" loop; in Perl 6 please use "loop (;;)"';
6991d96 RT62478 Unsupported use of C-style "for (;;)" loop
vamped authored
479 }
4e5c79c @sorear Fudge S04-statements/for.t for niecza
sorear authored
480
6991d96 RT62478 Unsupported use of C-style "for (;;)" loop
vamped authored
481 {
001e798 @moritz &eval does not catch exceptions.
moritz authored
482 try { eval 'for (my $x; $x <=3; $x++) { $i; }'; diag($!) };
4e5c79c @sorear Fudge S04-statements/for.t for niecza
sorear authored
483 ok $! ~~ / 'C-style' /, 'Sensible error message';
6991d96 RT62478 Unsupported use of C-style "for (;;)" loop
vamped authored
484 }
1c97b6e [t/spec] Test for RT 71268: NPMCA from accessing result of "for ^1 {}"
kyle authored
485
c987a60 [t/spec] tests for RT #64886 For (1..10000000000) bug
bbkr authored
486 # RT #64886
7e60c7d Fudge S04-statements/for.t
kboga authored
487 #?rakudo skip "Nom doesn't feature lazily for looping over a range yet?"
c987a60 [t/spec] tests for RT #64886 For (1..10000000000) bug
bbkr authored
488 {
489 my $a = 0;
490 for (1..10000000000) {
491 $a++;
492 last;
493 }
494 is $a, 1, 'for on Range with huge max value is lazy and enters block';
495 }
496
0b7f0f0 @moritz test for RT #60780, odd sized list and two iteration variables
moritz authored
497 # RT #60780
498 lives_ok {
499 for 1 .. 5 -> $x, $y? { }
500 }, 'Iteration variables do not need to add up if one is optional';
501
16bc94a @tadzik Add passing test for RT #78232
tadzik authored
502 # RT #78232
503 {
504 my $a = 0;
505 for 1, 2, 3 { sub foo {}; $a++ }
506 is $a, 3, 'RT #78232';
507 }
508
18f9e04 @sorear Test for sorear/niecza@fd3c735
sorear authored
509 # http://irclog.perlgeek.de/perl6/2011-12-29#i_4892285
510 # (Niecza bug)
511 {
512 my $x = 0;
513 for 1 .. 2 -> $a, $b { $x = $b } #OK not used
514 is $x, 2, 'Lazy lists interact properly with multi-element for loops';
515 }
516
8b33523 @moritz RT #71270, simple case of list comprehension
moritz authored
517 # RT #71270
518 # list comprehension
519 {
520 sub f() { for ^1 { } };
521 is ~f(), '', 'empty for-loop returns empty list';
522 }
523
87f3d51 @moritz RT #74060, statment modifying "for" in list comprehension
moritz authored
524 # RT #74060
525 # more list comprehension
526 {
527 my @s = ($_ * 2 if $_ ** 2 > 3 for 0 .. 5);
528 is ~@s, '4 9 16 25', 'Can use statement-modifying "for" in list comprehension';
529 }
530
061d002 [t/spec] various small improvements.
moritz authored
531 # vim: ft=perl6
Something went wrong with that request. Please try again.