7 use Test::Leaner tests => 4 * 4 * (8 ** 3) * 2;
15 sub { "$_[0] = $magic_val" },
16 sub { "exists $_[0]" },
17 sub { "delete $_[0]" },
20 my (@vlex, %vlex, $vrlex);
21 our (@vgbl, %vgbl, $vrgbl);
24 '$vlex', # lexical array/hash
25 '$vgbl', # global array/hash
26 '$vrlex->', # lexical array/hash reference
27 '$vrgbl->', # global array/hash reference
34 '[0]', # array const (aelemfast)
35 '[$lex]', # array lexical
36 '[$gbl]', # array global
37 '[$lex+1]', # array complex
39 '{$lex}', # hash lexical
40 '{$gbl}', # hash global
41 '{"x$lex"}' # hash complex
45 (@vlex, %vlex, $vrlex) = ();
46 (@vgbl, %vgbl, $vrgbl) = ();
52 package autovivification::TestIterator;
59 next unless defined $arg;
62 if ($type eq 'ARRAY') {
64 } elsif ($type eq '') {
65 $list = [ 1 .. $arg ];
67 die "Invalid argument of type $type";
70 die "Empty list" unless $max;
80 idx => [ (0) x $len ],
87 my ($len, $max, $idx) = @$self{qw<len max idx>};
91 for ($i = 0; $i < $len; ++$i) {
92 if ($idx->[$i] == $max->[$i]) {
94 ++$idx->[$i + 1] unless $i == $len - 1;
106 my ($len, $lists, $idx) = @$self{qw<len lists idx>};
108 return map $lists->[$_]->[$idx->[$_]], 0 .. ($len - 1);
112 my $iterator = autovivification::TestIterator->new(
113 \@prefixes, \@heads, (\@derefs) x $depth,
116 my ($prefix, @elems) = $iterator->items;
117 my $code = $prefix->(join '', @elems);
118 my $exp = ($code =~ /^\s*exists/) ? !1
119 : (($code =~ /=\s*$magic_val/) ? $magic_val
122 my ($res, $err) = do {
123 local $SIG{__WARN__} = sub { die @_ };
125 my $r = eval <<" CODE";
131 is $err, '', "$code: no exception";
132 is $res, $exp, "$code: value";
133 } while ($iterator->next);