Final fixes before releasing last developer release
[dbsrgits/DBM-Deep.git] / t / 31_references.t
CommitLineData
019ab3a1 1use strict;
0e3e3555 2use warnings FATAL => 'all';
888453b9 3
0e3e3555 4use Test::More;
c57b19c6 5use Test::Deep;
019ab3a1 6use Test::Exception;
0e3e3555 7use t::common qw( new_dbm );
019ab3a1 8
9use_ok( 'DBM::Deep' );
0e3e3555 10my $dbm_factory = new_dbm();
11while ( my $dbm_maker = $dbm_factory->() ) {
12 my $db = $dbm_maker->();
019ab3a1 13
0e3e3555 14 my %hash = (
15 foo => 1,
16 bar => [ 1 .. 3 ],
17 baz => { a => 42 },
18 );
019ab3a1 19
0e3e3555 20 $db->{hash} = \%hash;
21 isa_ok( tied(%hash), 'DBM::Deep::Hash' );
019ab3a1 22
0e3e3555 23 is( $db->{hash}{foo}, 1 );
24 cmp_deeply( $db->{hash}{bar}, noclass([ 1 .. 3 ]) );
25 cmp_deeply( $db->{hash}{baz}, noclass({ a => 42 }) );
019ab3a1 26
0e3e3555 27 $hash{foo} = 2;
28 is( $db->{hash}{foo}, 2 );
019ab3a1 29
0e3e3555 30 $hash{bar}[1] = 90;
31 is( $db->{hash}{bar}[1], 90 );
c6ea6b6c 32
0e3e3555 33 $hash{baz}{b} = 33;
34 is( $db->{hash}{baz}{b}, 33 );
c6ea6b6c 35
0e3e3555 36 my @array = (
37 1, [ 1 .. 3 ], { a => 42 },
38 );
c6ea6b6c 39
0e3e3555 40 $db->{array} = \@array;
41 isa_ok( tied(@array), 'DBM::Deep::Array' );
c6ea6b6c 42
0e3e3555 43 is( $db->{array}[0], 1 );
44 cmp_deeply( $db->{array}[1], noclass([ 1 .. 3 ]) );
45 cmp_deeply( $db->{array}[2], noclass({ a => 42 }) );
c6ea6b6c 46
0e3e3555 47 $array[0] = 2;
48 is( $db->{array}[0], 2 );
c6ea6b6c 49
0e3e3555 50 $array[1][2] = 9;
51 is( $db->{array}[1][2], 9 );
c6ea6b6c 52
0e3e3555 53 $array[2]{b} = 'floober';
54 is( $db->{array}[2]{b}, 'floober' );
c6ea6b6c 55
0e3e3555 56 my %hash2 = ( abc => [ 1 .. 3 ] );
57 $array[3] = \%hash2;
9d4fa373 58
0e3e3555 59 $hash2{ def } = \%hash;
60 is( $array[3]{def}{foo}, 2 );
61}
9d4fa373 62
0e3e3555 63done_testing;