Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 144 lines (117 sloc) 3.31 kb
499fea9 [gsoc_spectest] moved do.t into spec, added tests, fudged for rakudo. (a...
Auzon authored
1 use v6;
2
3 use Test;
4
5 plan 23;
6
7 # L<S04/The do-once loop/"can't" put "statement modifier">
963df52 [spec]: Fix todo of do+modifier tests.
pmichaud authored
8 #?rakudo 6 todo 'do {} while/until/if is valid but should not be'
499fea9 [gsoc_spectest] moved do.t into spec, added tests, fudged for rakudo. (a...
Auzon authored
9 eval_dies_ok 'my $i = 1; do { $i++ } while $i < 5;',
10 "'do' can't take the 'while' modifier";
11
12 eval_dies_ok 'my $i = 1; do { $i++ } until $i > 4;',
13 "'do' can't take the 'until' modifier";
14
15 eval_dies_ok 'my $i = 1; do { $i++ } if $i;',
16 "'do' can't take the 'if' modifier";
17
18 eval_dies_ok 'my $i; do { $i++ } for 1..3;',
19 "'do' can't take the 'for' modifier";
20
21 eval_dies_ok 'my $i; do { $i++ } unless $i;',
22 "'do' can't take the 'unless' modifier";
23
24 eval_dies_ok 'my $i; do { $i++ } given $i;',
25 "'do' can't take the 'given' modifier";
26
27 # L<S04/The do-once loop/statement "prefixing with" do>
28 {
29 my $x;
30 my ($a, $b, $c) = 'a' .. 'c';
31
32 $x = do if $a { $b } else { $c };
33 is $x, 'b', "prefixing 'if' statement with 'do' (then)";
34
35 $x = do if !$a { $b } else { $c };
36 is $x, 'c', "prefixing 'if' statement with 'do' (else)";
4d3ec37 [t/spec]: Unfudge a spectest in do.t.
pmichaud authored
37 }
499fea9 [gsoc_spectest] moved do.t into spec, added tests, fudged for rakudo. (a...
Auzon authored
38
39 =begin comment
40 If the final statement is a conditional which does not execute
41 any branch, the return value is undef in item context and ()
42 in list context.
43 =end comment
4d3ec37 [t/spec]: Unfudge a spectest in do.t.
pmichaud authored
44 #?rakudo skip 'if returning undef'
45 {
499fea9 [gsoc_spectest] moved do.t into spec, added tests, fudged for rakudo. (a...
Auzon authored
46 $x = do if 0 { 1 } elsif 0 { 2 };
4d3ec37 [t/spec]: Unfudge a spectest in do.t.
pmichaud authored
47 ok !$x.defined, 'when if does not execute any branch, return undef';
499fea9 [gsoc_spectest] moved do.t into spec, added tests, fudged for rakudo. (a...
Auzon authored
48 }
49
50 {
51 my $ret = do given 3 {
52 when 3 { 1 }
53 };
54 is($ret, 1, 'do STMT works');
55 }
56
57 {
58 my $ret = do { given 3 {
59 when 3 { 1 }
60 } };
61 is($ret, 1, 'do { STMT } works');
62 }
63
64 # L<S04/The do-once loop/"you may use" do "on an expression">
65 {
66 my $ret = do 42;
67 is($ret, 42, 'do EXPR should also work (single number)');
68
69 $ret = do 3 + 2;
70 is($ret, 5, 'do EXPR should also work (simple + expr)');
71
72 $ret = do do 5;
73 is($ret, 5, 'nested do (1)');
74
75 $ret = do {do 5};
76 is($ret, 5, 'nested do (2)');
77
78 # precedence decisions do not cross a do boundary
79 $ret = 2 * do 2 + 5;
2e3530b [t/spec] Typo - s/ precendence / precedence /
Util authored
80 is($ret, 14, 'do affects precedence correctly');
499fea9 [gsoc_spectest] moved do.t into spec, added tests, fudged for rakudo. (a...
Auzon authored
81 }
82
83 # L<S04/The do-once loop/"can take" "loop control statements">
207f13f [t] and [t/spec]
moritz authored
84 #?rakudo todo 'next() should also work on do blocks (?)'
499fea9 [gsoc_spectest] moved do.t into spec, added tests, fudged for rakudo. (a...
Auzon authored
85 {
86 my $i;
87 do {
88 $i++;
89 next;
90 $i--;
91 };
92 is $i, 1, "'next' works in 'do' block";
93 }
94
95 #?rakudo skip 'last not implemented'
96 {
97 is eval('
98 my $i;
99 do {
100 $i++;
101 last;
102 $i--;
103 };
104 $i;
105 '), 1, "'last' works in 'do' block";
106 }
107
108 # IRC notes:
109 # <agentzh> audreyt: btw, can i use redo in the do-once loop?
110 # <audreyt> it can, and it will redo it
111 #?rakudo skip 'redo not implemented'
112 {
113 is eval('
114 my $i;
115 do {
116 $i++;
117 redo if $i < 3;
118 $i--;
119 };
120 $i;
121 '), 2, "'redo' works in 'do' block";
122 }
123
3152b01 [t] some updates to README, and fixed all but one smartlink in t/spec/
moritz authored
124 # L<S04/The do-once loop/"bare block is not a do-once">
499fea9 [gsoc_spectest] moved do.t into spec, added tests, fudged for rakudo. (a...
Auzon authored
125 {
126 eval_dies_ok 'my $i; { $i++; next; $i--; }',
127 "bare block can't take 'next'";
128
129 eval_dies_ok 'my $i; { $i++; last; $i--; }',
130 "bare block can't take 'last'";
131
132 eval_dies_ok 'my $i; { $i++; redo; $i--; }',
133 "bare block can't take 'last'";
134 }
135
136 # L<S04/Statement parsing/"final closing curly on a line"
137 # reverts to semicolon>
138 {
139 my $a = do {
140 1 + 2;
141 } # no trailing `;'
142 is $a, 3, "final `}' on a line reverted to `;'";
143 }
Something went wrong with that request. Please try again.