X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Flocal.t;h=8bfea00b9a4006b5b7fe19f5d58dd0d63b5fe82b;hb=21fa6956243df9cb622bebfa0934ea7923519b4f;hp=bc24657a54f034e8dd9c242fd1e943afb01fc3ee;hpb=7d654f43b92f51303a8d5388d3c3bfb7ebbceb22;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/local.t b/t/op/local.t index bc24657..8bfea00 100755 --- a/t/op/local.t +++ b/t/op/local.t @@ -2,9 +2,10 @@ BEGIN { chdir 't' if -d 't'; + @INC = qw(. ../lib); require './test.pl'; } -plan tests => 104; +plan tests => 122; my $list_assignment_supported = 1; @@ -392,3 +393,72 @@ sub f { ok(0 == $[); } is($h{"\243"}, "pound"); is($h{"\302\240"}, "octects"); } + +# And with slices +{ + my %h; + $h{"\243"} = "pound"; + $h{"\302\240"} = "octects"; + is(scalar keys %h, 2); + { + my $unicode = chr 256; + my $ambigous = "\240" . $unicode; + chop $ambigous; + local @h{$unicode, $ambigous} = (256, 160); + + is(scalar keys %h, 4); + is($h{"\243"}, "pound"); + is($h{$unicode}, 256); + is($h{$ambigous}, 160); + is($h{"\302\240"}, "octects"); + } + is(scalar keys %h, 2); + is($h{"\243"}, "pound"); + is($h{"\302\240"}, "octects"); +} + +# [perl #39012] localizing @_ element then shifting frees element too # soon + +{ + my $x; + my $y = bless [], 'X39012'; + sub X39012::DESTROY { $x++ } + sub { local $_[0]; shift }->($y); + ok(!$x, '[perl #39012]'); + +} + +# when localising a hash element, the key should be copied, not referenced + +{ + my %h=('k1' => 111); + my $k='k1'; + { + local $h{$k}=222; + + is($h{'k1'},222); + $k='k2'; + } + ok(! exists($h{'k2'})); + is($h{'k1'},111); +} +{ + my %h=('k1' => 111); + our $k = 'k1'; # try dynamic too + { + local $h{$k}=222; + is($h{'k1'},222); + $k='k2'; + } + ok(! exists($h{'k2'})); + is($h{'k1'},111); +} + +# Keep this test last, as it can SEGV +{ + local *@; + pass("Localised *@"); + eval {1}; + pass("Can eval with *@ localised"); +} +