Array tests now pass
[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 {
6e6789b0 31 $db->{scalarref} = $fh;
86867f3a 32 } qr/Storage of references of type 'GLOB' is not supported/,
eea0d863 33 'Storage of glob refs not supported';
34
00d9bd0b 35 warn "\n1: " . $db->_engine->_dump_file;
eea0d863 36 $db->{scalar} = $x;
00d9bd0b 37 warn "\n2: " . $db->_engine->_dump_file;
a8026397 38 TODO: {
eea0d863 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" );
a8026397 45 }
00d9bd0b 46
47 warn $db->_engine->_dump_file;
a8026397 48}
49
50{
2a81bf9e 51 my $db = DBM::Deep->new( $filename );
a8026397 52
a8026397 53 is( $db->{scalar}, $x, "Scalar retrieved ok" );
54 TODO: {
eea0d863 55 todo_skip "Refs to DBM::Deep objects aren't implemented yet", 2;
a8026397 56 is( ${$db->{scalarref}}, 30, "Scalarref retrieved ok" );
eea0d863 57 is( ${$db->{selfref}}, 26, "Scalarref to stored scalar retrieved ok" );
a8026397 58 }
59}