Further changes
[dbsrgits/DBM-Deep.git] / t / 22_internal_copy.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
5use Test::More tests => 12;
6
7use_ok( 'DBM::Deep' );
8
9unlink "t/test.db";
10my $db = DBM::Deep->new( "t/test.db" );
11if ($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
28is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" );
29is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" );
30
31$db->{copy} = $db->{hash1};
32
33is( $db->{copy}{subkey1}, 'subvalue1', "Value copied correctly" );
34is( $db->{copy}{subkey2}, 'subvalue2', "Value copied correctly" );
35
36$db->{copy}{subkey1} = "another value";
37is( $db->{copy}{subkey1}, 'another value', "New value is set correctly" );
38is( $db->{hash1}{subkey1}, 'another value', "Old value is set to the new one" );
39
40is( scalar(keys %{$db->{hash1}}), 2, "Start with 2 keys in the original" );
41is( scalar(keys %{$db->{copy}}), 2, "Start with 2 keys in the copy" );
42
43delete $db->{copy}{subkey2};
44
45is( scalar(keys %{$db->{copy}}), 1, "Now only have 1 key in the copy" );
46is( scalar(keys %{$db->{hash1}}), 1, "... and only 1 key in the original" );
47
48$db->{copy} = $db->{hash2};
49is( $db->{copy}{subkey3}, 'subvalue3', "After the second copy, we're still good" );