X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F18_export.t;h=1ff8051fc57d320accab2027450114f426208c68;hb=5c0756fcb3b5c7ca76c52be6c7c9d78841e5d57b;hp=aae08e647737ada3c76c68c33a47570248a00f5d;hpb=075910edd08e4ee071dcf8b0abbde2ac00cc0daa;p=dbsrgits%2FDBM-Deep.git diff --git a/t/18_export.t b/t/18_export.t index aae08e6..1ff8051 100644 --- a/t/18_export.t +++ b/t/18_export.t @@ -2,53 +2,66 @@ # 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 %struct = ( + key1 => "value1", + key2 => "value2", + array1 => [ "elem0", "elem1", "elem2", { foo => 'bar' }, [ 5 ] ], + hash1 => { + subkey1 => "subvalue1", + subkey2 => "subvalue2", + subkey3 => bless( { + sub_obj => bless([ + bless([], 'Foo'), + ], 'Foo'), + sub_obj2 => bless([], 'Foo'), + }, 'Foo' ), + }, +); + +my ($fh, $filename) = new_fh(); +my $db = DBM::Deep->new({ + file => $filename, + fh => $fh, + autobless => 1, +}); ## # Create structure in DB ## -$db->import( - key1 => "value1", - key2 => "value2", - array1 => [ "elem0", "elem1", "elem2" ], - hash1 => { - subkey1 => "subvalue1", - subkey2 => "subvalue2" - } -); +$db->import( \%struct ); ## # Export entire thing ## -my $struct = $db->export(); +my $compare = $db->export(); -## -# close, delete file -## -undef $db; -unlink "t/test.db"; - -## -# Make sure everything is here, outside DB -## -ok( - ($struct->{key1} eq "value1") && - ($struct->{key2} eq "value2") && - ($struct->{array1} && - ($struct->{array1}->[0] eq "elem0") && - ($struct->{array1}->[1] eq "elem1") && - ($struct->{array1}->[2] eq "elem2") - ) && - ($struct->{hash1} && - ($struct->{hash1}->{subkey1} eq "subvalue1") && - ($struct->{hash1}->{subkey2} eq "subvalue2") - ) +cmp_deeply( + $compare, + { + key1 => "value1", + key2 => "value2", + array1 => [ "elem0", "elem1", "elem2", { foo => 'bar' }, [ 5 ] ], + hash1 => { + subkey1 => "subvalue1", + subkey2 => "subvalue2", + subkey3 => bless( { + sub_obj => bless([ + bless([], 'Foo'), + ], 'Foo'), + sub_obj2 => bless([], 'Foo'), + }, 'Foo' ), + }, + }, + "Everything matches", ); + +isa_ok( tied(%{$db->{hash1}{subkey3}})->export, 'Foo' ); +isa_ok( tied(@{$db->{hash1}{subkey3}{sub_obj}})->export, 'Foo' ); +isa_ok( tied(@{$db->{hash1}{subkey3}{sub_obj}[0]})->export, 'Foo' ); +isa_ok( tied(@{$db->{hash1}{subkey3}{sub_obj2}})->export, 'Foo' );