X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F04_array.t;h=24b52ecbb74f22c9c8f85ac1acacd89a2ed93d4d;hb=6e78585cfdedc2754b455639da5cc877d7f25cab;hp=cc2b2b94e9ded25c82c1fd848bcd2793e58236ca;hpb=9bb8d2fd2efafc7b4832e87f9109eb72751975cf;p=dbsrgits%2FDBM-Deep.git diff --git a/t/04_array.t b/t/04_array.t index cc2b2b9..24b52ec 100644 --- a/t/04_array.t +++ b/t/04_array.t @@ -2,7 +2,7 @@ # DBM::Deep Test ## use strict; -use Test::More tests => 124; +use Test::More tests => 128; use Test::Exception; use t::common qw( new_fh ); @@ -10,8 +10,9 @@ use_ok( 'DBM::Deep' ); my ($fh, $filename) = new_fh(); my $db = DBM::Deep->new( - file => $filename, - type => DBM::Deep->TYPE_ARRAY + file => $filename, + fh => $fh, + type => DBM::Deep->TYPE_ARRAY ); ## @@ -62,7 +63,7 @@ is( $db->fetch(4), 'elem4.1' ); throws_ok { $db->[-6] = 'whoops!'; -} qr/Modification of non-creatable array value attempted, subscript -6/, "Correct error thrown"; +} qr/Modification of non-creatable array value attempted, subscript -6/, "Correct error thrown"; my $popped = $db->pop; is( $db->length, 4, "... and we have four after popping" ); @@ -77,6 +78,7 @@ is( $db->length, 3, "... and we have three after shifting" ); is( $db->[0], 'elem1', "0th element still there after shifting" ); is( $db->[1], 'elem2', "1st element still there after shifting" ); is( $db->[2], 'elem3', "2nd element still there after shifting" ); +is( $db->[3], undef, "There is no third element now" ); is( $shifted, 'elem0', "Shifted value is correct" ); ## @@ -196,6 +198,11 @@ is($db->[0], "elem first"); is($db->[1], "elem last"); is($returned[0], "middle ABC"); +@returned = $db->splice; +is( $db->length, 0 ); +is( $returned[0], "elem first" ); +is( $returned[1], "elem last" ); + $db->[0] = [ 1 .. 3 ]; $db->[1] = { a => 'foo' }; is( $db->[0]->length, 3, "Reuse of same space with array successful" ); @@ -240,30 +247,32 @@ throws_ok { } qr/Cannot use an undefined array index/, "EXISTS fails on an undefined key"; # Bug reported by Mike Schilli +# Also, RT #29583 reported by HANENKAMP { my ($fh, $filename) = new_fh(); my $db = DBM::Deep->new( file => $filename, + fh => $fh, type => DBM::Deep->TYPE_ARRAY ); - push @{$db}, 1, { foo => 1 }; + push @{$db}, 3, { foo => 1 }; lives_ok { shift @{$db}; } "Shift doesn't die moving references around"; is( $db->[0]{foo}, 1, "Right hashref there" ); lives_ok { - unshift @{$db}, [ 1 .. 3 ]; + unshift @{$db}, [ 1 .. 3, [ 1 .. 3 ] ]; unshift @{$db}, 1; } "Unshift doesn't die moving references around"; - is( $db->[1][1], 2, "Right arrayref there" ); + is( $db->[1][3][1], 2, "Right arrayref there" ); is( $db->[2]{foo}, 1, "Right hashref there" ); # Add test for splice moving references around lives_ok { splice @{$db}, 0, 0, 1 .. 3; } "Splice doesn't die moving references around"; - is( $db->[4][1], 2, "Right arrayref there" ); + is( $db->[4][3][1], 2, "Right arrayref there" ); is( $db->[5]{foo}, 1, "Right hashref there" ); }