File: 20_tie.t

package info (click to toggle)
libdbm-deep-perl 2.0008-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 884 kB
  • sloc: perl: 7,383; sql: 36
file content (68 lines) | stat: -rw-r--r-- 1,619 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use strict;
use warnings FATAL => 'all';

use Test::More;
use Test::Exception;
use t::common qw( new_fh );

use_ok( 'DBM::Deep' );

# testing the various modes of opening a file
{
    my ($fh, $filename) = new_fh();
    my %hash;
    my $db = tie %hash, 'DBM::Deep', $filename;

    ok(1, "Tied an hash with an array for params" );
}

{
    my ($fh, $filename) = new_fh();
    my %hash;
    my $db = tie %hash, 'DBM::Deep', {
        file => $filename,
    };

    ok(1, "Tied a hash with a hashref for params" );
}

{
    my ($fh, $filename) = new_fh();
    my @array;
    my $db = tie @array, 'DBM::Deep', $filename;

    ok(1, "Tied an array with an array for params" );

    is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
}

{
    my ($fh, $filename) = new_fh();
    my @array;
    my $db = tie @array, 'DBM::Deep', {
        file => $filename,
    };

    ok(1, "Tied an array with a hashref for params" );

    is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
}

my ($fh, $filename) = new_fh();
throws_ok {
    tie my %hash, 'DBM::Deep', [ file => $filename ];
} qr/Not a hashref/, "Passing an arrayref to TIEHASH fails";

throws_ok {
    tie my @array, 'DBM::Deep', [ file => $filename ];
} qr/Not a hashref/, "Passing an arrayref to TIEARRAY fails";

throws_ok {
    tie my %hash, 'DBM::Deep', undef, file => $filename;
} qr/Odd number of parameters/, "Odd number of params to TIEHASH fails";

throws_ok {
    tie my @array, 'DBM::Deep', undef, file => $filename;
} qr/Odd number of parameters/, "Odd number of params to TIEARRAY fails";

done_testing;