summaryrefslogtreecommitdiff
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
parent7c7c771f637468fccf32a16e82076fb0a2378117 (diff)
downloadperl-b9d6bef4b93a33f3590bca291e2bd2c859a88370.tar.gz
Add tests for Tie::ExtraHash
-rw-r--r--MANIFEST1
-rw-r--r--Porting/Maintainers.pl1
-rw-r--r--lib/Tie/ExtraHash.t50
3 files changed, 52 insertions, 0 deletions
diff --git a/MANIFEST b/MANIFEST
index 632f0a2e97..b5ad9187e7 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -3608,6 +3608,7 @@ lib/Tie/Array/push.t Test for Tie::Array
lib/Tie/Array/splice.t Test for Tie::Array::SPLICE
lib/Tie/Array/stdpush.t Test for Tie::StdArray
lib/Tie/Array/std.t Test for Tie::StdArray
+lib/Tie/ExtraHash.t Test for Tie::ExtraHash (in Tie/Hash.pm)
lib/Tie/Handle.pm Base class for tied handles
lib/Tie/Handle/stdhandle_from_handle.t Test for Tie::StdHandle/Handle backwards compat
lib/Tie/Handle/stdhandle.t Test for Tie::StdHandle
diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl
index bbb19316f7..1164ebf0a4 100644
--- a/Porting/Maintainers.pl
+++ b/Porting/Maintainers.pl
@@ -1764,6 +1764,7 @@ use File::Glob qw(:case);
lib/Thread.{pm,t}
lib/Tie/Array.pm
lib/Tie/Array/
+ lib/Tie/ExtraHash.t
lib/Tie/Handle.pm
lib/Tie/Handle/
lib/Tie/Hash.pm
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");
+