]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/32-localize_elem-block.t
Rework how Scope::Upper::TestGenerator generates its 'local' tests
[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 our $testcase;
14
15 local $Scope::Upper::TestGenerator::local_test = sub { '' };
16
17 local $Scope::Upper::TestGenerator::allblocks = 1;
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_var = '$a[1]';
32
33 our @a;
34
35 for my $level (0 .. 1) {
36  my $height = $level + 1;
37  my $tests = Scope::Upper::TestGenerator::gen($height, $level);
38  for (@$tests) {
39   $testcase = $_;
40   @a = (10, 11);
41   eval;
42   diag $@ if $@;
43  }
44 }
45
46 local $Scope::Upper::TestGenerator::call = sub {
47  my ($height, $level, $i) = @_;
48  $level = $level ? 'UP ' x $level : 'HERE';
49  return [ "localize_elem '%h', 'a' => 0 => $level;\n" ];
50 };
51
52 local $Scope::Upper::TestGenerator::test = sub {
53  my ($height, $level, $i, $x) = @_;
54  my $j = ($i == $height - $level) ? 0 : (defined $x ? $x : 'undef');
55  return "is(\$h{a}, $j, 'x h=$height, l=$level, i=$i');\n";
56 };
57
58 local $Scope::Upper::TestGenerator::local_var = '$h{a}';
59
60 our %h;
61
62 for my $level (0 .. 1) {
63  my $height = $level + 1;
64  my $tests = Scope::Upper::TestGenerator::gen($height, $level);
65  for (@$tests) {
66   $testcase = $_;
67   %h = ();
68   eval;
69   diag $@ if $@;
70  }
71 }