r11687@rob-kinyons-powerbook58: rob | 2006-04-29 23:33:57 -0400
[dbsrgits/DBM-Deep.git] / t / 17_import.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
8dee06cd 5use Test::More tests => 6;
a3e62809 6use Test::Deep;
fde3db1a 7use t::common qw( new_fh );
ffed8b01 8
9use_ok( 'DBM::Deep' );
10
fde3db1a 11my ($fh, $filename) = new_fh();
a3e62809 12my $db = DBM::Deep->new({
13 file => $filename,
14 autobless => 1,
15});
ffed8b01 16
17##
18# Create structure in memory
19##
20my $struct = {
21 key1 => "value1",
22 key2 => "value2",
23 array1 => [ "elem0", "elem1", "elem2" ],
24 hash1 => {
25 subkey1 => "subvalue1",
a3e62809 26 subkey2 => "subvalue2",
27 subkey3 => bless( {}, 'Foo' ),
ffed8b01 28 }
29};
30
31##
32# Import entire thing
33##
34$db->import( $struct );
ffed8b01 35
a3e62809 36cmp_deeply(
37 $db,
7faa3b17 38 noclass({
a3e62809 39 key1 => 'value1',
40 key2 => 'value2',
41 array1 => [ 'elem0', 'elem1', 'elem2', ],
42 hash1 => {
43 subkey1 => "subvalue1",
44 subkey2 => "subvalue2",
17ca2cc9 45 subkey3 => useclass( bless {}, 'Foo' ),
a3e62809 46 },
7faa3b17 47 }),
a3e62809 48 "Everything matches",
ffed8b01 49);
8dee06cd 50
51$struct->{foo} = 'bar';
52is( $struct->{foo}, 'bar', "\$struct has foo and it's 'bar'" );
53ok( !exists $db->{foo}, "\$db doesn't have the 'foo' key, so \$struct is not tied" );
54
55$struct->{hash1}->{foo} = 'bar';
56is( $struct->{hash1}->{foo}, 'bar', "\$struct->{hash1} has foo and it's 'bar'" );
57ok( !exists $db->{hash1}->{foo}, "\$db->{hash1} doesn't have the 'foo' key, so \$struct->{hash1} is not tied" );
12b96196 58
59__END__
60
61Need to add tests for:
62 - Failure case (have something tied or a glob or something like that)
63 - Where we already have $db->{hash1} to make sure that it's not overwritten