X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F40-localize_delete-target.t;h=c5abf9d8bbf7afcf39774c5afb4888adac229fac;hb=add935e784ba40a5c477b8b8c93fb4a2159b53a1;hp=24597b7d036968030caeff7337cf707db0df637c;hpb=0a6221d3f467b5f819e3c119b4cda0218399cb51;p=perl%2Fmodules%2FScope-Upper.git diff --git a/t/40-localize_delete-target.t b/t/40-localize_delete-target.t index 24597b7..c5abf9d 100644 --- a/t/40-localize_delete-target.t +++ b/t/40-localize_delete-target.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 36; +use Test::More tests => 44 + 4; use Scope::Upper qw/localize_delete UP HERE/; @@ -107,6 +107,16 @@ our @a; is_deeply \@a, [ 4 .. 6 ], 'localize_delete "@a", 4 (exists) => UP [end]'; } +{ + { + localize_delete '@nonexistent', 2; + is_deeply eval('*nonexistent{ARRAY}'), [ ], + 'localize_delete "@nonexistent", anything => HERE [ok]'; + } + is_deeply eval('*nonexistent{ARRAY}'), [ ], + 'localize_delete "@nonexistent", anything => HERE [end]'; +} + # Hashes our %h; @@ -142,26 +152,80 @@ our %h; is_deeply \%h, { a => 1, b => 2 }, 'localize_delete "%h", "a" => UP [end]'; } +{ + { + localize_delete '%nonexistent', 'a'; + is_deeply eval('*nonexistent{HASH}'), { }, + 'localize_delete "%nonexistent", anything => HERE [ok]'; + } + is_deeply eval('*nonexistent{HASH}'), { }, + 'localize_delete "%nonexistent", anything => HERE [end]'; +} + # Others our $x = 1; { localize_delete '$x', 2 => HERE; - is $x, undef, 'localize "$x", anything => HERE [ok]'; + is $x, undef, 'localize_delete "$x", anything => HERE [ok]'; +} +is $x, 1, 'localize_delete "$x", anything => HERE [end]'; + +{ + { + localize_delete '$nonexistent', 2; + is eval('${*nonexistent{SCALAR}}'), undef, + 'localize_delete "$nonexistent", anything => HERE [ok]'; + } + is eval('${*nonexistent{SCALAR}}'), undef, + 'localize_delete "$nonexistent", anything => HERE [end]'; } -is $x, 1, 'localize "$x", anything => HERE [end]'; sub x { 1 }; { localize_delete '&x', 2 => HERE; - ok !exists(&x), 'localize "&x", anything => HERE [ok]'; + ok !exists(&x), 'localize_delete "&x", anything => HERE [ok]'; +} +is x(), 1, 'localize_delete "&x", anything => HERE [end]'; + +{ + { + localize_delete '&nonexistent', 2; + is eval('exists &nonexistent'), !1, + 'localize_delete "&nonexistent", anything => HERE [ok]'; + } + is eval('exists &nonexistent'), !1, + 'localize_delete "&nonexistent", anything => HERE [end]'; } -is x(), 1, 'localize "&x", anything => HERE [end]'; { localize_delete *x, sub { } => HERE; - is !exists(&x), 1, 'localize *x, anything => HERE [ok 1]'; - is !defined($x), 1, 'localize *x, anything => HERE [ok 2]'; + is !exists(&x), 1, 'localize_delete *x, anything => HERE [ok 1]'; + is !defined($x), 1, 'localize_delete *x, anything => HERE [ok 2]'; +} +is x(), 1, 'localize_delete *x, anything => HERE [end 1]'; +is $x, 1, 'localize_delete *x, anything => HERE [end 2]'; + +# Invalid + +sub invalid_ref { qr/^Invalid \Q$_[0]\E reference as the localization target/ } + +{ + eval { localize_delete \1, 0 => HERE }; + like $@, invalid_ref('SCALAR'), 'invalid localize_delete \1, 0 => HERE'; +} + +{ + eval { localize_delete [ ], 0 => HERE }; + like $@, invalid_ref('ARRAY'), 'invalid localize_delete [ ], 0 => HERE'; +} + +{ + eval { localize_delete { }, 0 => HERE }; + like $@, invalid_ref('HASH'), 'invalid localize_delete { }, 0 => HERE'; +} + +{ + eval { localize_delete sub { }, 0 => HERE }; + like $@, invalid_ref('CODE'), 'invalid localize_delete sub { }, 0 => HERE'; } -is x(), 1, 'localize *x, anything => HERE [end 1]'; -is $x, 1, 'localize *x, anything => HERE [end 2]';