From b9d6bef4b93a33f3590bca291e2bd2c859a88370 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Mon, 2 Aug 2010 09:43:27 +0200 Subject: Add tests for Tie::ExtraHash --- lib/Tie/ExtraHash.t | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 lib/Tie/ExtraHash.t (limited to 'lib') diff --git a/lib/Tie/ExtraHash.t b/lib/Tie/ExtraHash.t new file mode 100644 index 0000000000..c8e4630882 --- /dev/null +++ b/lib/Tie/ExtraHash.t @@ -0,0 +1,50 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + if ($^O eq 'MacOS') { + @INC = qw(: ::lib ::macos:lib); + } else { + @INC = '.'; + push @INC, '../lib'; + } +} +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"); + -- cgit v1.2.1