From: Vincent Pit Date: Sat, 3 Jan 2009 16:33:44 +0000 (+0100) Subject: Test next and last X-Git-Tag: v0.03~4 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=c05ad1b89116d3c5312b904ba20cd53d473443fd;p=perl%2Fmodules%2FScope-Upper.git Test next and last --- diff --git a/t/23-localize-ctl.t b/t/23-localize-ctl.t index 1a0c2a2..c85c4a8 100644 --- a/t/23-localize-ctl.t +++ b/t/23-localize-ctl.t @@ -3,12 +3,80 @@ use strict; use warnings; -use Test::More tests => 28; +use Test::More tests => 44; use Scope::Upper qw/localize/; our ($x, $y); +{ + local $x = 1; + { + local $x = 2; + localize '$y' => 1 => 0; + is $x, 2, 'last 0 [ok - x]'; + is $y, 1, 'last 0 [ok - y]'; + last; + $y = 2; + } + is $x, 1, 'last 0 [end - x]'; + is $y, undef, 'last 0 [end - y]'; +} + +{ + local $x = 1; +LOOP: + { + local $x = 2; + local $y = 0; + { + local $x = 3; + localize '$y' => 1 => 1; + is $x, 3, 'last 1 [ok - x]'; + is $y, 0, 'last 1 [ok - y]'; + last LOOP; + $y = 3; + } + $y = 2; + } + is $x, 1, 'last 1 [end - x]'; + is $y, undef, 'last 1 [end - y]'; +} + +{ + local $x = 1; + { + local $x = 2; + localize '$y' => 1 => 0; + is $x, 2, 'next 0 [ok - x]'; + is $y, 1, 'next 0 [ok - y]'; + next; + $y = 2; + } + is $x, 1, 'next 0 [end - x]'; + is $y, undef, 'next 0 [end - y]'; +} + +{ + local $x = 1; +LOOP: + { + local $x = 2; + local $y = 0; + { + local $x = 3; + localize '$y' => 1 => 1; + is $x, 3, 'next 1 [ok - x]'; + is $y, 0, 'next 1 [ok - y]'; + next LOOP; + $y = 3; + } + $y = 2; + } + is $x, 1, 'next 1 [end - x]'; + is $y, undef, 'next 1 [end - y]'; +} + { local $x = 1; {