r15625@rob-kinyons-computer (orig r9171): rkinyon | 2007-02-26 11:56:32 -0500
[dbsrgits/DBM-Deep.git] / t / 19_crossref.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
9d4fa373 5use Test::More tests => 6;
6use Test::Exception;
fde3db1a 7use t::common qw( new_fh );
ffed8b01 8
9use_ok( 'DBM::Deep' );
10
fde3db1a 11my ($fh2, $filename2) = new_fh();
98ac82af 12my $db2 = DBM::Deep->new( $filename2 );
13
14{
fde3db1a 15 my ($fh, $filename) = new_fh();
98ac82af 16 my $db = DBM::Deep->new( $filename );
17
18 ##
19 # Create structure in $db
20 ##
21 $db->import(
22 hash1 => {
23 subkey1 => "subvalue1",
c9cec40e 24 subkey2 => "subvalue2",
98ac82af 25 }
26 );
98ac82af 27 is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" );
28 is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" );
2120a181 29
30 # Test cross-ref nested hash accross DB objects
9d4fa373 31 throws_ok {
32 $db2->{copy} = $db->{hash1};
2120a181 33 } qr/Cannot store something that is tied\./, "cross-ref fails";
34
35 # This error text is for when internal cross-refs are implemented
36 #} qr/Cannot cross-reference\. Use export\(\) instead\./, "cross-ref fails";
37
9d4fa373 38 $db2->{copy} = $db->{hash1}->export;
98ac82af 39}
ffed8b01 40
41##
42# Make sure $db2 has copy of $db's hash structure
43##
44is( $db2->{copy}{subkey1}, 'subvalue1', "Value copied correctly" );
45is( $db2->{copy}{subkey2}, 'subvalue2', "Value copied correctly" );