From: rkinyon Date: Tue, 21 Feb 2006 19:45:50 +0000 (+0000) Subject: UNSHIFT and PUSH now return the length of the new array X-Git-Tag: 0-97~31 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8f6d6ed019154cc498c0fafdea6d443d53e2de17;p=dbsrgits%2FDBM-Deep.git UNSHIFT and PUSH now return the length of the new array --- diff --git a/lib/DBM/Deep/Array.pm b/lib/DBM/Deep/Array.pm index 9f11127..cacfea6 100644 --- a/lib/DBM/Deep/Array.pm +++ b/lib/DBM/Deep/Array.pm @@ -90,6 +90,8 @@ sub PUSH { $self->STORE( $length, $content ); $length++; } + + return $length; } sub SHIFT { @@ -137,6 +139,8 @@ sub UNSHIFT { for (my $i = 0; $i < $new_size; $i++) { $self->STORE( $i, $new_elements[$i] ); } + + return $length + $new_size; } sub SPLICE { diff --git a/t/04_array.t b/t/04_array.t index d5385a1..c75c2dc 100644 --- a/t/04_array.t +++ b/t/04_array.t @@ -140,12 +140,10 @@ is( $db->length(), 0, "After pop() on empty array, length is still 0" ); is( $db->shift, undef, "shift on an empty array returns undef" ); is( $db->length(), 0, "After shift() on empty array, length is still 0" ); -TODO: { - local $TODO = "unshift returns the number of elements in the array"; - is( $db->unshift( 1, 2, 3 ), 3, "unshift returns the number of elements in the array" ); - is( $db->unshift( 1, 2, 3 ), 6, "unshift returns the number of elements in the array" ); - is( $db->push( 1, 2, 3 ), 9, "unshift returns the number of elements in the array" ); -} +is( $db->unshift( 1, 2, 3 ), 3, "unshift returns the number of elements in the array" ); +is( $db->unshift( 1, 2, 3 ), 6, "unshift returns the number of elements in the array" ); +is( $db->push( 1, 2, 3 ), 9, "push returns the number of elements in the array" ); + is( $db->length(), 9, "After unshift and push on empty array, length is now 9" ); $db->clear;