Minor fixes, including removing the ==2/1 from add_bucket()
[dbsrgits/DBM-Deep.git] / t / 26_scalar_ref.t
CommitLineData
a8026397 1use strict;
2
eea0d863 3use Test::More tests => 10;
4use Test::Exception;
fde3db1a 5use t::common qw( new_fh );
a8026397 6
7use_ok( 'DBM::Deep' );
8
fde3db1a 9my ($fh, $filename) = new_fh();
2a81bf9e 10
eea0d863 11my $x = 25;
a8026397 12{
2a81bf9e 13 my $db = DBM::Deep->new( $filename );
a8026397 14
eea0d863 15 throws_ok {
16 $db->{scalarref} = \$x;
86867f3a 17 } qr/Storage of references of type 'SCALAR' is not supported/,
eea0d863 18 'Storage of scalar refs not supported';
a8026397 19
eea0d863 20 throws_ok {
21 $db->{scalarref} = \\$x;
86867f3a 22 } qr/Storage of references of type 'REF' is not supported/,
eea0d863 23 'Storage of ref refs not supported';
24
25 throws_ok {
26 $db->{scalarref} = sub { 1 };
86867f3a 27 } qr/Storage of references of type 'CODE' is not supported/,
eea0d863 28 'Storage of code refs not supported';
29
30 throws_ok {
31 $db->{scalarref} = $db->_get_self->_fh;
86867f3a 32 } qr/Storage of references of type 'GLOB' is not supported/,
eea0d863 33 'Storage of glob refs not supported';
34
35 $db->{scalar} = $x;
a8026397 36 TODO: {
eea0d863 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" );
a8026397 43 }
44}
45
46{
2a81bf9e 47 my $db = DBM::Deep->new( $filename );
a8026397 48
a8026397 49 is( $db->{scalar}, $x, "Scalar retrieved ok" );
50 TODO: {
eea0d863 51 todo_skip "Refs to DBM::Deep objects aren't implemented yet", 2;
a8026397 52 is( ${$db->{scalarref}}, 30, "Scalarref retrieved ok" );
eea0d863 53 is( ${$db->{selfref}}, 26, "Scalarref to stored scalar retrieved ok" );
a8026397 54 }
55}