summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Cantrell <david@cantrell.org.uk>2010-08-02 09:43:27 +0200
committerSteffen Mueller <smueller@cpan.org>2010-08-02 09:43:27 +0200
commitb9d6bef4b93a33f3590bca291e2bd2c859a88370 (patch)
tree15e07a7bf39e199d55b6599ef85f70e9336d1cc5 /lib
parent7c7c771f637468fccf32a16e82076fb0a2378117 (diff)
downloadperl-b9d6bef4b93a33f3590bca291e2bd2c859a88370.tar.gz
Add tests for Tie::ExtraHash
Diffstat (limited to 'lib')
-rw-r--r--lib/Tie/ExtraHash.t50
1 files changed, 50 insertions, 0 deletions
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");
+