X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F17_import.t;h=eeb868822fd020330e8e7ca304b1dfbd6796b958;hb=b9b85d473bba31fe1f875563f9076853dc256dca;hp=5f3e275dc7e8c34e86a31bbdd20472fe30aaf4e7;hpb=075910edd08e4ee071dcf8b0abbde2ac00cc0daa;p=dbsrgits%2FDBM-Deep.git diff --git a/t/17_import.t b/t/17_import.t index 5f3e275..eeb8688 100644 --- a/t/17_import.t +++ b/t/17_import.t @@ -2,15 +2,17 @@ # DBM::Deep Test ## use strict; -use Test::More tests => 2; +use Test::More tests => 6; +use Test::Deep; +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({ + file => $filename, + autobless => 1, +}); ## # Create structure in memory @@ -21,7 +23,8 @@ my $struct = { array1 => [ "elem0", "elem1", "elem2" ], hash1 => { subkey1 => "subvalue1", - subkey2 => "subvalue2" + subkey2 => "subvalue2", + subkey3 => bless( {}, 'Foo' ), } }; @@ -29,21 +32,32 @@ my $struct = { # Import entire thing ## $db->import( $struct ); -undef $struct; -## -# Make sure everything is there -## -ok( - ($db->{key1} eq "value1") && - ($db->{key2} eq "value2") && - ($db->{array1} && - ($db->{array1}->[0] eq "elem0") && - ($db->{array1}->[1] eq "elem1") && - ($db->{array1}->[2] eq "elem2") - ) && - ($db->{hash1} && - ($db->{hash1}->{subkey1} eq "subvalue1") && - ($db->{hash1}->{subkey2} eq "subvalue2") - ) +cmp_deeply( + $db, + noclass({ + key1 => 'value1', + key2 => 'value2', + array1 => [ 'elem0', 'elem1', 'elem2', ], + hash1 => { + subkey1 => "subvalue1", + subkey2 => "subvalue2", + subkey3 => useclass( bless {}, 'Foo' ), + }, + }), + "Everything matches", ); + +$struct->{foo} = 'bar'; +is( $struct->{foo}, 'bar', "\$struct has foo and it's 'bar'" ); +ok( !exists $db->{foo}, "\$db doesn't have the 'foo' key, so \$struct is not tied" ); + +$struct->{hash1}->{foo} = 'bar'; +is( $struct->{hash1}->{foo}, 'bar', "\$struct->{hash1} has foo and it's 'bar'" ); +ok( !exists $db->{hash1}->{foo}, "\$db->{hash1} doesn't have the 'foo' key, so \$struct->{hash1} is not tied" ); + +__END__ + +Need to add tests for: + - Failure case (have something tied or a glob or something like that) + - Where we already have $db->{hash1} to make sure that it's not overwritten