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;
194 skip 'Not testing deprecated given/when on Perl 5.37.10 or later'
195 => 30 if "$]" >= 5.037010;
197 eval <<' GIVEN_TEST_1';
199 if ("$]" >= 5.017_011) {
201 warnings->unimport('experimental::smartmatch');
204 use feature 'switch';
212 localize '$y' => 1 => UP UP;
213 is $x, 3, 'given/when - localize at given [not yet - x]';
214 is $y, undef, 'given/when - localize at given [not yet - y]';
218 is $x, 1, 'given/when - localize at given [ok - x]';
219 is $y, 1, 'given/when - localize at given [ok - y]';
224 eval <<' GIVEN_TEST_2';
226 if ("$]" >= 5.017_011) {
228 warnings->unimport('experimental::smartmatch');
231 use feature 'switch';
239 localize '$y' => 1 => UP UP;
240 is $x, 3, 'given/when/continue - localize at given [not yet 1 - x]';
241 is $y, undef, 'given/when/continue - localize at given [not yet 1 - y]';
244 is $x, 2, 'given/when/continue - localize at given [not yet 2 - x]';
245 is $y, undef, 'given/when/continue - localize at given [not yet 2 - y]';
247 is $x, 1, 'given/when/continue - localize at given [ok - x]';
248 is $y, 1, 'given/when/continue - localize at given [ok - y]';
253 eval <<' GIVEN_TEST_3';
255 if ("$]" >= 5.017_011) {
257 warnings->unimport('experimental::smartmatch');
260 use feature 'switch';
268 localize '$y' => 1 => UP UP;
269 is $x, 3, 'given/default - localize at given [not yet - x]';
270 is $y, undef, 'given/default - localize at given [not yet - y]';
274 is $x, 1, 'given/default - localize at given [ok - x]';
275 is $y, 1, 'given/default - localize at given [ok - y]';
280 eval <<' GIVEN_TEST_4';
282 if ("$]" >= 5.017_011) {
284 warnings->unimport('experimental::smartmatch');
287 use feature 'switch';
295 localize '$y' => 1 => UP UP;
296 is $x, 3, 'given/default/continue - localize at given [not yet 1 - x]';
297 is $y, undef, 'given/default/continue - localize at given [not yet 1 - y]';
300 is $x, 2, 'given/default/continue - localize at given [not yet 2 - x]';
301 is $y, undef, 'given/default/continue - localize at given [not yet 2 - y]';
303 is $x, 1, 'given/default/continue - localize at given [ok - x]';
304 is $y, 1, 'given/default/continue - localize at given [ok - y]';
309 eval <<' GIVEN_TEST_5';
311 if ("$]" >= 5.017_011) {
313 warnings->unimport('experimental::smartmatch');
316 use feature 'switch';
328 localize '$y' => 1 => UP UP UP;
329 is $x, 5, 'given/default/given/when - localize at default [not yet 1 - x]';
330 is $y, undef, 'given/default/given/when - localize at default [not yet 1 - y]';
333 is $x, 4, 'given/default/given/when - localize at default [not yet 2 - x]';
334 is $y, undef, 'given/default/given/when - localize at default [not yet 2 - y]';
336 is $x, 3, 'given/default/given/when - localize at default [not yet 3 - x]';
337 is $y, undef, 'given/default/given/when - localize at default [not yet 3 - y]';
340 is $x, 2, 'given/default/given/when - localize at default [ok 1 - x]';
341 is $y, 1, 'given/default/given/when - localize at default [ok 1 - y]';
343 is $x, 1, 'given/default/given/when - localize at default [ok 2 - x]';
344 is $y, undef, 'given/default/given/when - localize at default [ok 2 - y]';