X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F40-localize_delete-target.t;h=26a81952010a26c7a3e43b16c7329f0a56e949af;hb=e7846e7f6fded4c4a3139054c5206c1480711867;hp=c5abf9d8bbf7afcf39774c5afb4888adac229fac;hpb=59a1136cba8ac79b0428d55824873b55a9b700aa;p=perl%2Fmodules%2FScope-Upper.git diff --git a/t/40-localize_delete-target.t b/t/40-localize_delete-target.t index c5abf9d..26a8195 100644 --- a/t/40-localize_delete-target.t +++ b/t/40-localize_delete-target.t @@ -3,9 +3,9 @@ use strict; use warnings; -use Test::More tests => 44 + 4; +use Test::More tests => 53 + 4; -use Scope::Upper qw/localize_delete UP HERE/; +use Scope::Upper qw; # Arrays @@ -162,7 +162,7 @@ our %h; 'localize_delete "%nonexistent", anything => HERE [end]'; } -# Others +# Scalars our $x = 1; { @@ -181,6 +181,8 @@ is $x, 1, 'localize_delete "$x", anything => HERE [end]'; 'localize_delete "$nonexistent", anything => HERE [end]'; } +# Code + sub x { 1 }; { localize_delete '&x', 2 => HERE; @@ -206,6 +208,50 @@ is x(), 1, 'localize_delete "&x", anything => HERE [end]'; is x(), 1, 'localize_delete *x, anything => HERE [end 1]'; is $x, 1, 'localize_delete *x, anything => HERE [end 2]'; +sub X::foo { 'X::foo' } + +{ + { + { + localize_delete '&X::foo', undef => UP; + is(X->foo(), 'X::foo', 'localize_delete "&X::foo", undef => UP [not yet X]'); + } + ok(!X->can('foo'), 'localize_delete "&X::foo", undef => UP [ok X]'); + } + is(X->foo(), 'X::foo', 'localize_delete "&X::foo", undef => UP [end X]'); +} + +@Y::ISA = 'X'; + +{ + { + { + localize_delete '&X::foo', undef => UP; + is(Y->foo(), 'X::foo', 'localize_delete "&X::foo", undef => UP [not yet Y]'); + } + ok(!Y->can('foo'), 'localize_delete "&X::foo", undef => UP [ok Y]'); + } + is(Y->foo(), 'X::foo', 'localize_delete "&X::foo", undef => UP [end Y]'); +} + + +{ + local *Y::foo = sub { 'Y::foo' }; + { + { + localize_delete '&Y::foo', undef => UP; + is(Y->foo(), 'Y::foo', 'localize_delete "&Y::foo", undef => UP [not yet]'); + } + is(Y->foo(), 'X::foo', 'localize_delete "&Y::foo", undef => UP [ok]'); + } + is(Y->foo(), 'Y::foo', 'localize_delete "&Y::foo", undef => UP [end]'); +} + +{ + # Prevent 'only once' warnings + local *Y::foo = *Y::foo; +} + # Invalid sub invalid_ref { qr/^Invalid \Q$_[0]\E reference as the localization target/ }