Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 561 lines (461 sloc) 11.894 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 a…
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, p…
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, p…
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, p…
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, p…
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, p…
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 no…
jnthn authored
86 }
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
87
5a882b3 [spectest] Unskip a test for Rakudo, and remove some tests for the no…
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, p…
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, p…
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, p…
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, p…
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, p…
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, p…
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…
Auzon authored
166 # "for @a -> $var" is ro by default.
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
167 #?rakudo skip "<-> is confusing the parser, I think"
b1c8167 @coke pugs fudge
coke authored
168 #?pugs skip 'parsefail'
912dda9 [gsoc_spectest] added tests to for.t and fudged it for rakudo. (added…
Auzon authored
169 {
170 my @a = <1 2 3 4>;
171
172 eval_dies_ok('for @a -> $elem {$elem = 5}', '-> $var is ro by default');
173
174 for @a <-> $elem {$elem++;}
175 is(@a, <2 3 4 5>, '<-> $var is rw');
176
177 for @a <-> $first, $second {$first++; $second++}
178 is(@a, <3 4 5 6>, '<-> $var, $var2 works');
179 }
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
180
181 # for with "is rw"
182 {
183 my @array_s = (0..2);
184 my @s = (1..3);
185 for @array_s { $_++ };
186 is(@array_s, @s, 'for @array { $_++ }');
187 }
188
189 {
985603b [t/spec] merge mis-placed mutating_listops.t into S04-statements/for.t
moritz authored
190 my @array = <a b c d>;
191 for @array { $_ ~= "c" }
192 is ~@array, "ac bc cc dc",
193 'mutating $_ in for works';
194 }
195
196 {
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
197 my @array_t = (0..2);
198 my @t = (1..3);
199 for @array_t -> $val is rw { $val++ };
200 is(@array_t, @t, 'for @array -> $val is rw { $val++ }');
201 }
202
b1c8167 @coke pugs fudge
coke authored
203 #?pugs skip "Can't modify const item"
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
204 {
205 my @array_v = (0..2);
206 my @v = (1..3);
207 for @array_v.values -> $val is rw { $val++ };
ea2ee24 [STD] various bugs
lwall authored
208 is(@array_v, @v, 'for @array.values -> $val is rw { $val++ }');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
209 }
210
b1c8167 @coke pugs fudge
coke authored
211 #?pugs skip "Can't modify const item"
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
212 {
213 my @array_kv = (0..2);
214 my @kv = (1..3);
215 for @array_kv.kv -> $key, $val is rw { $val++ };
216 is(@array_kv, @kv, 'for @array.kv -> $key, $val is rw { $val++ }');
217 }
218
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
219 #?rakudo skip "is rw NYI"
b1c8167 @coke pugs fudge
coke authored
220 #?pugs skip "Can't modify const item"
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
221 {
222 my %hash_v = ( a => 1, b => 2, c => 3 );
223 my %v = ( a => 2, b => 3, c => 4 );
224 for %hash_v.values -> $val is rw { $val++ };
225 is(%hash_v, %v, 'for %hash.values -> $val is rw { $val++ }');
226 }
227
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
228 #?rakudo skip "is rw NYI"
b1c8167 @coke pugs fudge
coke authored
229 #?pugs todo
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
230 {
231 my %hash_kv = ( a => 1, b => 2, c => 3 );
232 my %kv = ( a => 2, b => 3, c => 4 );
233 try { for %hash_kv.kv -> $key, $val is rw { $val++ }; };
83474c3 [t/spec]: Clean up a few tests.
pmichaud authored
234 is( %hash_kv, %kv, 'for %hash.kv -> $key, $val is rw { $val++ }');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
235 }
236
237 # .key //= ++$i for @array1;
734bc95 [t/spec]
moritz authored
238 class TestClass{ has $.key is rw };
239
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
240 {
734bc95 [t/spec]
moritz authored
241 my @array1 = (TestClass.new(:key<1>),TestClass.new());
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
242 my $i = 0;
4e5c79c @sorear Fudge S04-statements/for.t for niecza
sorear authored
243 for @array1 { .key //= ++$i }
734bc95 [t/spec]
moritz authored
244 my $sum1 = [+] @array1.map: { $_.key };
ba8e84a [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
245 is( $sum1, 2, '.key //= ++$i for @array1;' );
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
246
247 }
248
249 # .key = 1 for @array1;
250 {
251 my @array1 = (TestClass.new(),TestClass.new(:key<2>));
252
734bc95 [t/spec]
moritz authored
253 .key = 1 for @array1;
254 my $sum1 = [+] @array1.map: { $_.key };
255 is($sum1, 2, '.key = 1 for @array1;');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
256 }
257
258 # $_.key = 1 for @array1;
259 {
260 my @array1 = (TestClass.new(),TestClass.new(:key<2>));
261
4837029 [spec] fudged for.t. Fails with 'Null PMC access in type()'
moritz authored
262 $_.key = 1 for @array1;
734bc95 [t/spec]
moritz authored
263 my $sum1 = [+] @array1.map: { $_.key };
264 is( $sum1, 2, '$_.key = 1 for @array1;');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
265
266 }
267
268 # rw scalars
269 #L<S04/The C<for> statement/implicit parameter to block read/write "by default">
270 {
271 my ($a, $b, $c) = 0..2;
272 try { for ($a, $b, $c) { $_++ } };
273 is( [$a,$b,$c], [1,2,3], 'for ($a,$b,$c) { $_++ }');
274
275 ($a, $b, $c) = 0..2;
276 try { for ($a, $b, $c) -> $x is rw { $x++ } };
277 is( [$a,$b,$c], [1,2,3], 'for ($a,$b,$c) -> $x is rw { $x++ }');
278 }
279
280 # list context
281
282 {
4837029 [spec] fudged for.t. Fails with 'Null PMC access in type()'
moritz authored
283 my $a = '';
ede6fd4 @coke pugs refudge (for "gist")
coke authored
284 my $b = '';
285 for 1..3, 4..6 { $a ~= $_.WHAT.gist ; $b ~= Int.gist };
286 is($a, $b, 'List context');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
287
288 $a = '';
afa3b69 Fix tests to concat the gist of the type object instead of the type o…
kboga authored
289 for [1..3, 4..6] { $a ~= $_.WHAT.gist };
ede6fd4 @coke pugs refudge (for "gist")
coke authored
290 is($a, Array.gist, 'List context');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
291
292 $a = '';
ede6fd4 @coke pugs refudge (for "gist")
coke authored
293 $b = '';
294 for [1..3], [4..6] { $a ~= $_.WHAT.gist ; $b ~= Array.gist };
295 is($a, $b, 'List context');
89aedbe [spec] moved for.t to spec/, updated POD
moritz authored
296 }
033e98b [t/spec] test for RT #58392, masak++
moritz authored
297
298 {
299 # 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
300 # confuse some lexical pads or the like, see RT #58392
033e98b [t/spec] test for RT #58392, masak++
moritz authored
301 my $gather = '';
302 sub f($l) {
303 if $l <= 0 {
304 return $l;
305 }
306 $gather ~= $l;
307 for 1..3 {
308 f($l-1);
309 $gather ~= '.';
310 }
311 }
312 f(2);
313
314 is $gather, '21....1....1....', 'Can mix recursion and for';
315 }
316
fe4c35b @moritz RT #103332, for loops, lexicals and recursion
moritz authored
317 # another variation
318 {
319 my $t = '';
320 my $c;
321 sub r($x) {
322 my $h = $c++;
323 r $x-1 if $x;
324 for 1 { $t ~= $h };
325 };
326 r 3;
327 is $t, '3210', 'can mix recursion and for (RT 103332)';
328 }
329
764328f [t] merged statements/grepa-and-sort-in-for.t into spec/S04-statement…
moritz authored
330 # grep and sort in for - these were pugs bugs once, so let's
331 # keep them as regression tests
332
333 {
334 my @array = <1 2 3 4>;
335 my $output = '';
336
337 for (grep { 1 }, @array) -> $elem {
338 $output ~= "$elem,";
339 }
340
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
341 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
342 }
343
344 {
345 my @array = <1 2 3 4>;
346 my $output = '';
347
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
348 for @array.sort -> $elem {
764328f [t] merged statements/grepa-and-sort-in-for.t into spec/S04-statement…
moritz authored
349 $output ~= "$elem,";
350 }
351
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
352 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
353 }
354
355 {
356 my @array = <1 2 3 4>;
959cd56 [t/spec] initialize a variable to make rakudo happy
moritz authored
357 my $output = '';
764328f [t] merged statements/grepa-and-sort-in-for.t into spec/S04-statement…
moritz authored
358
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
359 for (grep { 1 }, @array.sort) -> $elem {
764328f [t] merged statements/grepa-and-sort-in-for.t into spec/S04-statement…
moritz authored
360 $output ~= "$elem,";
361 }
362
363 is $output, "1,2,3,4,", "grep and sort work in for";
364 }
365
94226b4 t/spec more smartlink fixes
szabgab authored
366 # L<S04/Statement parsing/keywords require whitespace>
abbd86a [t/spec] Added test for required whitespace after a built-in statemen…
azawawi authored
367 eval_dies_ok('for(0..5) { }','keyword needs at least one whitespace after it');
368
6e27257 test for loop with two varibles
szabgab authored
369 # looping with more than one loop variables
370 {
371 my @a = <1 2 3 4>;
372 my $str = '';
373 for @a -> $x, $y {
374 $str ~= $x+$y;
375 }
376 is $str, "37", "for loop with two variables";
377 }
378
e681f59 for test
szabgab authored
379 {
380 #my $str = '';
4e5c79c @sorear Fudge S04-statements/for.t for niecza
sorear authored
381 eval_dies_ok('for 1..5 -> $x, $y { $str ~= "$x$y" }', 'Should throw exception, no value for parameter $y');
e681f59 for test
szabgab authored
382 #is $str, "1234", "loop ran before throwing exception";
383 #diag ">$str<";
384 }
385
68b11e4 [t/spec] label existing RT #63994 test
kyle authored
386 #?rakudo skip 'optional variable in for loop (RT #63994)'
42626ba @coke niecza (auto)unfudge
coke authored
387 #?niecza 2 todo 'NYI'
628aa1e more for related test
szabgab authored
388 {
389 my $str = '';
390 for 1..5 -> $x, $y? {
391 $str ~= " " ~ $x*$y;
392 }
393 is $str, " 2 12 0";
394 }
395
21ee055 test for loop with default value
szabgab authored
396 {
397 my $str = '';
398 for 1..5 -> $x, $y = 7 {
399 $str ~= " " ~ $x*$y;
400 }
82c7ae0 [t/spec] tests for :a[...] and :a{...} colonpair syntax
moritz authored
401 is $str, " 2 12 35", 'default values in for-loops';
21ee055 test for loop with default value
szabgab authored
402 }
403
b1c8167 @coke pugs fudge
coke authored
404 #?pugs todo
e681f59 for test
szabgab authored
405 {
406 my @a = <1 2 3>;
407 my @b = <4 5 6>;
408 my $res = '';
409 for @a Z @b -> $x, $y {
410 $res ~= " " ~ $x * $y;
411 }
412 is $res, " 4 10 18", "Z -ed for loop";
413 }
414
b1c8167 @coke pugs fudge
coke authored
415 #?pugs todo
628aa1e more for related test
szabgab authored
416 {
417 my @a = <1 2 3>;
418 my $str = '';
419
420 for @a Z @a Z @a Z @a Z @a -> $q, $w, $e, $r, $t {
421 $str ~= " " ~ $q*$w*$e*$r*$t;
422 }
423 is $str, " 1 {2**5} {3**5}", "Z-ed for loop with 5 arrays";
424 }
e681f59 for test
szabgab authored
425
5faff5e testing infinite for loops
szabgab authored
426 {
427 eval_dies_ok 'for 1.. { };', "Please use ..* for indefinite range";
428 eval_dies_ok 'for 1... { };', "1... does not exist";
429 }
430
431 {
432 my $c;
433 for 1..8 {
434 $c = $_;
435 last if $_ == 6;
436 }
437 is $c, 6, 'for loop ends in time using last';
438 }
439
440 {
441 my $c;
442 for 1..* {
443 $c = $_;
444 last if $_ == 6;
445 }
446 is $c, 6, 'infinte for loop ends in time using last';
447 }
448
449 {
450 my $c;
451 for 1..Inf {
452 $c = $_;
453 last if $_ == 6;
454 }
455 is $c, 6, 'infinte for loop ends in time using last';
456 }
457
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
458 # RT #62478
b1c8167 @coke pugs fudge
coke authored
459 #?pugs todo
f8f1bfd [t/spec] Massive refudge and tweaks to get for.t working in Rakudo, p…
colomon authored
460 {
001e798 @moritz &eval does not catch exceptions.
moritz authored
461 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
462 ok "$!" ~~ /C\-style/, 'mentions C-style';
463 ok "$!" ~~ /for/, 'mentions for';
464 ok "$!" ~~ /loop/, 'mentions loop';
465 }
466
4856f9e [t/spec] Test for RT #65212
kyle authored
467 # RT #65212
b1c8167 @coke pugs fudge
coke authored
468 #?pugs todo
4856f9e [t/spec] Test for RT #65212
kyle authored
469 {
470 my $parsed = 0;
001e798 @moritz &eval does not catch exceptions.
moritz authored
471 try { eval '$parsed = 1; for (1..3)->$n { last }' };
4856f9e [t/spec] Test for RT #65212
kyle authored
472 ok ! $parsed, 'for (1..3)->$n fails to parse';
473 }
e681f59 for test
szabgab authored
474
1c97b6e [t/spec] Test for RT 71268: NPMCA from accessing result of "for ^1 {}"
kyle authored
475 # RT #71268
476 {
477 sub rt71268 { for ^1 {} }
b1c8167 @coke pugs fudge
coke authored
478 #?pugs todo
1c97b6e [t/spec] Test for RT 71268: NPMCA from accessing result of "for ^1 {}"
kyle authored
479 lives_ok { ~(rt71268) }, 'can stringify "for ^1 {}" without death';
b1c8167 @coke pugs fudge
coke authored
480 #?pugs skip 'Cannot cast from VList to VCode'
feebd08 [t/spec]: Update some Nil-related tests for undefined Nil.
pmichaud authored
481 ok rt71268() ~~ (), 'result of "for ^1 {}" is ()';
1c97b6e [t/spec] Test for RT 71268: NPMCA from accessing result of "for ^1 {}"
kyle authored
482 }
483
6991d96 RT62478 Unsupported use of C-style "for (;;)" loop
vamped authored
484 # RT 62478
485 {
29fe361 [t/spec] remove a say() that would confuse the TAP parser when the te…
moritz authored
486 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
487 }
4e5c79c @sorear Fudge S04-statements/for.t for niecza
sorear authored
488
b1c8167 @coke pugs fudge
coke authored
489 #?pugs todo
6991d96 RT62478 Unsupported use of C-style "for (;;)" loop
vamped authored
490 {
001e798 @moritz &eval does not catch exceptions.
moritz authored
491 try { eval 'for (my $x; $x <=3; $x++) { $i; }'; diag($!) };
4e5c79c @sorear Fudge S04-statements/for.t for niecza
sorear authored
492 ok $! ~~ / 'C-style' /, 'Sensible error message';
6991d96 RT62478 Unsupported use of C-style "for (;;)" loop
vamped authored
493 }
1c97b6e [t/spec] Test for RT 71268: NPMCA from accessing result of "for ^1 {}"
kyle authored
494
c987a60 [t/spec] tests for RT #64886 For (1..10000000000) bug
bbkr authored
495 # RT #64886
7e60c7d Fudge S04-statements/for.t
kboga authored
496 #?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
497 {
498 my $a = 0;
499 for (1..10000000000) {
500 $a++;
501 last;
502 }
503 is $a, 1, 'for on Range with huge max value is lazy and enters block';
504 }
505
0b7f0f0 @moritz test for RT #60780, odd sized list and two iteration variables
moritz authored
506 # RT #60780
507 lives_ok {
508 for 1 .. 5 -> $x, $y? { }
509 }, 'Iteration variables do not need to add up if one is optional';
510
16bc94a @tadzik Add passing test for RT #78232
tadzik authored
511 # RT #78232
512 {
513 my $a = 0;
514 for 1, 2, 3 { sub foo {}; $a++ }
515 is $a, 3, 'RT #78232';
516 }
517
18f9e04 @sorear Test for sorear/niecza@fd3c735
sorear authored
518 # http://irclog.perlgeek.de/perl6/2011-12-29#i_4892285
519 # (Niecza bug)
520 {
521 my $x = 0;
522 for 1 .. 2 -> $a, $b { $x = $b } #OK not used
523 is $x, 2, 'Lazy lists interact properly with multi-element for loops';
524 }
525
8b33523 @moritz RT #71270, simple case of list comprehension
moritz authored
526 # RT #71270
527 # list comprehension
b1c8167 @coke pugs fudge
coke authored
528 #?pugs skip 'Cannot cast from VList to VCode'
8b33523 @moritz RT #71270, simple case of list comprehension
moritz authored
529 {
530 sub f() { for ^1 { } };
531 is ~f(), '', 'empty for-loop returns empty list';
532 }
533
87f3d51 @moritz RT #74060, statment modifying "for" in list comprehension
moritz authored
534 # RT #74060
535 # more list comprehension
b1c8167 @coke pugs fudge
coke authored
536 #?pugs skip 'parsefail'
87f3d51 @moritz RT #74060, statment modifying "for" in list comprehension
moritz authored
537 {
538 my @s = ($_ * 2 if $_ ** 2 > 3 for 0 .. 5);
3ee43f2 @moritz fix logic error in previous commit. Ooops.
moritz authored
539 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
540 }
541
8eec946 @kyleha [for.t] Test for RT 113026: array iterator does not track a growing a…
kyleha authored
542 # RT 113026
543 #?rakudo todo 'RT 113026 array iterator does not track a growing array'
d94ae21 @colomon Fudge new tests for Niecza.
colomon authored
544 #?niecza todo 'array iterator does not track a growing array'
1e47107 @coke pugs fudge
coke authored
545 #?pugs todo
8eec946 @kyleha [for.t] Test for RT 113026: array iterator does not track a growing a…
kyleha authored
546 {
547 my @rt113026 = 1 .. 10;
548 my $iter = 0;
549 for @rt113026 -> $n {
550 $iter++;
551 if $iter % 2 {
552 @rt113026.push: $n;
553 }
554 }
555 is $iter, 20, 'iterating over an expanding list';
556 is @rt113026, <1 2 3 4 5 6 7 8 9 10 1 3 5 7 9 1 5 9 5 5>,
557 'array expanded in for loop is expanded';
558 }
559
061d002 [t/spec] various small improvements.
moritz authored
560 # vim: ft=perl6
Something went wrong with that request. Please try again.