Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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