Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 157 lines (129 sloc) 3.298 kb
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
1 use v6;
2
3 use Test;
4
fdaa7dc @usev6 Unfudge passing test for RT #116178, add 2nd test
usev6 authored
5 plan 27;
1b91866 @coke Convert to explicit plan
coke authored
6
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
7 # L<S04/"Conditional statements"/Conditional statement modifiers work as in Perl 5>
8
9 # test the for statement modifier
10 {
437d050 [t/spec] simplified some tests in for.t by initializing variables
moritz authored
11 my $a = '';
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
12 $a ~= $_ for ('a', 'b', 'a', 'b', 'a');
13 is($a, "ababa", "post for with parens");
14 }
15
16 # without parens
17 {
437d050 [t/spec] simplified some tests in for.t by initializing variables
moritz authored
18 my $a = '';
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
19 $a ~= $_ for 'a', 'b', 'a', 'b', 'a';
20 is($a, "ababa", "post for without parens");
21 }
22
23 {
437d050 [t/spec] simplified some tests in for.t by initializing variables
moritz authored
24 my $a = 0;
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
25 $a += $_ for (1 .. 10);
26 is($a, 55, "post for 1 .. 10 with parens");
27 }
28
29 {
437d050 [t/spec] simplified some tests in for.t by initializing variables
moritz authored
30 my $a = 0;
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
31 $a += $_ for 1 .. 10;
32 is($a, 55, "post for 1 .. 10 without parens");
33 }
34
35 {
36 my @a = (5, 7, 9);
37 my $a = 3;
38 $a *= $_ for @a;
39 is($a, 3 * 5 * 7 * 9, "post for array");
40 }
41
42 {
43 my @a = (5, 7, 9);
44 my $i = 5;
45 my sub check(Int $n){
46 is($n, $i, "sub Int with post for");
47 $i += 2;
48 }
49 check $_ for @a;
50 }
51
e9709e5 [t/spec] Add a couple of tests for the one-arg statement modifier for…
duff authored
52 {
53 my $a = "";
54 $a ~= "<$_>" for "hello";
55 is $a, "<hello>", 'iterating one constant element works';
56 }
57
58 {
59 my $a = ""; my $v = "hello";
60 $a ~= "<$_>" for $v;
61 is $a, "<hello>", 'iterating one variable element works';
62 }
63
5f0bdab @coke niecza unfudge
coke authored
64 #?niecza todo "closure for"
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
65 {
437d050 [t/spec] simplified some tests in for.t by initializing variables
moritz authored
66 my $a = 0;
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
67 { $a++ } for 1..3;
f203400 [t/spec]: Update testing in for.t of statement_modifier:for on blocks.
pmichaud authored
68 is $a, 3, 'the closure was called';
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
69 }
70
5f0bdab @coke niecza unfudge
coke authored
71 #?niecza todo "closure for"
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
72 {
437d050 [t/spec] simplified some tests in for.t by initializing variables
moritz authored
73 my $a = 0;
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
74 -> $i { $a += $i } for 1..3;
f203400 [t/spec]: Update testing in for.t of statement_modifier:for on blocks.
pmichaud authored
75 is $a, 6, 'the closure was called';
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
76 }
77
48992f8 [t/spec] fix all remaining broken smartlinks
moritz authored
78 # L<S04/The C<for> statement/for and given privately temporize>
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
79 {
437d050 [t/spec] simplified some tests in for.t by initializing variables
moritz authored
80 my $i = 0;
f5b8171 [spec] added from t/statements/modifiers/ and fudged t/spec/S05-modif…
dr_df0 authored
81 $_ = 10;
82 $i += $_ for 1..3;
83 is $_, 10, 'outer $_ did not get updated in lhs of for';
84 is $i, 1+2+3, 'postfix for worked';
85 }
8d8532c [t/spec] Test for RT #61494
kyle authored
86
832f178 [t/spec] fix more smartlinks; down to 33 broken links
moritz authored
87 # L<S04/The C<for> statement/When used as statement modifiers on implicit blocks>
2fd698f [t/spec] test that "for" statement modifier temporizes $_ on the thunk
moritz authored
88
89 {
90 $_ = 42;
91 my @trace;
92 @trace.push: $_ for 2, 3;
93 is @trace.join(':'), '2:3', 'statement modifier "for" sets $_ correctl';
94 is $_, 42, '"for" statement modifier restored $_ of outer block';
95 }
96
09b508b [t/spec] Test for RT 66622: statement mod "for" makes no implicit block
kyle authored
97 # RT 66622
98 {
99 my $rt66622 = 66622 for 1, 2, 3;
100 is $rt66622, 66622, 'statement modifier "for" makes no implicit block';
101 }
102
0cbc065 @lizmat s/eval_dies_ok/eval-dies-ok/g
lizmat authored
103 eval-dies-ok '1 for <a b> for <c d>;', 'double statement-modifying for is not allowed';
72d94a4 [t/spec] test for RT #64820, double statement modifying "for" is disa…
moritz authored
104
bb87d97 @tadzik Tests for RT #66606
tadzik authored
105 # RT #66606
106 {
107 my $x = 1 for ^3;
108 is $x, 1;
109 (my @a).push: $_ for ^3;
110 is @a.join(','), '0,1,2';
111 }
112
06a737b @peschwa Added tests for RT #89208
peschwa authored
113 # RT #89208
114 is ((sub r { "OH HAI" })() for 5), "OH HAI", 'Anon sub in statement modifier for works.';
115
82d502c @usev6 Add test for RT #118769
usev6 authored
116 # RT #118769
117 {
118 my @x = <x x x>;
119 $_ = 'foo' for @x;
120 is @x, <foo foo foo>, 'can assign to $_ in a statement_mod "for" loop (1)';
121
122 my @y = <& a& &b>;
123 s:g/\&/\\\&/ for @y;
124 is @y, ('\&', 'a\&', '\&b'), 'can assign to $_ in a statement_mod "for" loop (2)';
125 }
126
eee416a @TimToady fudge "{$_}" for ...
TimToady authored
127 # RT #100746
cd74a7c @TimToady ensure that "{$_}" for ... sets correct $_
TimToady authored
128 {
129 $_ = 'bogus';
130 my @r = gather { take "{$_}" for <cool but dry> }
131 is @r[0], 'cool', 'for modifies the $_ that is visible to the {} interpolator';
132 }
133
8c29100 @jnthn Tests for RT #111704.
jnthn authored
134 # RT #111704
135 {
136 my $a = '';
137 try { $a ~= $_ } for <1 2>;
138 is $a, '12', 'Correct $_ in try block in statement-modifying for';
139 }
140
f113f3f @jnthn Tests covering regression in given/for s.m.
jnthn authored
141 {
142 # Covers a bug where the block to first got compiled in the 'for' thunk
143 my @a;
144 for ^2 -> \c { 1 for first { @a.push(c); 0 }, ^2; };
145 is @a, (0, 0, 1, 1), 'for thunk does not mess up statement modifier closures';
146 }
147
fdaa7dc @usev6 Unfudge passing test for RT #116178, add 2nd test
usev6 authored
148 # RT #116178
149 {
150 my @a = <a b c>;
151 my %h;
152 %h{.value} //= .key for @a.pairs;
153 is %h, {:a(0), :b(1), :c(2)}, "default-assignment (//-) doesn't mix with implicit-variable method call";
154 }
155
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
156 # vim: ft=perl6
Something went wrong with that request. Please try again.