Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 208 lines (151 sloc) 3.884 kB
1f5765a [gsoc_spectest] moved leave.t into spec, changed $?BLOCK to &?BLOCK, …
Auzon authored
1 use v6;
2
3 use Test;
4
5 # Basic &leave tests
6 # L<S06/"The C<leave> function">
7
8 plan 23;
9
10 {
11 my $bare = { leave 42; 23 };
12
13 is $bare(), 42, 'basic leave() works';
14 }
15
7922e91 @KrisShannon Revert my last commit.
KrisShannon authored
16 #?pugs emit flunk '&?BLOCK.leave() not implemented in Pugs's interpreter core yet', :todo<feature>;
17 #?pugs emit skip_rest; exit;
1f5765a [gsoc_spectest] moved leave.t into spec, changed $?BLOCK to &?BLOCK, …
Auzon authored
18
19 {
20 my $bare = { &?BLOCK.leave(42); 23 };
21
22 is $bare(), 42, 'basic leave() is equivalent to &?BLOCK.leave()';
23 }
24
25 {
26 my $bare = { &?BLOCK.leave: 42; 23 };
27
28 is $bare(), 42, 'basic method leave works as colon listop';
29 }
30
31 {
32 my $bare = { leave &?BLOCK: 42; 23 };
33
34 is $bare(), 42, 'basic method leave works with indirect object';
35 }
36
37 {
38 my @bare = [41, do { leave; 23 }, 43 ];
39
40 is @bare, [41,43], 'basic leave returns null list in list context';
41 }
42
43 {
44 my @bare = [41, do { 21 + leave() + 23 }, 43 ];
45
46 is @bare, [41,43], 'basic leave() returns null list in list context';
47 }
48
49 {
50 my @bare = [41, do { &?BLOCK.leave; 23 }, 43 ];
51
52 is @bare, [41,43], 'basic &?BLOCK.leave returns null list in list context';
53 }
54
55 {
56 my @bare = [41, do { 21 + &?BLOCK.leave() + 23 }, 43 ];
57
58 is @bare, [41,43], 'basic &?BLOCK.leave() returns null list in list context';
59 }
60
61 {
62 my @bare = [41, do { leave &?BLOCK: ; 23 }, 43 ];
63
64 is @bare, [41,43], 'basic leave &?BLOCK: returns null list in list context';
65 }
66
67 {
68 my @bare = [41, do { 21 + (leave &?BLOCK:) + 23 }, 43 ];
69
70 is @bare, [41,43], 'basic leave &?BLOCK: returns null list in list context';
71 }
72
73 {
74 my @bare = [41, do { leave 42, 43; 23 }, 44 ];
75
76 is @bare, [41,42,43,44], 'basic leave returns valid list in list context';
77 }
78
79 {
80 my @bare = [41, do { 21 + leave(42, 43) + 23 }, 44 ];
81
82 is @bare, [41,42,43,44], 'basic leave() returns valid list in list context';
83 }
84
85 {
86 my @bare = [41, do { 21 + &?BLOCK.leave(42,43) + 23 }, 44 ];
87
88 is @bare, [41,42,43,44], 'basic &?BLOCK.leave() returns valid list in list context';
89 }
90
91 {
92 my @bare = [41, do { leave &?BLOCK: 42, 43; 23 }, 44 ];
93
94 is @bare, [41,42,43,44], 'basic leave &?BLOCK: returns valid list in list context';
95 }
96
97 {
98 my @bare = [41, do { 21 + (leave &?BLOCK: 42, 43) + 23 }, 44 ];
99
100 is @bare, [41,42,43,44], 'basic leave &?BLOCK: returns valid list in list context';
101 }
102
103 {
104 my $sub = sub () {
105 my $bare = { leave 42; 23 };
106
107 my $ret = $bare();
108 return 1000 + $ret;
109 };
110
111 is $sub(), 1042, 'leave() works and leaves only the innermost block';
112 }
113
114 {
115 my $sub = sub () {
116 &?ROUTINE.leave(42);
117 return 23;
118 };
119
120 is $sub(), 42, 'leave() works with &?ROUTINE as invocant';
121 }
122
123 {
124 my $outer = sub () {
125 my $inner = sub () {
126 my $most_inner = sub () {
127 leave $outer: 42;
128 return 23;
129 };
130
131 $most_inner();
132 return 22;
133 };
134
135 $inner();
136 return 21;
137 }
138
139 is $outer(), 42, 'nested leave() works with a subref as invocant';
140 }
141
142 {
143 my $sub = sub () {
144 my $bare = sub () {
145 Block.leave: 42;
146 return 23;
147 };
148
149 my $ret = $bare();
150 return 1000 + $ret;
151 };
152
153 is $sub(), 1042, 'leave() works with a Class (Block) as invocant';
154 }
155
156 {
157 my $sub = sub () {
158 my $bare = sub () {
159 leave Sub: 42;
160 return 23;
161 };
162
163 my $ret = $bare();
164 return 1000 + $ret;
165 };
166
167 is $sub(), 42, 'leave() works with a Class (Sub) as invocant';
168 }
169
170 {
171 my $sub = sub () {
172 LABEL: for 1..10 -> $n {
173 for 'a' .. 'b' -> $a {
174 LABEL.leave(42);
175 "$a,$n";
176 }
177 }
178 }
179
180 is $sub(), 42, 'leave() works with a loop label';
181 }
182
183 eval q[[
184 my $sub = sub () {
185 eager do # XXX without eager would require time travel
186 LABEL: for 1..10 -> $n {
187 for 'a' .. 'b' -> $a {
188 LABEL.leave(42,43); # note, must cancel ordinary list comprehension!
189 "$a,$n";
190 }
191 }
192 }
193
194 is [$sub()], [42,43], 'leave() works with a loop label in list context';
195 ]];
196
197 eval q[[
198 my $sub = sub () {
199 do LABEL: {
200 LABEL.leave(42);
201 } + 1000;
202 }
203
204 is $sub(), 1042, 'leave() works with an internal do label';
205 ]];
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
206
207 # vim: ft=perl6
Something went wrong with that request. Please try again.