X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F21-array.t;h=bf843d6e3f02b645bafa2b7c13b429b99354d8ad;hb=4ccff394a949fe8d99359c5ea6d154f85191f731;hp=5183bdfab92689d044df1a35e433539beb5f9727;hpb=92240461f2d526a94139ed4cf0fff445465b380d;p=perl%2Fmodules%2Fautovivification.git diff --git a/t/21-array.t b/t/21-array.t index 5183bdf..bf843d6 100644 --- a/t/21-array.t +++ b/t/21-array.t @@ -3,77 +3,15 @@ use strict; use warnings; -use Test::More tests => 6 * 3 * 260; - -sub testcase { - my ($var, $init, $code, $exp, $use, $global) = @_; - my $decl = $global ? "our $var; local $var;" : "my $var;"; - my $test = $var =~ /^[@%]/ ? "\\$var" : $var; - return < 6 * 3 * 270; + +use lib 't/lib'; +use autovivification::TestCases; while () { 1 while chomp; next unless /#/; - my @chunks = split /#+/, "$_ "; - s/^\s+//, s/\s+$// for @chunks; - my ($init, $code, $exp, $opts) = @chunks; - (my $var = $init) =~ s/[^\$@%\w].*//; - $init = $var eq $init ? '' : "$init;"; - my $use; - if ($opts) { - for (split ' ', $opts) { - my $no = 1; - $no = 0 if s/^([-+])// and $1 eq '-'; - $use .= ($no ? 'no' : 'use') . " autovivification '$_';" - } - } elsif (defined $opts) { - $opts = 'empty'; - $use = 'no autovivification;'; - } else { - $opts = 'default'; - $use = ''; - } - my @testcases = ( - [ $var, $init, $code, $exp, $use, 0 ], - [ $var, "use strict; $init", $code, $exp, $use, 1 ], - [ $var, "no strict; $init", $code, $exp, $use, 1 ], - ); - my @extra; - for (@testcases) { - my $var = $_->[0]; - if ($var =~ /\$/) { - my @new = @$_; - $new[0] =~ s/^$/@/; - $new[1] =~ s/$var\->/$var/g; - $new[2] =~ s/$var\->/$var/g; - push @extra, \@new; - } - } - push @testcases, @extra; - for (@testcases) { - my $testcase = testcase(@$_); - my ($var, $init, $code) = @$_; - my $desc = do { (my $x = "$var | $init") =~ s,;\s+$,,; $x } . " | $code | $opts"; - eval $testcase; - diag "== This testcase failed to compile ==\n$testcase\n## Reason: $@" if $@; - } + testcase_ok($_, '@'); } __DATA__ @@ -173,6 +111,20 @@ $x->[0] = 1 # 1 for $x->[1]; () # '', undef, [ 1, undef ] # +delete $x->[0] = 1 # 1 for $x->[0]; () # '', undef, [ 1 ] # +store $x->[0] = 1 # 1 for $x->[1]; () # '', undef, [ 1, undef ] # +store +--- dereferencing --- + +$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/Can't use an undefined value as an ARRAY reference/ : ''), undef, undef +$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/Can't use an undefined value as an ARRAY reference/ : ''), undef, undef # +$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/Can't use an undefined value as an ARRAY reference/ : ''), undef, undef # +fetch +$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/Can't use an undefined value as an ARRAY reference/ : ''), undef, undef # +exists +$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/Can't use an undefined value as an ARRAY reference/ : ''), undef, undef # +delete +$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/Can't use an undefined value as an ARRAY reference/ : ''), undef, undef # +store + +$x->[0] = 1 # my @a = @$x; () # '', undef, [ 1 ] # +fetch +$x->[0] = 1 # my @a = @$x; () # '', undef, [ 1 ] # +exists +$x->[0] = 1 # my @a = @$x; () # '', undef, [ 1 ] # +delete +$x->[0] = 1 # my @a = @$x; () # '', undef, [ 1 ] # +store + --- exists --- $x # exists $x->[0] # '', '', [ ]