1#!./perl 2 3use strict; 4use warnings; 5use Test::More tests => 11; 6use_ok('Tie::Hash'); 7 8tie my %tied, 'Tie::ExtraHash'; 9%tied = (apple => 'tree', cow => 'field'); 10my %hash = (apple => 'tree', cow => 'field'); 11 12# TIEHASH 13is_deeply(\%hash, \%tied, "TIEHASH"); 14ok(tied(%tied), "TIEHASH really does tie"); 15 16# FIRST/NEXTKEY 17is_deeply([sort keys %hash], [sort keys %tied], "FIRSTKEY/NEXTKEY"); 18is_deeply([sort values %hash], [sort values %tied], "FIRSTKEY/NEXTKEY"); 19 20# EXISTS 21ok(exists($tied{apple}) && exists($hash{apple}), 22 'EXISTS works when it exists'); 23 24# DELETE and !EXISTS 25delete($tied{apple}); delete($hash{apple}); 26ok(!exists($tied{apple}) && !exists($hash{apple}), 27 'EXISTS works when it doesn\'t exist (as does DELETE)'); 28 29# STORE and FETCH 30$tied{house} = $hash{house} = 'town'; 31ok($tied{house} eq 'town' && $tied{house} eq $hash{house}, 32 'STORE and FETCH'); 33 34# CLEAR 35%tied = (); %hash = (); 36ok(tied(%tied), "still tied after CLEAR"); 37is_deeply(\%tied, \%hash, "CLEAR"); 38 39# SCALAR 40is(scalar(%tied), scalar(%hash), "SCALAR"); 41 42