Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
68f943b3 |
5 | use Test::More tests => 6; |
a3e62809 |
6 | use Test::Deep; |
fde3db1a |
7 | use t::common qw( new_fh ); |
ffed8b01 |
8 | |
9 | use_ok( 'DBM::Deep' ); |
10 | |
a3e62809 |
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", |
68f943b3 |
18 | subkey3 => bless( { |
19 | sub_obj => bless([ |
20 | bless([], 'Foo'), |
21 | ], 'Foo'), |
22 | sub_obj2 => bless([], 'Foo'), |
23 | }, 'Foo' ), |
a3e62809 |
24 | }, |
25 | ); |
26 | |
68f943b3 |
27 | my ($fh, $filename) = new_fh(); |
28 | my $db = DBM::Deep->new({ |
29 | file => $filename, |
45f047f8 |
30 | fh => $fh, |
68f943b3 |
31 | autobless => 1, |
32 | }); |
ffed8b01 |
33 | |
68f943b3 |
34 | ## |
35 | # Create structure in DB |
36 | ## |
e00d0eb3 |
37 | $db->import( \%struct ); |
a3e62809 |
38 | |
68f943b3 |
39 | ## |
40 | # Export entire thing |
41 | ## |
42 | my $compare = $db->export(); |
a3e62809 |
43 | |
44 | cmp_deeply( |
45 | $compare, |
46 | { |
2a81bf9e |
47 | key1 => "value1", |
48 | key2 => "value2", |
49 | array1 => [ "elem0", "elem1", "elem2", { foo => 'bar' }, [ 5 ] ], |
50 | hash1 => { |
51 | subkey1 => "subvalue1", |
52 | subkey2 => "subvalue2", |
68f943b3 |
53 | subkey3 => bless( { |
54 | sub_obj => bless([ |
55 | bless([], 'Foo'), |
56 | ], 'Foo'), |
57 | sub_obj2 => bless([], 'Foo'), |
58 | }, 'Foo' ), |
a3e62809 |
59 | }, |
60 | }, |
61 | "Everything matches", |
ffed8b01 |
62 | ); |
68f943b3 |
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' ); |