More transaction tests and reorg of tests
[dbsrgits/DBM-Deep.git] / t / 02_hash.t
index 3f1969f..d4a52ef 100644 (file)
@@ -2,16 +2,14 @@
 # DBM::Deep Test
 ##
 use strict;
-use Test::More tests => 44;
+use Test::More tests => 32;
 use Test::Exception;
+use t::common qw( new_fh );
 
 use_ok( 'DBM::Deep' );
 
-unlink "t/test.db";
-my $db = DBM::Deep->new( "t/test.db" );
-if ($db->error()) {
-       die "ERROR: " . $db->error();
-}
+my ($fh, $filename) = new_fh();
+my $db = DBM::Deep->new( $filename );
 
 ##
 # put/get key
@@ -65,11 +63,9 @@ is( $temphash->{key3}, 'value3', "Third key copied successfully" );
 ##
 # delete keys
 ##
-TODO: {
-    local $TODO = "Delete should return the deleted value";
-    is( delete $db->{key1}, 'value1', "delete through tied inteface works" );
-    is( $db->delete("key2"), undef, "delete through OO inteface works" );
-}
+is( delete $db->{key2}, undef, "delete through tied inteface works" );
+is( $db->delete("key1"), 'value1', "delete through OO inteface works" );
+is( $db->{key3}, 'value3', "The other key is still there" );
 
 is( scalar keys %$db, 1, "After deleting two keys, 1 remains" );
 
@@ -97,10 +93,7 @@ is( $db->get("key1"), "value222222222222222222222222", "We set a value before cl
 # Make sure DB still works after closing / opening
 ##
 undef $db;
-$db = DBM::Deep->new( "t/test.db" );
-if ($db->error()) {
-       die "ERROR: " . $db->error();
-}
+$db = DBM::Deep->new( $filename );
 is( $db->get("key1"), "value222222222222222222222222", "The value we set is still there after closure" );
 
 ##
@@ -124,61 +117,8 @@ ok(
     ,"keys() still works if you replace long values with shorter ones"
 );
 
-# These tests verify that the array methods cannot be called on hashtypes.
-# They will be removed once the ARRAY and HASH types are refactored into their own classes.
-
-throws_ok {
-    $db->splice();
-} qr/SPLICE method only supported for arrays/, "Cannot call splice on a hash type";
-
-throws_ok {
-    $db->SPLICE();
-} qr/SPLICE method only supported for arrays/, "Cannot call SPLICE on a hash type";
-
-throws_ok {
-    $db->length();
-} qr/FETCHSIZE method only supported for arrays/, "Cannot call length on a hash type";
-
-throws_ok {
-    $db->FETCHSIZE();
-} qr/FETCHSIZE method only supported for arrays/, "Cannot call FETCHSIZE on a hash type";
-
-throws_ok {
-    $db->STORESIZE();
-} qr/STORESIZE method only supported for arrays/, "Cannot call STORESIZE on a hash type";
-
-throws_ok {
-    $db->POP();
-} qr/POP method only supported for arrays/, "Cannot call POP on a hash type";
-
-throws_ok {
-    $db->pop();
-} qr/POP method only supported for arrays/, "Cannot call pop on a hash type";
-
-throws_ok {
-    $db->PUSH();
-} qr/PUSH method only supported for arrays/, "Cannot call PUSH on a hash type";
-
-throws_ok {
-    $db->push();
-} qr/PUSH method only supported for arrays/, "Cannot call push on a hash type";
-
-throws_ok {
-    $db->SHIFT();
-} qr/SHIFT method only supported for arrays/, "Cannot call SHIFT on a hash type";
-
-throws_ok {
-    $db->shift();
-} qr/SHIFT method only supported for arrays/, "Cannot call shift on a hash type";
-
-throws_ok {
-    $db->UNSHIFT();
-} qr/UNSHIFT method only supported for arrays/, "Cannot call UNSHIFT on a hash type";
-
-throws_ok {
-    $db->unshift();
-} qr/UNSHIFT method only supported for arrays/, "Cannot call unshift on a hash type";
+# Test autovivification
 
-ok( $db->error, "We have an error ..." );
-$db->clear_error();
-ok( !$db->error(), "... and we cleared the error" );
+$db->{unknown}{bar} = 1;
+ok( $db->{unknown} );
+cmp_ok( $db->{unknown}{bar}, '==', 1 );