X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F31_references.t;h=03d73d1bf8c801d3abb83018b99b632538c6d0cb;hb=0e3e35555b9d0f781548d4d383f601ba69837310;hp=af9bc301acab7c7db4ebe3f55572a946b6f4d37d;hpb=4f0f6fff0474a896cad8bbb80d8c0ccce3d87bf9;p=dbsrgits%2FDBM-Deep.git diff --git a/t/31_references.t b/t/31_references.t index af9bc30..03d73d1 100644 --- a/t/31_references.t +++ b/t/31_references.t @@ -1,59 +1,63 @@ use strict; +use warnings FATAL => 'all'; -use Test::More tests => 16; +use Test::More; use Test::Deep; use Test::Exception; -use t::common qw( new_fh ); +use t::common qw( new_dbm ); use_ok( 'DBM::Deep' ); +my $dbm_factory = new_dbm(); +while ( my $dbm_maker = $dbm_factory->() ) { + my $db = $dbm_maker->(); -my ($fh, $filename) = new_fh(); -my $db = DBM::Deep->new( $filename ); + my %hash = ( + foo => 1, + bar => [ 1 .. 3 ], + baz => { a => 42 }, + ); -my %hash = ( - foo => 1, - bar => [ 1 .. 3 ], - baz => { a => 42 }, -); + $db->{hash} = \%hash; + isa_ok( tied(%hash), 'DBM::Deep::Hash' ); -$db->{hash} = \%hash; -isa_ok( tied(%hash), 'DBM::Deep::Hash' ); + is( $db->{hash}{foo}, 1 ); + cmp_deeply( $db->{hash}{bar}, noclass([ 1 .. 3 ]) ); + cmp_deeply( $db->{hash}{baz}, noclass({ a => 42 }) ); -is( $db->{hash}{foo}, 1 ); -cmp_deeply( $db->{hash}{bar}, noclass([ 1 .. 3 ]) ); -cmp_deeply( $db->{hash}{baz}, noclass({ a => 42 }) ); + $hash{foo} = 2; + is( $db->{hash}{foo}, 2 ); -$hash{foo} = 2; -is( $db->{hash}{foo}, 2 ); + $hash{bar}[1] = 90; + is( $db->{hash}{bar}[1], 90 ); -$hash{bar}[1] = 90; -is( $db->{hash}{bar}[1], 90 ); + $hash{baz}{b} = 33; + is( $db->{hash}{baz}{b}, 33 ); -$hash{baz}{b} = 33; -is( $db->{hash}{baz}{b}, 33 ); + my @array = ( + 1, [ 1 .. 3 ], { a => 42 }, + ); -my @array = ( - 1, [ 1 .. 3 ], { a => 42 }, -); + $db->{array} = \@array; + isa_ok( tied(@array), 'DBM::Deep::Array' ); -$db->{array} = \@array; -isa_ok( tied(@array), 'DBM::Deep::Array' ); + is( $db->{array}[0], 1 ); + cmp_deeply( $db->{array}[1], noclass([ 1 .. 3 ]) ); + cmp_deeply( $db->{array}[2], noclass({ a => 42 }) ); -is( $db->{array}[0], 1 ); -cmp_deeply( $db->{array}[1], noclass([ 1 .. 3 ]) ); -cmp_deeply( $db->{array}[2], noclass({ a => 42 }) ); + $array[0] = 2; + is( $db->{array}[0], 2 ); -$array[0] = 2; -is( $db->{array}[0], 2 ); + $array[1][2] = 9; + is( $db->{array}[1][2], 9 ); -$array[1][2] = 9; -is( $db->{array}[1][2], 9 ); + $array[2]{b} = 'floober'; + is( $db->{array}[2]{b}, 'floober' ); -$array[2]{b} = 'floober'; -is( $db->{array}[2]{b}, 'floober' ); + my %hash2 = ( abc => [ 1 .. 3 ] ); + $array[3] = \%hash2; -my %hash2 = ( abc => [ 1 .. 3 ] ); -$array[3] = \%hash2; + $hash2{ def } = \%hash; + is( $array[3]{def}{foo}, 2 ); +} -$hash2{ def } = \%hash; -is( $array[3]{def}{foo}, 2 ); +done_testing;