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