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