]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/32-localize_elem-block.t
Importing Scope-Upper-0.01
[perl/modules/Scope-Upper.git] / t / 32-localize_elem-block.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More 'no_plan'; 
7
8 use Scope::Upper qw/localize_elem/;
9
10 use lib 't/lib';
11 use Scope::Upper::TestGenerator;
12
13 local $Scope::Upper::TestGenerator::testlocal = sub { '' };
14
15 local $Scope::Upper::TestGenerator::allblocks = 1;
16
17 our $testcase;
18
19 local $Scope::Upper::TestGenerator::call = sub {
20  my ($height, $level, $i) = @_;
21  return [ "localize_elem '\@a', 1 => 0 => $level;\n" ];
22 };
23
24 local $Scope::Upper::TestGenerator::test = sub {
25  my ($height, $level, $i, $x) = @_;
26  my $j = ($i == $height - $level) ? 0 : (defined $x ? $x : 11);
27  return "is(\$a[1], $j, 'x h=$height, l=$level, i=$i');\n";
28 };
29
30 local $Scope::Upper::TestGenerator::local = sub {
31  my $x = $_[3];
32  return "local \$a[1] = $x;\n";
33 };
34
35 our @a;
36
37 for my $level (0 .. 1) {
38  my $height = $level + 1;
39  my $tests = Scope::Upper::TestGenerator::gen($height, $level);
40  for (@$tests) {
41   $testcase = $_;
42   @a = (10, 11);
43   eval;
44   diag $@ if $@;
45  }
46 }
47
48 local $Scope::Upper::TestGenerator::call = sub {
49  my ($height, $level, $i) = @_;
50  return [ "localize_elem '%h', 'a' => 0 => $level;\n" ];
51 };
52
53 local $Scope::Upper::TestGenerator::test = sub {
54  my ($height, $level, $i, $x) = @_;
55  my $j = ($i == $height - $level) ? 0 : (defined $x ? $x : 'undef');
56  return "is(\$h{a}, $j, 'x h=$height, l=$level, i=$i');\n";
57 };
58
59 local $Scope::Upper::TestGenerator::local = sub {
60  my $x = $_[3];
61  return "local \$h{a} = $x;\n";
62 };
63
64 our %h;
65
66 for my $level (0 .. 1) {
67  my $height = $level + 1;
68  my $tests = Scope::Upper::TestGenerator::gen($height, $level);
69  for (@$tests) {
70   $testcase = $_;
71   %h = ();
72   eval;
73   diag $@ if $@;
74  }
75 }