]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/05-words.t
Add a warning in t/05-words.t
[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 # This test is for internal use only and doesn't imply any kind of future
11 # compatibility on what the words should actually return.
12 # It is expected to fail when ran under the debugger.
13
14 is HERE, 0, 'main : here';
15 is TOP,  0, 'main : top';
16 is UP,   0, 'main : up';
17 is SUB,  undef, 'main : sub';
18 is EVAL, undef, 'main : eval';
19
20 {
21  is HERE, 1, '{ 1 } : here';
22  is TOP,  0, '{ 1 } : top';
23  is UP,   0, '{ 1 } : up';
24 }
25
26 do {
27  is HERE, 1,     'do { 1 } : here';
28  is SUB,  undef, 'do { 1 } : sub';
29  is EVAL, undef, 'do { 1 } : eval';
30 };
31
32 eval {
33  is HERE, 1,     'eval { 1 } : here';
34  is SUB,  undef, 'eval { 1 } : sub';
35  is EVAL, 1,     'eval { 1 } : eval';
36 };
37
38 eval q[
39  is HERE, 1,     'eval "1" : here';
40  is SUB,  undef, 'eval "1" : sub';
41  is EVAL, 1,     'eval "1" : eval';
42 ];
43
44 do {
45  is HERE, 1, 'do { 1 } while (0) : here';
46 } while (0);
47
48 sub {
49  is HERE, 1,     'sub { 1 } : here';
50  is SUB,  1,     'sub { 1 } : sub';
51  is EVAL, undef, 'sub { 1 } : eval';
52 }->();
53
54 for (1) {
55  is HERE, 1, 'for () { 1 } : here';
56 }
57
58 do {
59  eval {
60   do {
61    sub {
62     eval q[
63      {
64       is HERE,           6, 'mixed : here';
65       is TOP,            0, 'mixed : top';
66       is SUB,            4, 'mixed : first sub';
67       is SUB(SUB),       4, 'mixed : still first sub';
68       is EVAL,           5, 'mixed : first eval';
69       is EVAL(EVAL),     5, 'mixed : still first eval';
70       is EVAL(UP(EVAL)), 2, 'mixed : second eval';
71      }
72     ];
73    }->();
74   }
75  };
76 } while (0);
77
78 {
79  is SCOPE,    1, 'block : scope';
80  is SCOPE(0), 1, 'block : scope 0';
81  is SCOPE(1), 0, 'block : scope 1';
82  is CALLER,    0, 'block: caller';
83  is CALLER(0), 0, 'block : caller 0';
84  is CALLER(1), 0, 'block : caller 1';
85  sub {
86   is SCOPE,    2, 'block sub : scope';
87   is SCOPE(0), 2, 'block sub : scope 0';
88   is SCOPE(1), 1, 'block sub : scope 1';
89   is CALLER,    2, 'block sub : caller';
90   is CALLER(0), 2, 'block sub : caller 0';
91   is CALLER(1), 0, 'block sub : caller 1';
92   for (1) {
93    is SCOPE,    3, 'block sub for : scope';
94    is SCOPE(0), 3, 'block sub for : scope 0';
95    is SCOPE(1), 2, 'block sub for : scope 1';
96    is CALLER,    2, 'block sub for : caller';
97    is CALLER(0), 2, 'block sub for : caller 0';
98    is CALLER(1), 0, 'block sub for : caller 1';
99    eval {
100     is SCOPE,    4, 'block sub for eval : scope';
101     is SCOPE(0), 4, 'block sub for eval : scope 0';
102     is SCOPE(1), 3, 'block sub for eval : scope 1';
103     is SCOPE(2), 2, 'block sub for eval : scope 2';
104     is CALLER,    4, 'block sub for eval : caller';
105     is CALLER(0), 4, 'block sub for eval : caller 0';
106     is CALLER(1), 2, 'block sub for eval : caller 1';
107     is CALLER(2), 0, 'block sub for eval : caller 2';
108    }
109   }
110  }->();
111 }