X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F23-localize-ctl.t;h=213df7f2fa99e2a67eb8a49da936658bbbfab5b6;hb=fc2f5019e1fd7bc4f38054fc605fdf77ba5bdc65;hp=1a0c2a2e5688ba33d347cc2df85868b517cb871f;hpb=bac4fc46c2d48ce5db75de6c88e0983aeeedf865;p=perl%2Fmodules%2FScope-Upper.git diff --git a/t/23-localize-ctl.t b/t/23-localize-ctl.t index 1a0c2a2..213df7f 100644 --- a/t/23-localize-ctl.t +++ b/t/23-localize-ctl.t @@ -3,18 +3,86 @@ use strict; use warnings; -use Test::More tests => 28; +use Test::More tests => 44; -use Scope::Upper qw/localize/; +use Scope::Upper qw/localize UP HERE/; our ($x, $y); +{ + local $x = 1; + { + local $x = 2; + localize '$y' => 1 => HERE; + 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 => UP; + 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 => HERE; + 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 => UP; + 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; { local $x = 2; { - localize '$y' => 1 => 2; + localize '$y' => 1 => UP UP; } is $x, 2, 'goto 1 [not yet - x]'; is $y, undef, 'goto 1 [not yet - y]'; @@ -37,7 +105,7 @@ $y = undef; { local $x = 3; { - localize '$y' => 1 => 3; + localize '$y' => 1 => UP UP UP; } is $x, 3, 'goto 2 [not yet - x]'; is $y, undef, 'goto 2 [not yet - y]'; @@ -62,7 +130,7 @@ $y = undef; { { local $x = 3; - localize '$y' => 1 => 4; + localize '$y' => 1 => UP UP UP UP; is $x, 3, 'die - reap outside eval [not yet 1 - x]'; is $y, undef, 'die - reap outside eval [not yet 1 - y]'; } @@ -86,7 +154,7 @@ $y = undef; { { local $x = 3; - localize '$y' => 1 => 3; + localize '$y' => 1 => UP UP UP; is $x, 3, 'die - reap at eval [not yet 1 - x]'; is $y, undef, 'die - reap at eval [not yet 1 - y]'; } @@ -107,7 +175,7 @@ $y = undef; { { local $x = 3; - localize '$y' => 1 => 2; + localize '$y' => 1 => UP UP; is $x, 3, 'die - reap inside eval [not yet 1 - x]'; is $y, undef, 'die - reap inside eval [not yet 1 - y]'; }