X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F18_export.t;h=ddb2c14826679b3ce1e444a016bc636144576d5f;hb=67e9b86f22e8dacf29904f0163be3b23fae91074;hp=57d3975bda172221a2b20ce01f31ab71b766827e;hpb=fde3db1a5e4879bebec5ca8051caa2804d1a826e;p=dbsrgits%2FDBM-Deep.git diff --git a/t/18_export.t b/t/18_export.t index 57d3975..ddb2c14 100644 --- a/t/18_export.t +++ b/t/18_export.t @@ -1,51 +1,66 @@ -## -# DBM::Deep Test -## use strict; -use Test::More tests => 2; -use t::common qw( new_fh ); +use warnings FATAL => 'all'; + +use Test::More; +use Test::Deep; +use t::common qw( new_dbm ); use_ok( 'DBM::Deep' ); -my $struct; -{ - my ($fh, $filename) = new_fh(); - my $db = DBM::Deep->new( $filename ); +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 $dbm_factory = new_dbm( autobless => 1 ); +while ( my $dbm_maker = $dbm_factory->() ) { + my $db = $dbm_maker->(); ## # Create structure in DB ## - $db->import( - key1 => "value1", - key2 => "value2", - array1 => [ "elem0", "elem1", "elem2", { foo => 'bar' }, [ 5 ] ], - hash1 => { - subkey1 => "subvalue1", - subkey2 => "subvalue2", - } - ); + $db->import( \%struct ); ## # Export entire thing ## - $struct = $db->export(); + my $compare = $db->export(); + + 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' ); } -## -# 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->{array1}->[3]{foo} eq "bar") && - ($struct->{array1}->[4][0] eq "5") - ) && - ($struct->{hash1} && - ($struct->{hash1}->{subkey1} eq "subvalue1") && - ($struct->{hash1}->{subkey2} eq "subvalue2") - ) -); +done_testing;