summaryrefslogtreecommitdiff
path: root/lib/Tie/ExtraHash.t
blob: bbaf64f040714d194a708ead30493f7c44fba3c0 (plain)
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
#!./perl

use strict;
use warnings;
use Test::More tests => 11;
use_ok('Tie::Hash');

tie my %tied, 'Tie::ExtraHash';
%tied = (apple => 'tree', cow => 'field');
my %hash = (apple => 'tree', cow => 'field');

# TIEHASH
is_deeply(\%hash, \%tied, "TIEHASH");
ok(tied(%tied), "TIEHASH really does tie");

# FIRST/NEXTKEY
is_deeply([sort keys %hash], [sort keys %tied], "FIRSTKEY/NEXTKEY");
is_deeply([sort values %hash], [sort values %tied], "FIRSTKEY/NEXTKEY");

# EXISTS
ok(exists($tied{apple}) && exists($hash{apple}),
   'EXISTS works when it exists');

# DELETE and !EXISTS
delete($tied{apple}); delete($hash{apple});
ok(!exists($tied{apple}) && !exists($hash{apple}),
   'EXISTS works when it doesn\'t exist (as does DELETE)');

# STORE and FETCH
$tied{house} = $hash{house} = 'town';
ok($tied{house} eq 'town' && $tied{house} eq $hash{house},
   'STORE and FETCH');

# CLEAR
%tied = (); %hash = ();
ok(tied(%tied), "still tied after CLEAR");
is_deeply(\%tied, \%hash, "CLEAR");

# SCALAR
is(scalar(%tied), scalar(%hash), "SCALAR");