X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F20-hash.t;h=ad82aae48831c7809fc916b4567e890ed3fc8486;hb=6a425386b4dab23f859f51f3cc99a6ebe3c414f0;hp=c4fb680acad1c7a6d1c187add88793228ea9f669;hpb=2966b83e4eb41f8bd7f8c354e078bce07ced1fea;p=perl%2Fmodules%2Fautovivification.git diff --git a/t/20-hash.t b/t/20-hash.t index c4fb680..ad82aae 100644 --- a/t/20-hash.t +++ b/t/20-hash.t @@ -3,77 +3,15 @@ use strict; use warnings; -use Test::More tests => 6 * 3 * 240; - -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 * 260; + +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__ @@ -148,6 +86,31 @@ $x->{a}->{b} = 1 # $x->{a}->{b} # '', 1, { a => { b => 1 } } $x->{a}->{b} = 1 # $x->{a}->{d} # '', undef, { a => { b => 1 } } # +strict +store $x->{a}->{b} = 1 # $x->{c}->{d} # '', undef, { a => { b => 1 }, c => { } } # +strict +store +--- aliasing --- + +$x # 1 for $x->{a}; () # '', undef, { a => undef } +$x # 1 for $x->{a}; () # '', undef, undef # +$x # 1 for $x->{a}; () # '', undef, undef # +fetch +$x # 1 for $x->{a}; () # '', undef, { a => undef } # +exists +$x # 1 for $x->{a}; () # '', undef, { a => undef } # +delete +$x # 1 for $x->{a}; () # '', undef, { a => undef } # +store + +$x # $_ = 1 for $x->{a}; () # '', undef, { a => 1 } +$x # $_ = 1 for $x->{a}; () # '', undef, undef # +$x # $_ = 1 for $x->{a}; () # '', undef, undef # +fetch +$x # $_ = 1 for $x->{a}; () # '', undef, { a => 1 } # +exists +$x # $_ = 1 for $x->{a}; () # '', undef, { a => 1 } # +delete +$x # $_ = 1 for $x->{a}; () # '', undef, { a => 1 } # +store + +$x->{a} = 1 # 1 for $x->{a}; () # '', undef, { a => 1 } # +fetch +$x->{a} = 1 # 1 for $x->{b}; () # '', undef, { a => 1, b => undef } # +fetch +$x->{a} = 1 # 1 for $x->{a}; () # '', undef, { a => 1 } # +exists +$x->{a} = 1 # 1 for $x->{b}; () # '', undef, { a => 1, b => undef } # +exists +$x->{a} = 1 # 1 for $x->{a}; () # '', undef, { a => 1 } # +delete +$x->{a} = 1 # 1 for $x->{b}; () # '', undef, { a => 1, b => undef } # +delete +$x->{a} = 1 # 1 for $x->{a}; () # '', undef, { a => 1 } # +store +$x->{a} = 1 # 1 for $x->{b}; () # '', undef, { a => 1, b => undef } # +store + --- exists --- $x # exists $x->{a} # '', '', { }