]> git.vpit.fr Git - perl/modules/autovivification.git/blobdiff - t/20-hash.t
Handle array and hash slices
[perl/modules/autovivification.git] / t / 20-hash.t
index fa16a375d6cadae30f4499fcfbe3ceece2223dbf..6438056f89dae2ea5cf53250540d8e86ed9ea824 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 9 * 3 * 274;
+use Test::More tests => 9 * 3 * 290;
 
 use lib 't/lib';
 use autovivification::TestCases;
@@ -130,6 +130,28 @@ $x->{a} = 1 # my @a = %$x; () # '', undef, { a => 1 } # +exists
 $x->{a} = 1 # my @a = %$x; () # '', undef, { a => 1 } # +delete
 $x->{a} = 1 # my @a = %$x; () # '', undef, { a => 1 } # +store
 
+--- slice ---
+
+$x # my @a = @$x{'a', 'b'}; \@a # '', [ undef, undef ], { }
+$x # my @a = @$x{'a', 'b'}; \@a # '', [ undef, undef ], undef #
+$x # my @a = @$x{'a', 'b'}; \@a # '', [ undef, undef ], undef # +fetch
+$x # my @a = @$x{'a', 'b'}; \@a # '', [ undef, undef ], { }   # +exists
+$x # my @a = @$x{'a', 'b'}; \@a # '', [ undef, undef ], { }   # +delete
+$x # my @a = @$x{'a', 'b'}; \@a # '', [ undef, undef ], { }   # +store
+
+$x->{b} = 0 # my @a = @$x{'a', 'b'}; \@a # '', [ undef, 0 ], { b => 0 } # +fetch
+
+$x # @$x{'a', 'b'} = (1, 2); () # '', undef, { a => 1, b => 2 }
+$x # @$x{'a', 'b'} = (1, 2); () # '', undef, { a => 1, b => 2 } #
+$x # @$x{'a', 'b'} = (1, 2); () # '', undef, { a => 1, b => 2 } # +fetch
+$x # @$x{'a', 'b'} = (1, 2); () # '', undef, { a => 1, b => 2 } # +exists
+$x # @$x{'a', 'b'} = (1, 2); () # '', undef, { a => 1, b => 2 } # +delete
+$x # @$x{'a', 'b'} = (1, 2); () # qr/^Can't vivify reference/, undef, undef # +store
+
+$x->{a} = 0              # @$x{'a', 'b'} = (1, 2); () # '', undef, { a => 1, b => 2 } # +store
+$x->{c} = 0              # @$x{'a', 'b'} = (1, 2); () # '', undef, { a => 1, b => 2, c => 0 } # +store
+$x->{a} = 0, $x->{b} = 0 # @$x{'a', 'b'} = (1, 2); () # '', undef, { a => 1, b => 2 } # +store
+
 --- exists ---
 
 $x # exists $x->{a} # '', '', { }