Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 62 lines (49 sloc) 1.499 kb
1128b30 [t] moved loopscope.t to spec/, simplfied a bit
moritz authored
1 use v6;
2
3 use Test;
4
76ad216 fix some more smartlinks
szabgab authored
5 # L<S04/The C<for> statement>
6
632ffb7 @moritz get rid of some unused (and partially wrong) lexicals; fudge for-scope.t...
moritz authored
7 plan 16;
1128b30 [t] moved loopscope.t to spec/, simplfied a bit
moritz authored
8
9 # Implicit $_
10 for 1, 2 {
11 my $inside = '';
12 for 1 .. 3 { $inside ~= $_; }
13 is($inside, "123", "lexical scalar properly initialized, round $_");
14 }
15
16 for 1, 2 {
17 my @inside;
18 for 1 .. 3 { push @inside, $_; }
49d046f .join now defaults to ''
lwall authored
19 is(@inside.join, "123", "lexical array properly initialized, round $_");
1128b30 [t] moved loopscope.t to spec/, simplfied a bit
moritz authored
20 }
21
22 # Explicit $_
23 for 1, 2 {
24 my $inside = '';
25 for 1 .. 3 -> $_ { $inside ~= $_; }
26 is($inside, "123", "lexical scalar properly initialized, round $_, explicit \$_");
27 }
28
29 for 1, 2 {
30 my @inside;
31 for 1 .. 3 -> $_ { push @inside, $_; }
49d046f .join now defaults to ''
lwall authored
32 is(@inside.join, "123", "lexical array properly initialized, round $_, explicit \$_");
1128b30 [t] moved loopscope.t to spec/, simplfied a bit
moritz authored
33 }
34
35 # Explicit $_
36 for 1, 2 -> $_ {
37 my $inside = '';
38 for 1 .. 3 -> $_ { $inside ~= $_; }
39 is($inside, "123", "lexical scalar properly initialized, round $_, two explicit \$_s");
40 }
41
42 for 1, 2 -> $_ {
43 my @inside;
44 for 1 .. 3 -> $_ { push @inside, $_; }
49d046f .join now defaults to ''
lwall authored
45 is(@inside.join, "123", "lexical array properly initialized, round $_, two explicit \$_s");
1128b30 [t] moved loopscope.t to spec/, simplfied a bit
moritz authored
46 }
80b0155 [S04-statements/for-scope.t] added tests against [perl #60404]
masak authored
47
d75b5b3 [t/spec rakudo] fudge some tests for slurpy params
particle authored
48 {
49 sub respect(*@a) {
50 my @b = ();
207f13f [t] and [t/spec]
moritz authored
51 @b.push($_) for @a;
d75b5b3 [t/spec rakudo] fudge some tests for slurpy params
particle authored
52 return @b.elems;
53 }
54
55 is respect(1,2,3), 3, 'a for loop inside a sub loops over each of the elements';
207f13f [t] and [t/spec]
moritz authored
56 is respect([1,2,3]), 1, '... but only over one array ref';
d75b5b3 [t/spec rakudo] fudge some tests for slurpy params
particle authored
57 is respect( my @a = 1, 2, 3 ), 3, '...and when the array is declared in the argument list';
fe270aa @sorear Fix typo in S04/for-scope.t
sorear authored
58 is @a.join(','), '1,2,3', 'and the array get the right values';
80b0155 [S04-statements/for-scope.t] added tests against [perl #60404]
masak authored
59 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
60
61 # vim: ft=perl6
Something went wrong with that request. Please try again.