From: Vincent Pit Date: Sat, 26 Jun 2010 14:09:05 +0000 (+0200) Subject: Test numerous autovivifications X-Git-Tag: rt62800~8 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=cc49b33d4f6bae20e1f59e987ae52605cf5527fe;p=perl%2Fmodules%2Fautovivification.git Test numerous autovivifications --- diff --git a/MANIFEST b/MANIFEST index 064ed3e..63d31e1 100644 --- a/MANIFEST +++ b/MANIFEST @@ -13,10 +13,12 @@ t/00-load.t t/20-hash.t t/22-hash-kv.t t/23-hash-tied.t +t/24-hash-numerous.t t/30-array.t t/31-array-fast.t t/32-array-kv.t t/33-array-tied.t +t/34-array-numerous.t t/40-scope.t t/41-padsv.t t/42-deparse.t diff --git a/t/24-hash-numerous.t b/t/24-hash-numerous.t new file mode 100644 index 0000000..6d489a8 --- /dev/null +++ b/t/24-hash-numerous.t @@ -0,0 +1,152 @@ +#!perl + +use strict; +use warnings; + +use Test::More tests => 2 * 2 * 4; + +my $n = 100; + +{ + my $w; + { + my $r; + no autovivification; + $r = $w->{a}{b} for 1 .. $n; + } + is_deeply $w, undef, 'numerous fetches from an undef lexical'; + + $w = { a => undef }; + { + my $r; + no autovivification; + $r = $w->{a}{b} for 1 .. $n; + } + is_deeply $w, { a => undef },'numerous fetches from a 1-level hashref lexical'; +} + +{ + our $w; + { + my $r; + no autovivification; + $r = $w->{a}{b} for 1 .. $n; + } + is_deeply $w, undef, 'numerous fetches from an undef global'; + + $w = { a => undef }; + { + my $r; + no autovivification; + $r = $w->{a}{b} for 1 .. $n; + } + is_deeply $w, { a => undef },'numerous fetches from a 1-level hashref global'; +} + +{ + my $x; + { + my @r; + no autovivification; + @r = @{$x}{qw/a b/} for 1 .. $n; + } + is_deeply $x, undef, 'numerous slices from an undef lexical'; + + $x = { a => undef }; + { + my @r; + no autovivification; + @r = @{$x->{a}}{qw/b c/} for 1 .. $n; + } + is_deeply $x, { a => undef }, 'numerous slices from a 1-level hashref lexical'; +} + +{ + our $x; + { + my @r; + no autovivification; + @r = @{$x}{qw/a b/} for 1 .. $n; + } + is_deeply $x, undef, 'numerous slices from an undef global'; + + $x = { a => undef }; + { + my @r; + no autovivification; + @r = @{$x->{a}}{qw/b c/} for 1 .. $n; + } + is_deeply $x, { a => undef }, 'numerous slices from a 1-level hashref global'; +} + +{ + my $y; + { + my $r; + no autovivification; + $r = exists $y->{a}{b} for 1 .. $n; + } + is_deeply $y, undef, 'numerous exists from an undef lexical'; + + $y = { a => undef }; + { + my $r; + no autovivification; + $r = exists $y->{a}{b} for 1 .. $n; + } + is_deeply $y, { a => undef },'numerous exists from a 1-level hashref lexical'; +} + +{ + our $y; + { + my $r; + no autovivification; + $r = exists $y->{a}{b} for 1 .. $n; + } + is_deeply $y, undef, 'numerous exists from an undef global'; + + $y = { a => undef }; + { + my $r; + no autovivification; + $r = exists $y->{a}{b} for 1 .. $n; + } + is_deeply $y, { a => undef },'numerous exists from a 1-level hashref global'; +} + +{ + my $z; + { + my $r; + no autovivification; + $r = delete $z->{a}{b} for 1 .. $n; + } + is_deeply $z, undef, 'numerous deletes from an undef lexical'; + + $z = { a => undef }; + { + my $r; + no autovivification; + $r = delete $z->{a}{b} for 1 .. $n; + } + is_deeply $z, { a => undef },'numerous deletes from a 1-level hashref lexical'; +} + +{ + our $z; + { + my $r; + no autovivification; + $r = delete $z->{a}{b} for 1 .. $n; + } + is_deeply $z, undef, 'numerous deletes from an undef global'; + + $z = { a => undef }; + { + my $r; + no autovivification; + $r = delete $z->{a}{b} for 1 .. $n; + } + is_deeply $z, { a => undef },'numerous deletes from a 1-level hashref global'; +} diff --git a/t/34-array-numerous.t b/t/34-array-numerous.t new file mode 100644 index 0000000..1fda1f0 --- /dev/null +++ b/t/34-array-numerous.t @@ -0,0 +1,152 @@ +#!perl + +use strict; +use warnings; + +use Test::More tests => 2 * 2 * 4; + +my $n = 100; +my $i = 0; + +{ + my $w; + { + my $r; + no autovivification; + $r = $w->[0][$i] for 1 .. $n; + } + is_deeply $w, undef, 'numerous fetches from an undef lexical'; + + $w = [ undef ]; + { + my $r; + no autovivification; + $r = $w->[0][$i] for 1 .. $n; + } + is_deeply $w, [ undef ], 'numerous fetches from a 1-level arrayref lexical'; +} + +{ + our $w; + { + my $r; + no autovivification; + $r = $w->[0][$i] for 1 .. $n; + } + is_deeply $w, undef, 'numerous fetches from an undef global'; + + $w = [ undef ]; + { + my $r; + no autovivification; + $r = $w->[0][$i] for 1 .. $n; + } + is_deeply $w, [ undef ], 'numerous fetches from a 1-level arrayref global'; +} + +{ + my $x; + { + my @r; + no autovivification; + @r = @{$x}[0, 1] for 1 .. $n; + } + is_deeply $x, undef, 'numerous slices from an undef lexical'; + + $x = [ undef ]; + { + my @r; + no autovivification; + @r = @{$x->[0]}[0, 1] for 1 .. $n; + } + is_deeply $x, [ undef ], 'numerous slices from a 1-level arrayref lexical'; +} + +{ + our $x; + { + my @r; + no autovivification; + @r = @{$x}[0, 1] for 1 .. $n; + } + is_deeply $x, undef, 'numerous slices from an undef global'; + + $x = [ undef ]; + { + my @r; + no autovivification; + @r = @{$x->[0]}[0, 1] for 1 .. $n; + } + is_deeply $x, [ undef ], 'numerous slices from a 1-level arrayref global'; +} +{ + my $y; + { + my $r; + no autovivification; + $r = exists $y->[0][$i] for 1 .. $n; + } + is_deeply $y, undef, 'numerous exists from an undef lexical'; + + $y = [ undef ]; + { + my $r; + no autovivification; + $r = exists $y->[0][$i] for 1 .. $n; + } + is_deeply $y, [ undef ], 'numerous exists from a 1-level arrayref lexical'; +} + +{ + our $y; + { + my $r; + no autovivification; + $r = exists $y->[0][$i] for 1 .. $n; + } + is_deeply $y, undef, 'numerous exists from an undef global'; + + $y = [ undef ]; + { + my $r; + no autovivification; + $r = exists $y->[0][$i] for 1 .. $n; + } + is_deeply $y, [ undef ], 'numerous exists from a 1-level arrayref global'; +} + +{ + my $z; + { + my $r; + no autovivification; + $r = delete $z->[0][$i] for 1 .. $n; + } + is_deeply $z, undef, 'numerous deletes from an undef lexical'; + + $z = [ undef ]; + { + my $r; + no autovivification; + $r = delete $z->[0][$i] for 1 .. $n; + } + is_deeply $z, [ undef ], 'numerous deletes from a 1-level arrayref lexical'; +} + +{ + our $z; + { + my $r; + no autovivification; + $r = delete $z->[0][$i] for 1 .. $n; + } + is_deeply $z, undef, 'numerous deletes from an undef global'; + + $z = [ undef ]; + { + my $r; + no autovivification; + $r = delete $z->[0][$i] for 1 .. $n; + } + is_deeply $z, [ undef ], 'numerous deletes from a 1-level arrayref global'; +}