r14213@rob-kinyons-computer (orig r8080): rkinyon | 2006-11-17 20:47:50 -0500
[dbsrgits/DBM-Deep.git] / t / 31_references.t
1 ##
2 # DBM::Deep Test
3 ##
4 use strict;
5 use Test::More tests => 16;
6 use Test::Exception;
7 use t::common qw( new_fh );
8
9 use_ok( 'DBM::Deep' );
10
11 my ($fh, $filename) = new_fh();
12 my $db = DBM::Deep->new( $filename );
13
14 my %hash = (
15     foo => 1,
16     bar => [ 1 .. 3 ],
17     baz => { a => 42 },
18 );
19
20 $db->{hash} = \%hash;
21 isa_ok( tied(%hash), 'DBM::Deep::Hash' );
22
23 is( $db->{hash}{foo}, 1 );
24 is_deeply( $db->{hash}{bar}, [ 1 .. 3 ] );
25 is_deeply( $db->{hash}{baz}, { a => 42 } );
26
27 $hash{foo} = 2;
28 is( $db->{hash}{foo}, 2 );
29
30 $hash{bar}[1] = 90;
31 is( $db->{hash}{bar}[1], 90 );
32
33 $hash{baz}{b} = 33;
34 is( $db->{hash}{baz}{b}, 33 );
35
36 my @array = (
37     1, [ 1 .. 3 ], { a => 42 },
38 );
39
40 $db->{array} = \@array;
41 isa_ok( tied(@array), 'DBM::Deep::Array' );
42
43 is( $db->{array}[0], 1 );
44 is_deeply( $db->{array}[1], [ 1 .. 3 ] );
45 is_deeply( $db->{array}[2], { a => 42 } );
46
47 $array[0] = 2;
48 is( $db->{array}[0], 2 );
49
50 $array[1][2] = 9;
51 is( $db->{array}[1][2], 9 );
52
53 $array[2]{b} = 'floober';
54 is( $db->{array}[2]{b}, 'floober' );
55
56 my %hash2 = ( abc => [ 1 .. 3 ] );
57 $array[3] = \%hash2;
58 SKIP: {
59     skip "Internal references are not supported right now", 1;
60     $hash2{ def } = \%hash;
61
62     is( $array[3]{def}{foo}, 2 );
63 }