From: rkinyon Date: Thu, 23 Feb 2006 03:52:21 +0000 (+0000) Subject: Added tests on the return value of splice plus a comment on the need for setting X-Git-Tag: 0-97~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8fec41b9e33bdbabde82b0fe1d2334db33c22c15;p=dbsrgits%2FDBM-Deep.git Added tests on the return value of splice plus a comment on the need for setting --- diff --git a/lib/DBM/Deep/Array.pm b/lib/DBM/Deep/Array.pm index fd4abba..01fd9fb 100644 --- a/lib/DBM/Deep/Array.pm +++ b/lib/DBM/Deep/Array.pm @@ -2,6 +2,9 @@ package DBM::Deep::Array; use strict; +# This is to allow DBM::Deep::Array to handle negative indices on +# its own. Otherwise, Perl would intercept the call to negative +# indices for us. This was causing bugs for negative index handling. use vars qw( $NEGATIVE_INDICES ); $NEGATIVE_INDICES = 1; diff --git a/t/04_array.t b/t/04_array.t index c765cd5..04a62bc 100644 --- a/t/04_array.t +++ b/t/04_array.t @@ -2,7 +2,7 @@ # DBM::Deep Test ## use strict; -use Test::More tests => 95; +use Test::More tests => 99; use Test::Exception; use_ok( 'DBM::Deep' ); @@ -158,7 +158,9 @@ is($db->[2], "elem last", "Third element is 'elem last'"); ## # splice with length 1 ## -$db->splice( 1, 1, "middle A", "middle B" ); +my @returned = $db->splice( 1, 1, "middle A", "middle B" ); +is( scalar(@returned), 1, "One element was removed" ); +is( $returned[0], 'elem middle', "... and it was correctly removed" ); is($db->length(), 4); is($db->[0], "elem first"); is($db->[1], "middle A"); @@ -168,7 +170,8 @@ is($db->[3], "elem last"); ## # splice with length of 0 ## -$db->splice( -1, 0, "middle C" ); +@returned = $db->splice( -1, 0, "middle C" ); +is( scalar(@returned), 0, "No elements were removed" ); is($db->length(), 5); is($db->[0], "elem first"); is($db->[1], "middle A"); @@ -179,7 +182,8 @@ is($db->[4], "elem last"); ## # splice with length of 3 ## -$db->splice( 1, 3, "middle ABC" ); +my $returned = $db->splice( 1, 3, "middle ABC" ); +is( $returned, 'middle C', "Just the last element was returned" ); is($db->length(), 3); is($db->[0], "elem first"); is($db->[1], "middle ABC");