added test for freespace management
[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
95967a5e 18 ok(1, "Tied an hash with an array for params" );
ffed8b01 19}
20
21{
22 unlink "t/test.db";
23 my %hash;
24 my $db = tie %hash, 'DBM::Deep', {
25 file => 't/test.db',
26 };
27
95967a5e 28 ok(1, "Tied a hash with a hashref for params" );
ffed8b01 29}
30
31{
32 unlink "t/test.db";
33 my @array;
34 my $db = tie @array, 'DBM::Deep', 't/test.db';
35
95967a5e 36 ok(1, "Tied an array with an array for params" );
ffed8b01 37
3e97ba2a 38 is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
ffed8b01 39}
40
41{
42 unlink "t/test.db";
43 my @array;
44 my $db = tie @array, 'DBM::Deep', {
45 file => 't/test.db',
46 };
47
95967a5e 48 ok(1, "Tied an array with a hashref for params" );
ffed8b01 49
3e97ba2a 50 is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
ffed8b01 51}
52
e1b265cc 53unlink "t/test.db";
54throws_ok {
55 tie my %hash, 'DBM::Deep', [ file => 't/test.db' ];
56} qr/Not a hashref/, "Passing an arrayref to TIEHASH fails";
ffed8b01 57
e1b265cc 58unlink "t/test.db";
59throws_ok {
60 tie my @array, 'DBM::Deep', [ file => 't/test.db' ];
61} qr/Not a hashref/, "Passing an arrayref to TIEARRAY fails";
ffed8b01 62
217fef02 63unlink "t/test.db";
64throws_ok {
65 tie my %hash, 'DBM::Deep', undef, file => 't/test.db';
66} qr/Odd number of parameters/, "Odd number of params to TIEHASH fails";
ffed8b01 67
217fef02 68unlink "t/test.db";
69throws_ok {
70 tie my @array, 'DBM::Deep', undef, file => 't/test.db';
71} qr/Odd number of parameters/, "Odd number of params to TIEARRAY fails";