Merged with master and am ready to merge back
[dbsrgits/DBM-Deep.git] / t / 20_tie.t
CommitLineData
ffed8b01 1use strict;
0e3e3555 2use warnings FATAL => 'all';
3
4use Test::More;
217fef02 5use Test::Exception;
fde3db1a 6use t::common qw( new_fh );
ffed8b01 7
217fef02 8use_ok( 'DBM::Deep' );
ffed8b01 9
ffed8b01 10# testing the various modes of opening a file
ffed8b01 11{
fde3db1a 12 my ($fh, $filename) = new_fh();
ffed8b01 13 my %hash;
2a81bf9e 14 my $db = tie %hash, 'DBM::Deep', $filename;
ffed8b01 15
95967a5e 16 ok(1, "Tied an hash with an array for params" );
ffed8b01 17}
18
19{
fde3db1a 20 my ($fh, $filename) = new_fh();
ffed8b01 21 my %hash;
22 my $db = tie %hash, 'DBM::Deep', {
2a81bf9e 23 file => $filename,
ffed8b01 24 };
25
95967a5e 26 ok(1, "Tied a hash with a hashref for params" );
ffed8b01 27}
28
29{
fde3db1a 30 my ($fh, $filename) = new_fh();
ffed8b01 31 my @array;
2a81bf9e 32 my $db = tie @array, 'DBM::Deep', $filename;
ffed8b01 33
95967a5e 34 ok(1, "Tied an array with an array for params" );
ffed8b01 35
3e97ba2a 36 is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
ffed8b01 37}
38
39{
fde3db1a 40 my ($fh, $filename) = new_fh();
ffed8b01 41 my @array;
42 my $db = tie @array, 'DBM::Deep', {
2a81bf9e 43 file => $filename,
ffed8b01 44 };
45
95967a5e 46 ok(1, "Tied an array with a hashref for params" );
ffed8b01 47
3e97ba2a 48 is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
ffed8b01 49}
50
fde3db1a 51my ($fh, $filename) = new_fh();
e1b265cc 52throws_ok {
2a81bf9e 53 tie my %hash, 'DBM::Deep', [ file => $filename ];
e1b265cc 54} qr/Not a hashref/, "Passing an arrayref to TIEHASH fails";
ffed8b01 55
e1b265cc 56throws_ok {
2a81bf9e 57 tie my @array, 'DBM::Deep', [ file => $filename ];
e1b265cc 58} qr/Not a hashref/, "Passing an arrayref to TIEARRAY fails";
ffed8b01 59
217fef02 60throws_ok {
2a81bf9e 61 tie my %hash, 'DBM::Deep', undef, file => $filename;
217fef02 62} qr/Odd number of parameters/, "Odd number of params to TIEHASH fails";
ffed8b01 63
217fef02 64throws_ok {
2a81bf9e 65 tie my @array, 'DBM::Deep', undef, file => $filename;
217fef02 66} qr/Odd number of parameters/, "Odd number of params to TIEARRAY fails";
0e3e3555 67
68done_testing;