r11685@rob-kinyons-powerbook58: rob | 2006-04-29 10:50:27 -0400
[dbsrgits/DBM-Deep.git] / t / 18_export.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
68f943b3 5use Test::More tests => 6;
a3e62809 6use Test::Deep;
fde3db1a 7use t::common qw( new_fh );
ffed8b01 8
9use_ok( 'DBM::Deep' );
10
a3e62809 11my %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 27my ($fh, $filename) = new_fh();
28my $db = DBM::Deep->new({
29 file => $filename,
30 autobless => 1,
31});
ffed8b01 32
68f943b3 33##
34# Create structure in DB
35##
36$db->import( %struct );
a3e62809 37
68f943b3 38##
39# Export entire thing
40##
41my $compare = $db->export();
a3e62809 42
43cmp_deeply(
44 $compare,
45 {
2a81bf9e 46 key1 => "value1",
47 key2 => "value2",
48 array1 => [ "elem0", "elem1", "elem2", { foo => 'bar' }, [ 5 ] ],
49 hash1 => {
50 subkey1 => "subvalue1",
51 subkey2 => "subvalue2",
68f943b3 52 subkey3 => bless( {
53 sub_obj => bless([
54 bless([], 'Foo'),
55 ], 'Foo'),
56 sub_obj2 => bless([], 'Foo'),
57 }, 'Foo' ),
a3e62809 58 },
59 },
60 "Everything matches",
ffed8b01 61);
68f943b3 62
63isa_ok( tied(%{$db->{hash1}{subkey3}})->export, 'Foo' );
64isa_ok( tied(@{$db->{hash1}{subkey3}{sub_obj}})->export, 'Foo' );
65isa_ok( tied(@{$db->{hash1}{subkey3}{sub_obj}[0]})->export, 'Foo' );
66isa_ok( tied(@{$db->{hash1}{subkey3}{sub_obj2}})->export, 'Foo' );