]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/05-words.t
Introduce SCOPE()
[perl/modules/Scope-Upper.git] / t / 05-words.t
index 751b464b0a12ca7e0d37fdd78dff1ad3bdd1c6a5..2405d6ba47d54b1fc2ee6e5540bd1a2f47b2b95f 100644 (file)
@@ -3,56 +3,52 @@
 use strict;
 use warnings;
 
-use Test::More tests => 33;
+use Test::More tests => 29 + 13 * 2;
 
 use Scope::Upper qw/:words/;
 
 is HERE, 0, 'main : here';
 is TOP,  0, 'main : top';
 is UP,   0, 'main : up';
-is DOWN, 0, 'main : down';
 is SUB,  undef, 'main : sub';
 is EVAL, undef, 'main : eval';
 
 {
- is HERE, 0, '{ 1 } : here';
- is TOP,  1, '{ 1 } : top';
- is UP,   1, '{ 1 } : up';
- is DOWN, 0, '{ 1 } : down';
- is DOWN(UP), 0, '{ 1 } : up then down';
- is UP(DOWN), 1, '{ 1 } : down then up';
+ is HERE, 1, '{ 1 } : here';
+ is TOP,  0, '{ 1 } : top';
+ is UP,   0, '{ 1 } : up';
 }
 
 do {
- is TOP, 1, 'do { 1 } : top';
- is SUB, undef, 'do { 1 } : sub';
+ is HERE, 1,     'do { 1 } : here';
+ is SUB,  undef, 'do { 1 } : sub';
  is EVAL, undef, 'do { 1 } : eval';
 };
 
 eval {
- is TOP, 1, 'eval { 1 } : top';
- is SUB, undef, 'eval { 1 } : sub';
- is EVAL, 0, 'eval { 1 } : eval';
+ is HERE, 1,     'eval { 1 } : here';
+ is SUB,  undef, 'eval { 1 } : sub';
+ is EVAL, 1,     'eval { 1 } : eval';
 };
 
 eval q[
- is TOP, 1, 'eval "1" : top';
- is SUB, undef, 'eval "1" : sub';
- is EVAL, 0, 'eval "1" : eval';
+ is HERE, 1,     'eval "1" : here';
+ is SUB,  undef, 'eval "1" : sub';
+ is EVAL, 1,     'eval "1" : eval';
 ];
 
 do {
- is TOP, 1, 'do { 1 } while (0) : top';
+ is HERE, 1, 'do { 1 } while (0) : here';
 } while (0);
 
 sub {
- is TOP, 1, 'sub { 1 } : top';
- is SUB, 0, 'sub { 1 } : sub';
+ is HERE, 1,     'sub { 1 } : here';
+ is SUB,  1,     'sub { 1 } : sub';
  is EVAL, undef, 'sub { 1 } : eval';
 }->();
 
 for (1) {
- is TOP, 1, 'for () { 1 } : top';
+ is HERE, 1, 'for () { 1 } : here';
 }
 
 do {
@@ -61,16 +57,51 @@ do {
    sub {
     eval q[
      {
-      is HERE, 0, 'mixed : here';
-      is TOP,  6, 'mixed : top';
-      is SUB,  2, 'mixed : first sub';
-      is SUB(SUB), 2, 'mixed : still first sub';
-      is EVAL, 1, 'mixed : first eval';
-      is EVAL(EVAL),     1, 'mixed : still first eval';
-      is EVAL(UP(EVAL)), 4, 'mixed : second eval';
+      is HERE,           6, 'mixed : here';
+      is TOP,            0, 'mixed : top';
+      is SUB,            4, 'mixed : first sub';
+      is SUB(SUB),       4, 'mixed : still first sub';
+      is EVAL,           5, 'mixed : first eval';
+      is EVAL(EVAL),     5, 'mixed : still first eval';
+      is EVAL(UP(EVAL)), 2, 'mixed : second eval';
      }
     ];
    }->();
   }
  };
 } while (0);
+
+{
+ is SCOPE,    1, 'block : scope';
+ is SCOPE(0), 1, 'block : scope 0';
+ is SCOPE(1), 0, 'block : scope 1';
+ is CALLER,    0, 'block: caller';
+ is CALLER(0), 0, 'block : caller 0';
+ is CALLER(1), 0, 'block : caller 1';
+ sub {
+  is SCOPE,    2, 'block sub : scope';
+  is SCOPE(0), 2, 'block sub : scope 0';
+  is SCOPE(1), 1, 'block sub : scope 1';
+  is CALLER,    2, 'block sub : caller';
+  is CALLER(0), 2, 'block sub : caller 0';
+  is CALLER(1), 0, 'block sub : caller 1';
+  for (1) {
+   is SCOPE,    3, 'block sub for : scope';
+   is SCOPE(0), 3, 'block sub for : scope 0';
+   is SCOPE(1), 2, 'block sub for : scope 1';
+   is CALLER,    2, 'block sub for : caller';
+   is CALLER(0), 2, 'block sub for : caller 0';
+   is CALLER(1), 0, 'block sub for : caller 1';
+   eval {
+    is SCOPE,    4, 'block sub for eval : scope';
+    is SCOPE(0), 4, 'block sub for eval : scope 0';
+    is SCOPE(1), 3, 'block sub for eval : scope 1';
+    is SCOPE(2), 2, 'block sub for eval : scope 2';
+    is CALLER,    4, 'block sub for eval : caller';
+    is CALLER(0), 4, 'block sub for eval : caller 0';
+    is CALLER(1), 2, 'block sub for eval : caller 1';
+    is CALLER(2), 0, 'block sub for eval : caller 2';
+   }
+  }
+ }->();
+}