Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 88 lines (61 sloc) 1.495 kb
1407f9d [t/statemets] deleted until.t, since the same version was already in t/s...
dr_df0 authored
1 use v6;
2
3 use Test;
4
76ad216 fix some more smartlinks
szabgab authored
5 # L<S04/The C<for> statement>
6
1407f9d [t/statemets] deleted until.t, since the same version was already in t/s...
dr_df0 authored
7 # Test primarily aimed at PIL2JS
8
2d495bf [t/spec] tests for RT #73400 Cannot loop over Capture object in Rakudo
bbkr authored
9 plan 9;
1407f9d [t/statemets] deleted until.t, since the same version was already in t/s...
dr_df0 authored
10
11 # sanity tests
12 {
13 my $res='';
14
15 for <a b c> { $res ~= $_ }
16 is $res, "abc", "for works with an <...> array literal";
17 }
18
19 {
20 my $res='';
21
22 for (<a b c>) { $res ~= $_ }
23 is $res, "abc", "for works with an (<...>) array literal";
24 }
25
26 # for with only one item, a constant
27 {
28 my $res='';
29
30 for ("a",) { $res ~= $_ }
31 is $res, "a", "for works with an (a_single_constant,) array literal";
32 }
33
34 {
35 my $res='';
36
37 for ("a") { $res ~= $_ }
38 is $res, "a", "for works with (a_single_constant)";
39 }
40
41 {
42 my $res='';
43
44 for "a" { $res ~= $_ }
45 is $res, "a", "for works with \"a_single_constant\"";
46 }
47
48 # for with only one item, an arrayref
49 # See thread "for $arrayref {...}" on p6l started by Ingo Blechschmidt,
50 # L<"http://www.nntp.perl.org/group/perl.perl6.language/22970">
51 {
52 my $arrayref = [1,2,3];
53
54 my $count=0;
55 for ($arrayref,) { $count++ }
56
57 is $count, 1, 'for ($arrayref,) {...} executes the loop body only once';
58 }
59
60 {
61 my $arrayref = [1,2,3];
62
63 my $count=0;
64 for ($arrayref) { $count++ }
65
66 is $count, 1, 'for ($arrayref) {...} executes the loop body only once';
67 }
68
69 {
70 my $arrayref = [1,2,3];
71
72 my $count=0;
73 for $arrayref { $count++ }
74
75 is $count, 1, 'for $arrayref {...} executes the loop body only once';
76 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
77
2d495bf [t/spec] tests for RT #73400 Cannot loop over Capture object in Rakudo
bbkr authored
78 # RT #73400
79 {
80 my $capture = \[1,2,3];
81 my $count = 0;
82 for $capture { $count++ }
83
84 is $count, 1, 'for $capture {...} executes the loop body only once';
85 }
86
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
87 # vim: ft=perl6
Something went wrong with that request. Please try again.