Refactored to _descend to fix the recursion bug
[dbsrgits/DBM-Deep.git] / t / 26_scalar_ref.t
CommitLineData
a8026397 1use strict;
0e3e3555 2use warnings FATAL => 'all';
a8026397 3
0e3e3555 4use Test::More;
eea0d863 5use Test::Exception;
0e3e3555 6use t::common qw( new_dbm new_fh );
a8026397 7
8use_ok( 'DBM::Deep' );
9
eea0d863 10my $x = 25;
0e3e3555 11my $dbm_factory = new_dbm();
12while ( my $dbm_maker = $dbm_factory->() ) {
13 {
14 my $db = $dbm_maker->();
15
16 throws_ok {
17 $db->{scalarref} = \$x;
18 } qr/Storage of references of type 'SCALAR' is not supported/,
19 'Storage of scalar refs not supported';
20
21 throws_ok {
22 $db->{scalarref} = \\$x;
23 } qr/Storage of references of type 'REF' is not supported/,
24 'Storage of ref refs not supported';
25
26 throws_ok {
27 $db->{scalarref} = sub { 1 };
28 } qr/Storage of references of type 'CODE' is not supported/,
29 'Storage of code refs not supported';
30
31 throws_ok {
32 my ($fh, $filename) = new_fh;
33 $db->{scalarref} = $fh;
34 } qr/Storage of references of type 'GLOB' is not supported/,
35 'Storage of glob refs not supported';
36
37 $db->{scalar} = $x;
38 TODO: {
39 todo_skip "Refs to DBM::Deep objects aren't implemented yet", 2;
40 lives_ok {
41 $db->{selfref} = \$db->{scalar};
42 } "Refs to DBM::Deep objects are ok";
43
44 is( ${$db->{selfref}}, $x, "A ref to a DBM::Deep object is ok" );
45 }
a8026397 46 }
a8026397 47
0e3e3555 48 {
49 my $db = $dbm_maker->();
a8026397 50
0e3e3555 51 is( $db->{scalar}, $x, "Scalar retrieved ok" );
52 TODO: {
53 todo_skip "Refs to DBM::Deep objects aren't implemented yet", 2;
54 is( ${$db->{scalarref}}, 30, "Scalarref retrieved ok" );
55 is( ${$db->{selfref}}, 26, "Scalarref to stored scalar retrieved ok" );
56 }
a8026397 57 }
58}
0e3e3555 59
60done_testing;