File: 19_crossref.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 (79 lines) | stat: -rw-r--r-- 2,168 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
69
70
71
72
73
74
75
76
77
78
79
use strict;
use warnings FATAL => 'all';

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

use_ok( 'DBM::Deep' );

my $dbm_factory = new_dbm();
while ( my $dbm_maker = $dbm_factory->() ) {
    my $db = $dbm_maker->();

    SKIP: {
        skip "Apparently, we cannot detect a tied scalar?", 1;
        tie my $foo, 'Tied::Scalar';
        throws_ok {
            $db->{failure} = $foo;
        } qr/Cannot store something that is tied\./, "tied scalar storage fails";
    }

    {
        tie my @foo, 'Tied::Array';
        throws_ok {
            $db->{failure} = \@foo;
        } qr/Cannot store something that is tied\./, "tied array storage fails";
    }

    {
        tie my %foo, 'Tied::Hash';
        throws_ok {
            $db->{failure} = \%foo;
        } qr/Cannot store something that is tied\./, "tied hash storage fails";
    }

    # Need to create a second instance of a dbm here, but only of the type
    # being tested.
    if(0){
        my $db2 = $dbm_maker->();

        $db2->import({
            hash1 => {
                subkey1 => "subvalue1",
                subkey2 => "subvalue2",
            }
        });
        is( $db2->{hash1}{subkey1}, 'subvalue1', "Value1 imported correctly" );
        is( $db2->{hash1}{subkey2}, 'subvalue2', "Value2 imported correctly" );

        # Test cross-ref nested hash across DB objects
        throws_ok {
            $db->{copy} = $db2->{hash1};
        } qr/Cannot store values across DBM::Deep files\. Please use export\(\) instead\./, "cross-ref fails";

        # This error text is for when internal cross-refs are implemented:
        # qr/Cannot cross-reference\. Use export\(\) instead\./

        my $x = $db2->{hash1}->export;
        $db->{copy} = $x;
    }

    ##
    # Make sure $db has copy of $db2's hash structure
    ##
#    is( $db->{copy}{subkey1}, 'subvalue1', "Value1 copied correctly" );
#    is( $db->{copy}{subkey2}, 'subvalue2', "Value2 copied correctly" );
}

done_testing;

package Tied::Scalar;
sub TIESCALAR { bless {}, $_[0]; }
sub FETCH{}

package Tied::Array;
sub TIEARRAY { bless {}, $_[0]; }

package Tied::Hash;
sub TIEHASH { bless {}, $_[0]; }