Fixed naive use of {@_} in TIE*
[dbsrgits/DBM-Deep.git] / t / 20_tie.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
217fef02 5use Test::More tests => 11;
6use Test::Exception;
ffed8b01 7
217fef02 8use_ok( 'DBM::Deep' );
ffed8b01 9
10##
11# testing the various modes of opening a file
12##
13{
14 unlink "t/test.db";
15 my %hash;
16 my $db = tie %hash, 'DBM::Deep', 't/test.db';
17
18 if ($db->error()) {
19 print "ERROR: " . $db->error();
20 ok(0);
21 exit(0);
22 }
3e97ba2a 23 else { ok(1, "Tied an hash with an array for params" ); }
ffed8b01 24}
25
26{
27 unlink "t/test.db";
28 my %hash;
29 my $db = tie %hash, 'DBM::Deep', {
30 file => 't/test.db',
31 };
32
33 if ($db->error()) {
34 print "ERROR: " . $db->error();
35 ok(0);
36 exit(0);
37 }
3e97ba2a 38 else { ok(1, "Tied a hash with a hashref for params" ); }
ffed8b01 39}
40
41{
42 unlink "t/test.db";
43 my @array;
44 my $db = tie @array, 'DBM::Deep', 't/test.db';
45
46 if ($db->error()) {
47 print "ERROR: " . $db->error();
48 ok(0);
49 exit(0);
50 }
3e97ba2a 51 else { ok(1, "Tied an array with an array for params" ); }
ffed8b01 52
3e97ba2a 53 is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
ffed8b01 54}
55
56{
57 unlink "t/test.db";
58 my @array;
59 my $db = tie @array, 'DBM::Deep', {
60 file => 't/test.db',
61 };
62
63 if ($db->error()) {
64 print "ERROR: " . $db->error();
65 ok(0);
66 exit(0);
67 }
3e97ba2a 68 else { ok(1, "Tied an array with a hashref for params" ); }
ffed8b01 69
3e97ba2a 70 is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
ffed8b01 71}
72
73# These are testing the naive use of ref() within TIEHASH and TIEARRAY.
74# They should be doing (Scalar::Util::reftype($_[0]) eq 'HASH') and then
75# erroring out if it's not.
76TODO: {
217fef02 77 todo_skip( "Naive use of {\@_}", 1 );
ffed8b01 78 unlink "t/test.db";
79 my %hash;
80 my $db = tie %hash, 'DBM::Deep', [
81 file => 't/test.db',
82 ];
83
84 if ($db->error()) {
85 print "ERROR: " . $db->error();
86 ok(0);
87 exit(0);
88 }
89 else { ok(1); }
90}
91
92TODO: {
217fef02 93 todo_skip( "Naive use of {\@_}", 1 );
ffed8b01 94 unlink "t/test.db";
95 my @array;
96 my $db = tie @array, 'DBM::Deep', [
97 file => 't/test.db',
98 ];
99
100 if ($db->error()) {
101 print "ERROR: " . $db->error();
102 ok(0);
103 exit(0);
104 }
105 else { ok(1); }
106}
107
217fef02 108unlink "t/test.db";
109throws_ok {
110 tie my %hash, 'DBM::Deep', undef, file => 't/test.db';
111} qr/Odd number of parameters/, "Odd number of params to TIEHASH fails";
ffed8b01 112
217fef02 113unlink "t/test.db";
114throws_ok {
115 tie my @array, 'DBM::Deep', undef, file => 't/test.db';
116} qr/Odd number of parameters/, "Odd number of params to TIEARRAY fails";