Fixed immediate dependence on DBI
[dbsrgits/DBM-Deep.git] / t / 26_scalar_ref.t
1 use strict;
2 use warnings FATAL => 'all';
3
4 use Test::More;
5 use Test::Exception;
6 use t::common qw( new_dbm new_fh );
7
8 use_ok( 'DBM::Deep' );
9
10 my $x = 25;
11 my $dbm_factory = new_dbm();
12 while ( 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         }
46     }
47
48     {
49         my $db = $dbm_maker->();
50
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         }
57     }
58 }
59
60 done_testing;