Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
5 | use Test::More tests => 12; |
6 | |
7 | use_ok( 'DBM::Deep' ); |
8 | |
9 | unlink "t/test.db"; |
10 | my $db = DBM::Deep->new( "t/test.db" ); |
11 | if ($db->error()) { |
12 | die "ERROR: " . $db->error(); |
13 | } |
14 | |
15 | ## |
16 | # Create structure in $db |
17 | ## |
18 | $db->import( |
19 | hash1 => { |
20 | subkey1 => "subvalue1", |
21 | subkey2 => "subvalue2", |
22 | }, |
23 | hash2 => { |
24 | subkey3 => 'subvalue3', |
25 | }, |
26 | ); |
27 | |
28 | is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" ); |
29 | is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" ); |
30 | |
31 | $db->{copy} = $db->{hash1}; |
32 | |
33 | is( $db->{copy}{subkey1}, 'subvalue1', "Value copied correctly" ); |
34 | is( $db->{copy}{subkey2}, 'subvalue2', "Value copied correctly" ); |
35 | |
36 | $db->{copy}{subkey1} = "another value"; |
37 | is( $db->{copy}{subkey1}, 'another value', "New value is set correctly" ); |
38 | is( $db->{hash1}{subkey1}, 'another value', "Old value is set to the new one" ); |
39 | |
40 | is( scalar(keys %{$db->{hash1}}), 2, "Start with 2 keys in the original" ); |
41 | is( scalar(keys %{$db->{copy}}), 2, "Start with 2 keys in the copy" ); |
42 | |
43 | delete $db->{copy}{subkey2}; |
44 | |
45 | is( scalar(keys %{$db->{copy}}), 1, "Now only have 1 key in the copy" ); |
46 | is( scalar(keys %{$db->{hash1}}), 1, "... and only 1 key in the original" ); |
47 | |
48 | $db->{copy} = $db->{hash2}; |
49 | is( $db->{copy}{subkey3}, 'subvalue3', "After the second copy, we're still good" ); |