6 use Test::More tests => 44 + 30;
8 use Scope::Upper qw<localize UP HERE>;
16 localize '$y' => 1 => HERE;
17 is $x, 2, 'last 0 [ok - x]';
18 is $y, 1, 'last 0 [ok - y]';
22 is $x, 1, 'last 0 [end - x]';
23 is $y, undef, 'last 0 [end - y]';
34 localize '$y' => 1 => UP;
35 is $x, 3, 'last 1 [ok - x]';
36 is $y, 0, 'last 1 [ok - y]';
42 is $x, 1, 'last 1 [end - x]';
43 is $y, undef, 'last 1 [end - y]';
50 localize '$y' => 1 => HERE;
51 is $x, 2, 'next 0 [ok - x]';
52 is $y, 1, 'next 0 [ok - y]';
56 is $x, 1, 'next 0 [end - x]';
57 is $y, undef, 'next 0 [end - y]';
68 localize '$y' => 1 => UP;
69 is $x, 3, 'next 1 [ok - x]';
70 is $y, 0, 'next 1 [ok - y]';
76 is $x, 1, 'next 1 [end - x]';
77 is $y, undef, 'next 1 [end - y]';
85 localize '$y' => 1 => UP UP;
87 is $x, 2, 'goto 1 [not yet - x]';
88 is $y, undef, 'goto 1 [not yet - y]';
96 is $x, 1, 'goto 1 [ok - x]';
97 is $y, 1, 'goto 1 [ok - y]';
108 localize '$y' => 1 => UP UP UP;
110 is $x, 3, 'goto 2 [not yet - x]';
111 is $y, undef, 'goto 2 [not yet - y]';
120 is $x, 1, 'goto 2 [ok - x]';
121 is $y, 1, 'goto 2 [ok - y]';
133 localize '$y' => 1 => UP UP UP UP;
134 is $x, 3, 'die - localize outside eval [not yet 1 - x]';
135 is $y, undef, 'die - localize outside eval [not yet 1 - y]';
137 is $x, 2, 'die - localize outside eval [not yet 2 - x]';
138 is $y, undef, 'die - localize outside eval [not yet 2 - y]';
142 is $x, 1, 'die - localize outside eval [not yet 3 - x]';
143 is $y, undef, 'die - localize outside eval [not yet 3 - y]';
144 } # should trigger here
145 is $x, 1, 'die - localize outside eval [ok - x]';
146 is $y, 1, 'die - localize outside eval [ok - y]';
157 localize '$y' => 1 => UP UP UP;
158 is $x, 3, 'die - localize at eval [not yet 1 - x]';
159 is $y, undef, 'die - localize at eval [not yet 1 - y]';
161 is $x, 2, 'die - localize at eval [not yet 2 - x]';
162 is $y, undef, 'die - localize at eval [not yet 2 - y]';
165 }; # should trigger here
166 is $x, 1, 'die - localize at eval [ok - x]';
167 is $y, 1, 'die - localize at eval [ok - y]';
178 localize '$y' => 1 => UP UP;
179 is $x, 3, 'die - localize inside eval [not yet 1 - x]';
180 is $y, undef, 'die - localize inside eval [not yet 1 - y]';
182 is $x, 2, 'die - localize inside eval [not yet 2 - x]';
183 is $y, undef, 'die - localize inside eval [not yet 2 - y]';
185 } # should trigger here
187 is $x, 1, 'die - localize inside eval [ok - x]';
188 is $y, undef, 'die - localize inside eval [ok - y]';
193 skip 'Perl 5.10 required to test given/when' => 30 if "$]" < 5.010;
195 eval <<' GIVEN_TEST_1';
196 use feature 'switch';
204 localize '$y' => 1 => UP UP;
205 is $x, 3, 'given/when - localize at given [not yet - x]';
206 is $y, undef, 'given/when - localize at given [not yet - y]';
210 is $x, 1, 'given/when - localize at given [ok - x]';
211 is $y, 1, 'given/when - localize at given [ok - y]';
216 eval <<' GIVEN_TEST_2';
217 use feature 'switch';
225 localize '$y' => 1 => UP UP;
226 is $x, 3, 'given/when/continue - localize at given [not yet 1 - x]';
227 is $y, undef, 'given/when/continue - localize at given [not yet 1 - y]';
230 is $x, 2, 'given/when/continue - localize at given [not yet 2 - x]';
231 is $y, undef, 'given/when/continue - localize at given [not yet 2 - y]';
233 is $x, 1, 'given/when/continue - localize at given [ok - x]';
234 is $y, 1, 'given/when/continue - localize at given [ok - y]';
239 eval <<' GIVEN_TEST_3';
240 use feature 'switch';
248 localize '$y' => 1 => UP UP;
249 is $x, 3, 'given/default - localize at given [not yet - x]';
250 is $y, undef, 'given/default - localize at given [not yet - y]';
254 is $x, 1, 'given/default - localize at given [ok - x]';
255 is $y, 1, 'given/default - localize at given [ok - y]';
260 eval <<' GIVEN_TEST_4';
261 use feature 'switch';
269 localize '$y' => 1 => UP UP;
270 is $x, 3, 'given/default/continue - localize at given [not yet 1 - x]';
271 is $y, undef, 'given/default/continue - localize at given [not yet 1 - y]';
274 is $x, 2, 'given/default/continue - localize at given [not yet 2 - x]';
275 is $y, undef, 'given/default/continue - localize at given [not yet 2 - y]';
277 is $x, 1, 'given/default/continue - localize at given [ok - x]';
278 is $y, 1, 'given/default/continue - localize at given [ok - y]';
283 eval <<' GIVEN_TEST_5';
284 use feature 'switch';
296 localize '$y' => 1 => UP UP UP;
297 is $x, 5, 'given/default/given/when - localize at default [not yet 1 - x]';
298 is $y, undef, 'given/default/given/when - localize at default [not yet 1 - y]';
301 is $x, 4, 'given/default/given/when - localize at default [not yet 2 - x]';
302 is $y, undef, 'given/default/given/when - localize at default [not yet 2 - y]';
304 is $x, 3, 'given/default/given/when - localize at default [not yet 3 - x]';
305 is $y, undef, 'given/default/given/when - localize at default [not yet 3 - y]';
308 is $x, 2, 'given/default/given/when - localize at default [ok 1 - x]';
309 is $y, 1, 'given/default/given/when - localize at default [ok 1 - y]';
311 is $x, 1, 'given/default/given/when - localize at default [ok 2 - x]';
312 is $y, undef, 'given/default/given/when - localize at default [ok 2 - y]';