Standardized test incantations
[dbsrgits/DBM-Deep.git] / t / 18_export.t
1 ##
2 # DBM::Deep Test
3 ##
4 use strict;
5 use Test::More tests => 6;
6 use Test::Deep;
7 use t::common qw( new_fh );
8
9 use_ok( 'DBM::Deep' );
10
11 my %struct = (
12     key1 => "value1",
13     key2 => "value2",
14     array1 => [ "elem0", "elem1", "elem2", { foo => 'bar' }, [ 5 ] ],
15     hash1 => {
16         subkey1 => "subvalue1",
17         subkey2 => "subvalue2",
18         subkey3 => bless( {
19             sub_obj => bless([
20                 bless([], 'Foo'),
21             ], 'Foo'),
22             sub_obj2 => bless([], 'Foo'),
23         }, 'Foo' ),
24     },
25 );
26
27 my ($fh, $filename) = new_fh();
28 my $db = DBM::Deep->new({
29     file      => $filename,
30     autobless => 1,
31 });
32
33 ##
34 # Create structure in DB
35 ##
36 $db->import( \%struct );
37
38 ##
39 # Export entire thing
40 ##
41 my $compare = $db->export();
42
43 cmp_deeply(
44     $compare,
45     {
46         key1 => "value1",
47         key2 => "value2",
48         array1 => [ "elem0", "elem1", "elem2", { foo => 'bar' }, [ 5 ] ],
49         hash1 => {
50             subkey1 => "subvalue1",
51             subkey2 => "subvalue2",
52             subkey3 => bless( {
53                 sub_obj => bless([
54                     bless([], 'Foo'),
55                 ], 'Foo'),
56                 sub_obj2 => bless([], 'Foo'),
57             }, 'Foo' ),
58         },
59     },
60     "Everything matches",
61 );
62
63 isa_ok( tied(%{$db->{hash1}{subkey3}})->export, 'Foo' );
64 isa_ok( tied(@{$db->{hash1}{subkey3}{sub_obj}})->export, 'Foo' );
65 isa_ok( tied(@{$db->{hash1}{subkey3}{sub_obj}[0]})->export, 'Foo' );
66 isa_ok( tied(@{$db->{hash1}{subkey3}{sub_obj2}})->export, 'Foo' );