Tagged 0.981_01 (experimental auditlog)
[dbsrgits/DBM-Deep.git] / t / 21_tie_access.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
5use Test::More;
6use Test::Exception;
7
8plan tests => 7;
9
10use_ok( 'DBM::Deep' );
11
12# How should one test for creation failure with the tie mechanism?
13
14unlink "t/test.db";
15
16{
17 my %hash;
18 tie %hash, 'DBM::Deep', "t/test.db";
19
20 $hash{key1} = 'value';
21 is( $hash{key1}, 'value', 'Set and retrieved key1' );
22}
23
24{
25 my %hash;
26 tie %hash, 'DBM::Deep', "t/test.db";
27
28 is( $hash{key1}, 'value', 'Set and retrieved key1' );
29
30 is( keys %hash, 1, "There's one key so far" );
31 ok( exists $hash{key1}, "... and it's key1" );
32}
33
9d085683 34throws_ok {
35 tie my @array, 'DBM::Deep', {
36 file => 't/test.db',
37 type => DBM::Deep->TYPE_ARRAY,
38 };
39} qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
ffed8b01 40
90f93b43 41unlink "t/test2.db";
42DBM::Deep->new( file => 't/test2.db', type => DBM::Deep->TYPE_ARRAY );
9d085683 43
44throws_ok {
45 tie my %hash, 'DBM::Deep', {
90f93b43 46 file => 't/test2.db',
9d085683 47 type => DBM::Deep->TYPE_HASH,
48 };
49} qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";