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