From: Hugo van der Sanden Date: Tue, 25 Feb 2003 15:24:17 +0000 (+0000) Subject: Add missing file from change #18774. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=22efcfd695558c79203ea419fa22b3dfdc2549ee;p=p5sagit%2Fp5-mst-13.2.git Add missing file from change #18774. p4raw-link: @18774 on //depot/perl: 82d039840b913b4eed10833ac05709a5abd02ead p4raw-id: //depot/perl@18778 --- diff --git a/t/op/localref.t b/t/op/localref.t new file mode 100644 index 0000000..9379575 --- /dev/null +++ b/t/op/localref.t @@ -0,0 +1,85 @@ +#!./perl + +chdir 't' if -d 't'; +@INC = qw(. ../lib); +require "test.pl"; +plan( tests => 63 ); + +$aa = 1; +{ local $aa; $aa = 2; is($aa,2); } +is($aa,1); +{ local ${aa}; $aa = 3; is($aa,3); } +is($aa,1); +{ local ${"aa"}; $aa = 4; is($aa,4); } +is($aa,1); +$x = "aa"; +{ local ${$x}; $aa = 5; is($aa,5); undef $x; is($aa,5); } +is($aa,1); +$x = "a"; +{ local ${$x x2};$aa = 6; is($aa,6); undef $x; is($aa,6); } +is($aa,1); +$x = "aa"; +{ local $$x; $aa = 7; is($aa,7); undef $x; is($aa,7); } +is($aa,1); + +@aa = qw/a b/; +{ local @aa; @aa = qw/c d/; is("@aa","c d"); } +is("@aa","a b"); +{ local @{aa}; @aa = qw/e f/; is("@aa","e f"); } +is("@aa","a b"); +{ local @{"aa"}; @aa = qw/g h/; is("@aa","g h"); } +is("@aa","a b"); +$x = "aa"; +{ local @{$x}; @aa = qw/i j/; is("@aa","i j"); undef $x; is("@aa","i j"); } +is("@aa","a b"); +$x = "a"; +{ local @{$x x2};@aa = qw/k l/; is("@aa","k l"); undef $x; is("@aa","k l"); } +is("@aa","a b"); +$x = "aa"; +{ local @$x; @aa = qw/m n/; is("@aa","m n"); undef $x; is("@aa","m n"); } +is("@aa","a b"); + +%aa = qw/a b/; +{ local %aa; %aa = qw/c d/; is($aa{c},"d"); } +is($aa{a},"b"); +{ local %{aa}; %aa = qw/e f/; is($aa{e},"f"); } +is($aa{a},"b"); +{ local %{"aa"}; %aa = qw/g h/; is($aa{g},"h"); } +is($aa{a},"b"); +$x = "aa"; +{ local %{$x}; %aa = qw/i j/; is($aa{i},"j"); undef $x; is($aa{i},"j"); } +is($aa{a},"b"); +$x = "a"; +{ local %{$x x2};%aa = qw/k l/; is($aa{k},"l"); undef $x; is($aa{k},"l"); } +is($aa{a},"b"); +$x = "aa"; +{ local %$x; %aa = qw/m n/; is($aa{m},"n"); undef $x; is($aa{m},"n"); } +is($aa{a},"b"); + +sub test_err_localref () { + like($@,qr/Can't localize through a reference/,'error'); +} +$x = \$aa; +my $y = \$aa; +eval { local $$x; }; test_err_localref; +eval { local ${$x}; }; test_err_localref; +eval { local $$y; }; test_err_localref; +eval { local ${$y}; }; test_err_localref; +eval { local ${\$aa}; }; test_err_localref; +eval { local ${\'aa'}; }; test_err_localref; +$x = \@aa; +$y = \@aa; +eval { local @$x; }; test_err_localref; +eval { local @{$x}; }; test_err_localref; +eval { local @$y; }; test_err_localref; +eval { local @{$y}; }; test_err_localref; +eval { local @{\@aa}; }; test_err_localref; +eval { local @{[]}; }; test_err_localref; +$x = \%aa; +$y = \%aa; +eval { local %$x; }; test_err_localref; +eval { local %{$x}; }; test_err_localref; +eval { local %$y; }; test_err_localref; +eval { local %{$y}; }; test_err_localref; +eval { local %{\%aa}; }; test_err_localref; +eval { local %{{a=>1}}; };test_err_localref;