Suppress a few compilation warnings in pp_hot.c.
[p5sagit/p5-mst-13.2.git] / t / op / localref.t
CommitLineData
22efcfd6 1#!./perl
2
3chdir 't' if -d 't';
4@INC = qw(. ../lib);
5require "test.pl";
6plan( tests => 63 );
7
8$aa = 1;
9{ local $aa; $aa = 2; is($aa,2); }
10is($aa,1);
11{ local ${aa}; $aa = 3; is($aa,3); }
12is($aa,1);
13{ local ${"aa"}; $aa = 4; is($aa,4); }
14is($aa,1);
15$x = "aa";
16{ local ${$x}; $aa = 5; is($aa,5); undef $x; is($aa,5); }
17is($aa,1);
18$x = "a";
19{ local ${$x x2};$aa = 6; is($aa,6); undef $x; is($aa,6); }
20is($aa,1);
21$x = "aa";
22{ local $$x; $aa = 7; is($aa,7); undef $x; is($aa,7); }
23is($aa,1);
24
25@aa = qw/a b/;
26{ local @aa; @aa = qw/c d/; is("@aa","c d"); }
27is("@aa","a b");
28{ local @{aa}; @aa = qw/e f/; is("@aa","e f"); }
29is("@aa","a b");
30{ local @{"aa"}; @aa = qw/g h/; is("@aa","g h"); }
31is("@aa","a b");
32$x = "aa";
33{ local @{$x}; @aa = qw/i j/; is("@aa","i j"); undef $x; is("@aa","i j"); }
34is("@aa","a b");
35$x = "a";
36{ local @{$x x2};@aa = qw/k l/; is("@aa","k l"); undef $x; is("@aa","k l"); }
37is("@aa","a b");
38$x = "aa";
39{ local @$x; @aa = qw/m n/; is("@aa","m n"); undef $x; is("@aa","m n"); }
40is("@aa","a b");
41
42%aa = qw/a b/;
43{ local %aa; %aa = qw/c d/; is($aa{c},"d"); }
44is($aa{a},"b");
45{ local %{aa}; %aa = qw/e f/; is($aa{e},"f"); }
46is($aa{a},"b");
47{ local %{"aa"}; %aa = qw/g h/; is($aa{g},"h"); }
48is($aa{a},"b");
49$x = "aa";
50{ local %{$x}; %aa = qw/i j/; is($aa{i},"j"); undef $x; is($aa{i},"j"); }
51is($aa{a},"b");
52$x = "a";
53{ local %{$x x2};%aa = qw/k l/; is($aa{k},"l"); undef $x; is($aa{k},"l"); }
54is($aa{a},"b");
55$x = "aa";
56{ local %$x; %aa = qw/m n/; is($aa{m},"n"); undef $x; is($aa{m},"n"); }
57is($aa{a},"b");
58
59sub test_err_localref () {
60 like($@,qr/Can't localize through a reference/,'error');
61}
62$x = \$aa;
63my $y = \$aa;
64eval { local $$x; }; test_err_localref;
65eval { local ${$x}; }; test_err_localref;
66eval { local $$y; }; test_err_localref;
67eval { local ${$y}; }; test_err_localref;
68eval { local ${\$aa}; }; test_err_localref;
69eval { local ${\'aa'}; }; test_err_localref;
70$x = \@aa;
71$y = \@aa;
72eval { local @$x; }; test_err_localref;
73eval { local @{$x}; }; test_err_localref;
74eval { local @$y; }; test_err_localref;
75eval { local @{$y}; }; test_err_localref;
76eval { local @{\@aa}; }; test_err_localref;
77eval { local @{[]}; }; test_err_localref;
78$x = \%aa;
79$y = \%aa;
80eval { local %$x; }; test_err_localref;
81eval { local %{$x}; }; test_err_localref;
82eval { local %$y; }; test_err_localref;
83eval { local %{$y}; }; test_err_localref;
84eval { local %{\%aa}; }; test_err_localref;
85eval { local %{{a=>1}}; };test_err_localref;