Commit | Line | Data |
019ab3a1 |
1 | use strict; |
888453b9 |
2 | |
9d4fa373 |
3 | use Test::More tests => 16; |
c57b19c6 |
4 | use Test::Deep; |
019ab3a1 |
5 | use Test::Exception; |
fde3db1a |
6 | use t::common qw( new_fh ); |
019ab3a1 |
7 | |
8 | use_ok( 'DBM::Deep' ); |
9 | |
fde3db1a |
10 | my ($fh, $filename) = new_fh(); |
45f047f8 |
11 | my $db = DBM::Deep->new( file => $filename, fh => $fh, ); |
019ab3a1 |
12 | |
13 | my %hash = ( |
14 | foo => 1, |
15 | bar => [ 1 .. 3 ], |
16 | baz => { a => 42 }, |
17 | ); |
18 | |
19 | $db->{hash} = \%hash; |
685e40f1 |
20 | isa_ok( tied(%hash), 'DBM::Deep::Hash' ); |
019ab3a1 |
21 | |
22 | is( $db->{hash}{foo}, 1 ); |
c57b19c6 |
23 | cmp_deeply( $db->{hash}{bar}, noclass([ 1 .. 3 ]) ); |
24 | cmp_deeply( $db->{hash}{baz}, noclass({ a => 42 }) ); |
019ab3a1 |
25 | |
26 | $hash{foo} = 2; |
27 | is( $db->{hash}{foo}, 2 ); |
c6ea6b6c |
28 | |
29 | $hash{bar}[1] = 90; |
30 | is( $db->{hash}{bar}[1], 90 ); |
31 | |
32 | $hash{baz}{b} = 33; |
33 | is( $db->{hash}{baz}{b}, 33 ); |
34 | |
35 | my @array = ( |
36 | 1, [ 1 .. 3 ], { a => 42 }, |
37 | ); |
38 | |
39 | $db->{array} = \@array; |
40 | isa_ok( tied(@array), 'DBM::Deep::Array' ); |
41 | |
42 | is( $db->{array}[0], 1 ); |
c57b19c6 |
43 | cmp_deeply( $db->{array}[1], noclass([ 1 .. 3 ]) ); |
44 | cmp_deeply( $db->{array}[2], noclass({ a => 42 }) ); |
c6ea6b6c |
45 | |
46 | $array[0] = 2; |
47 | is( $db->{array}[0], 2 ); |
48 | |
49 | $array[1][2] = 9; |
50 | is( $db->{array}[1][2], 9 ); |
51 | |
52 | $array[2]{b} = 'floober'; |
53 | is( $db->{array}[2]{b}, 'floober' ); |
9d4fa373 |
54 | |
55 | my %hash2 = ( abc => [ 1 .. 3 ] ); |
56 | $array[3] = \%hash2; |
9d4fa373 |
57 | |
888453b9 |
58 | $hash2{ def } = \%hash; |
59 | is( $array[3]{def}{foo}, 2 ); |