]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/05-words.t
Introduce SCOPE()
[perl/modules/Scope-Upper.git] / t / 05-words.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 29 + 13 * 2;
7
8 use Scope::Upper qw/:words/;
9
10 is HERE, 0, 'main : here';
11 is TOP,  0, 'main : top';
12 is UP,   0, 'main : up';
13 is SUB,  undef, 'main : sub';
14 is EVAL, undef, 'main : eval';
15
16 {
17  is HERE, 1, '{ 1 } : here';
18  is TOP,  0, '{ 1 } : top';
19  is UP,   0, '{ 1 } : up';
20 }
21
22 do {
23  is HERE, 1,     'do { 1 } : here';
24  is SUB,  undef, 'do { 1 } : sub';
25  is EVAL, undef, 'do { 1 } : eval';
26 };
27
28 eval {
29  is HERE, 1,     'eval { 1 } : here';
30  is SUB,  undef, 'eval { 1 } : sub';
31  is EVAL, 1,     'eval { 1 } : eval';
32 };
33
34 eval q[
35  is HERE, 1,     'eval "1" : here';
36  is SUB,  undef, 'eval "1" : sub';
37  is EVAL, 1,     'eval "1" : eval';
38 ];
39
40 do {
41  is HERE, 1, 'do { 1 } while (0) : here';
42 } while (0);
43
44 sub {
45  is HERE, 1,     'sub { 1 } : here';
46  is SUB,  1,     'sub { 1 } : sub';
47  is EVAL, undef, 'sub { 1 } : eval';
48 }->();
49
50 for (1) {
51  is HERE, 1, 'for () { 1 } : here';
52 }
53
54 do {
55  eval {
56   do {
57    sub {
58     eval q[
59      {
60       is HERE,           6, 'mixed : here';
61       is TOP,            0, 'mixed : top';
62       is SUB,            4, 'mixed : first sub';
63       is SUB(SUB),       4, 'mixed : still first sub';
64       is EVAL,           5, 'mixed : first eval';
65       is EVAL(EVAL),     5, 'mixed : still first eval';
66       is EVAL(UP(EVAL)), 2, 'mixed : second eval';
67      }
68     ];
69    }->();
70   }
71  };
72 } while (0);
73
74 {
75  is SCOPE,    1, 'block : scope';
76  is SCOPE(0), 1, 'block : scope 0';
77  is SCOPE(1), 0, 'block : scope 1';
78  is CALLER,    0, 'block: caller';
79  is CALLER(0), 0, 'block : caller 0';
80  is CALLER(1), 0, 'block : caller 1';
81  sub {
82   is SCOPE,    2, 'block sub : scope';
83   is SCOPE(0), 2, 'block sub : scope 0';
84   is SCOPE(1), 1, 'block sub : scope 1';
85   is CALLER,    2, 'block sub : caller';
86   is CALLER(0), 2, 'block sub : caller 0';
87   is CALLER(1), 0, 'block sub : caller 1';
88   for (1) {
89    is SCOPE,    3, 'block sub for : scope';
90    is SCOPE(0), 3, 'block sub for : scope 0';
91    is SCOPE(1), 2, 'block sub for : scope 1';
92    is CALLER,    2, 'block sub for : caller';
93    is CALLER(0), 2, 'block sub for : caller 0';
94    is CALLER(1), 0, 'block sub for : caller 1';
95    eval {
96     is SCOPE,    4, 'block sub for eval : scope';
97     is SCOPE(0), 4, 'block sub for eval : scope 0';
98     is SCOPE(1), 3, 'block sub for eval : scope 1';
99     is SCOPE(2), 2, 'block sub for eval : scope 2';
100     is CALLER,    4, 'block sub for eval : caller';
101     is CALLER(0), 4, 'block sub for eval : caller 0';
102     is CALLER(1), 2, 'block sub for eval : caller 1';
103     is CALLER(2), 0, 'block sub for eval : caller 2';
104    }
105   }
106  }->();
107 }