Added tests for storing tied stuff
[dbsrgits/DBM-Deep.git] / t / 04_array.t
index 04a62bc..d5e5138 100644 (file)
@@ -2,22 +2,20 @@
 # DBM::Deep Test
 ##
 use strict;
-use Test::More tests => 99;
+use Test::More tests => 107;
 use Test::Exception;
+use File::Temp qw( tempfile tempdir );
+use Fcntl qw( :flock );
 
 use_ok( 'DBM::Deep' );
 
-##
-# basic file open
-##
-unlink "t/test.db";
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+flock $fh, LOCK_UN;
 my $db = DBM::Deep->new(
-       file => "t/test.db",
+       file => $filename,
        type => DBM::Deep->TYPE_ARRAY
 );
-if ($db->error()) {
-       die "ERROR: " . $db->error();
-}
 
 TODO: {
     local $TODO = "How is this test ever supposed to pass?";
@@ -58,7 +56,10 @@ is( $db->[-2], $db->[3], "-2nd index is 3rd index" );
 is( $db->[-3], $db->[2], "-3rd index is 2nd index" );
 is( $db->[-4], $db->[1], "-4th index is 1st index" );
 is( $db->[-5], $db->[0], "-5th index is 0th index" );
-is( $db->[-6], undef, "-6th index is undef" );
+
+# This is for Perls older than 5.8.0 because of is()'s prototype
+{ my $v = $db->[-6]; is( $v, undef, "-6th index is undef" ); }
+
 is( $db->length, 5, "... and we have five elements after abortive -6 index lookup" );
 
 $db->[-1] = 'elem4.1';
@@ -189,10 +190,21 @@ is($db->[0], "elem first");
 is($db->[1], "middle ABC");
 is($db->[2], "elem last");
 
-# These tests verify that the hash methods cannot be called on arraytypes.
-# They will be removed once the ARRAY and HASH types are refactored into their own classes.
+@returned = $db->splice( 1 );
+is($db->length(), 1);
+is($db->[0], "elem first");
+is($returned[0], "middle ABC");
+is($returned[1], "elem last");
+
+$db->push( @returned );
+
+@returned = $db->splice( 1, -1 );
+is($db->length(), 2);
+is($db->[0], "elem first");
+is($db->[1], "elem last");
+is($returned[0], "middle ABC");
 
 $db->[0] = [ 1 .. 3 ];
 $db->[1] = { a => 'foo' };
-is( $db->[0]->length, 3, "Reuse of same space with array successful" );
 is( $db->[1]->fetch('a'), 'foo', "Reuse of same space with hash successful" );
+is( $db->[0]->length, 3, "Reuse of same space with array successful" );