]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/20-localize.t
Importing Scope-Upper-0.01
[perl/modules/Scope-Upper.git] / t / 20-localize.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 4 + 10 + 6 + 5 + 6;
7
8 use Scope::Upper qw/localize/;
9
10 our $x;
11
12 sub loc { local $x; my $y = $_[1]; localize '$x', $y, $_[0] + 1 }
13
14 $x = 0;
15 {
16  is($x, 0, 'start');
17  local $x = 7;
18  {
19   local $x = 8;
20   loc(0, 1);
21   is($x, 1, 'localized to 1');
22  }
23  is($x, 7, 'no longer localized');
24 }
25 is($x, 0, 'end');
26
27 $x = 0;
28 {
29  is($x, 0, 'start');
30  local $x = 7;
31  {
32   local $x = 8;
33   loc(1, 1);
34   is($x, 8, 'not localized');
35   local $x = 9;
36   is($x, 9, 'not localized');
37  }
38  is($x, 1, 'localized to 1');
39  {
40   is($x, 1, 'localized to 1');
41   {
42    is($x, 1, 'localized to 1');
43    local $x = 10;
44    is($x, 10, 'localized to undef');
45   }
46   is($x, 1, 'localized to 1');
47  }
48  is($x, 1, 'localized to 1');
49 }
50 is($x, 0, 'end');
51
52 $x = 0;
53 {
54  is($x, 0, 'start');
55  local $x = 7;
56  {
57   local $x = 8;
58   {
59    local $x = 9;
60    {
61     local $x = 10;
62     loc(2, 1);
63     is($x, 10, 'not localized');
64    }
65    is($x, 9, 'not localized');
66   }
67   is($x, 1, 'localized to 1');
68  }
69  is($x, 7, 'no longer localized');
70 }
71 is($x, 0, 'end');
72
73 $x = 0;
74 {
75  is($x, 0, 'start');
76  local $x = 8;
77  {
78   {
79    local $x = 8;
80    loc(2, 1);
81    is($x, 8, 'not localized');
82   }
83   loc(0, 2);
84   is($x, 2, 'localized to 2');
85  }
86  is($x, 1, 'localized to 1');
87 }
88 is($x, 0, 'end');
89
90 $x = 0;
91 {
92  is($x, 0, 'start');
93  local $x;
94  {
95   {
96    loc(2, 1);
97    is($x, undef, 'not localized');
98    local $x;
99    loc(1, 2);
100    is($x, undef, 'not localized');
101   }
102   is($x, 2, 'localized to 2');
103  }
104  is($x, 1, 'localized to 1');
105 }
106 is($x, 0, 'end');
107