]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/05-words.t
bcb3ac9bcc806e5b986df0706cef95818c3e5f27
[perl/modules/Scope-Upper.git] / t / 05-words.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 BEGIN {
9  if ($^P) {
10   plan skip_all => 'hardcoded values are wrong under the debugger';
11  } else {
12   plan tests    => 29 + 13 * 2;
13  }
14 }
15
16 use Scope::Upper qw<:words>;
17
18 # This test is for internal use only and doesn't imply any kind of future
19 # compatibility on what the words should actually return.
20
21 is HERE, 0, 'main : here';
22 is TOP,  0, 'main : top';
23 is UP,   0, 'main : up';
24 is SUB,  undef, 'main : sub';
25 is EVAL, undef, 'main : eval';
26
27 {
28  is HERE, 1, '{ 1 } : here';
29  is TOP,  0, '{ 1 } : top';
30  is UP,   0, '{ 1 } : up';
31 }
32
33 do {
34  is HERE, 1,     'do { 1 } : here';
35  is SUB,  undef, 'do { 1 } : sub';
36  is EVAL, undef, 'do { 1 } : eval';
37 };
38
39 eval {
40  is HERE, 1,     'eval { 1 } : here';
41  is SUB,  undef, 'eval { 1 } : sub';
42  is EVAL, 1,     'eval { 1 } : eval';
43 };
44
45 eval q[
46  is HERE, 1,     'eval "1" : here';
47  is SUB,  undef, 'eval "1" : sub';
48  is EVAL, 1,     'eval "1" : eval';
49 ];
50
51 do {
52  is HERE, 1, 'do { 1 } while (0) : here';
53 } while (0);
54
55 sub {
56  is HERE, 1,     'sub { 1 } : here';
57  is SUB,  1,     'sub { 1 } : sub';
58  is EVAL, undef, 'sub { 1 } : eval';
59 }->();
60
61 for (1) {
62  is HERE, 1, 'for () { 1 } : here';
63 }
64
65 do {
66  eval {
67   do {
68    sub {
69     eval q[
70      {
71       is HERE,           6, 'mixed : here';
72       is TOP,            0, 'mixed : top';
73       is SUB,            4, 'mixed : first sub';
74       is SUB(SUB),       4, 'mixed : still first sub';
75       is EVAL,           5, 'mixed : first eval';
76       is EVAL(EVAL),     5, 'mixed : still first eval';
77       is EVAL(UP(EVAL)), 2, 'mixed : second eval';
78      }
79     ];
80    }->();
81   }
82  };
83 } while (0);
84
85 {
86  is SCOPE,    1, 'block : scope';
87  is SCOPE(0), 1, 'block : scope 0';
88  is SCOPE(1), 0, 'block : scope 1';
89  is CALLER,    0, 'block: caller';
90  is CALLER(0), 0, 'block : caller 0';
91  is CALLER(1), 0, 'block : caller 1';
92  sub {
93   is SCOPE,    2, 'block sub : scope';
94   is SCOPE(0), 2, 'block sub : scope 0';
95   is SCOPE(1), 1, 'block sub : scope 1';
96   is CALLER,    2, 'block sub : caller';
97   is CALLER(0), 2, 'block sub : caller 0';
98   is CALLER(1), 0, 'block sub : caller 1';
99   for (1) {
100    is SCOPE,    3, 'block sub for : scope';
101    is SCOPE(0), 3, 'block sub for : scope 0';
102    is SCOPE(1), 2, 'block sub for : scope 1';
103    is CALLER,    2, 'block sub for : caller';
104    is CALLER(0), 2, 'block sub for : caller 0';
105    is CALLER(1), 0, 'block sub for : caller 1';
106    eval {
107     is SCOPE,    4, 'block sub for eval : scope';
108     is SCOPE(0), 4, 'block sub for eval : scope 0';
109     is SCOPE(1), 3, 'block sub for eval : scope 1';
110     is SCOPE(2), 2, 'block sub for eval : scope 2';
111     is CALLER,    4, 'block sub for eval : caller';
112     is CALLER(0), 4, 'block sub for eval : caller 0';
113     is CALLER(1), 2, 'block sub for eval : caller 1';
114     is CALLER(2), 0, 'block sub for eval : caller 2';
115    }
116   }
117  }->();
118 }