Speed up clear()
[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     fh => $fh,
31     autobless => 1,
32 });
33
34 ##
35 # Create structure in DB
36 ##
37 $db->import( \%struct );
38
39 ##
40 # Export entire thing
41 ##
42 my $compare = $db->export();
43
44 cmp_deeply(
45     $compare,
46     {
47         key1 => "value1",
48         key2 => "value2",
49         array1 => [ "elem0", "elem1", "elem2", { foo => 'bar' }, [ 5 ] ],
50         hash1 => {
51             subkey1 => "subvalue1",
52             subkey2 => "subvalue2",
53             subkey3 => bless( {
54                 sub_obj => bless([
55                     bless([], 'Foo'),
56                 ], 'Foo'),
57                 sub_obj2 => bless([], 'Foo'),
58             }, 'Foo' ),
59         },
60     },
61     "Everything matches",
62 );
63
64 isa_ok( tied(%{$db->{hash1}{subkey3}})->export, 'Foo' );
65 isa_ok( tied(@{$db->{hash1}{subkey3}{sub_obj}})->export, 'Foo' );
66 isa_ok( tied(@{$db->{hash1}{subkey3}{sub_obj}[0]})->export, 'Foo' );
67 isa_ok( tied(@{$db->{hash1}{subkey3}{sub_obj2}})->export, 'Foo' );