Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
86867f3a |
5 | use Test::More tests => 5; |
6 | use Test::Deep; |
fde3db1a |
7 | use t::common qw( new_fh ); |
ffed8b01 |
8 | |
9 | use_ok( 'DBM::Deep' ); |
10 | |
eff6a245 |
11 | diag "This test can take up to a minute to run. Please be patient."; |
12 | |
fde3db1a |
13 | my ($fh, $filename) = new_fh(); |
ffed8b01 |
14 | my $db = DBM::Deep->new( |
2a81bf9e |
15 | file => $filename, |
86867f3a |
16 | type => DBM::Deep->TYPE_HASH, |
ffed8b01 |
17 | ); |
ffed8b01 |
18 | |
19 | ## |
20 | # put/get many keys |
21 | ## |
a4e2db58 |
22 | my $max_keys = 4000; |
23 | |
ffed8b01 |
24 | for ( 0 .. $max_keys ) { |
25 | $db->put( "hello $_" => "there " . $_ * 2 ); |
26 | } |
27 | |
30029562 |
28 | my $count = -1; |
ffed8b01 |
29 | for ( 0 .. $max_keys ) { |
30029562 |
30 | $count = $_; |
31 | unless ( $db->get( "hello $_" ) eq "there " . $_ * 2 ) { |
32 | last; |
33 | }; |
ffed8b01 |
34 | } |
30029562 |
35 | is( $count, $max_keys, "We read $count keys" ); |
bee3661a |
36 | |
86867f3a |
37 | my @keys = sort keys %$db; |
38 | cmp_ok( scalar(@keys), '==', $max_keys + 1, "Number of keys is correct" ); |
39 | my @control = sort map { "hello $_" } 0 .. $max_keys; |
40 | cmp_deeply( \@keys, \@control, "Correct keys are there" ); |
41 | |
bee3661a |
42 | $db->clear; |
43 | cmp_ok( scalar(keys %$db), '==', 0, "Number of keys after clear() is correct" ); |