From: Nicholas Clark Date: Sun, 14 Apr 2002 22:54:43 +0000 (+0100) Subject: Re: [PATCH] Re: restricted hashes are unblessable X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0cd24ecfa77c796fc462e9808f747fde6a836a04;p=p5sagit%2Fp5-mst-13.2.git Re: [PATCH] Re: restricted hashes are unblessable Message-ID: <20020414215442.GE301@Bagpuss.unfortu.net> p4raw-id: //depot/perl@15926 --- diff --git a/lib/Hash/Util.t b/lib/Hash/Util.t index a42a52e..20efb44 100644 --- a/lib/Hash/Util.t +++ b/lib/Hash/Util.t @@ -6,7 +6,8 @@ BEGIN { chdir 't'; } } -use Test::More tests => 55; +use Test::More tests => 61; +use strict; my @Exported_Funcs; BEGIN { @@ -202,4 +203,27 @@ like( $@, qr/^Attempt to access disallowed key 'I_DONT_EXIST' in a restricted ha is (scalar keys %hash, 0, "and therefore there are no keys"); $hash{second} = 1; is (scalar keys %hash, 1, "we now have just one key"); + delete $hash{second}; + is (scalar keys %hash, 0, "back to zero"); + + unlock_keys(%hash); # We have deliberately left a placeholder. + + $hash{void} = undef; + $hash{nowt} = undef; + + is (scalar keys %hash, 2, "two keys, values both undef"); + + lock_keys(%hash); + + is (scalar keys %hash, 2, "still two keys after locking"); + + eval {$hash{second} = -1}; + like ($@, + qr/^Attempt to access disallowed key 'second' in a restricted hash/, + 'previously locked place holders should fail'); + + is ($hash{void}, undef, + "undef values should not be misunderstood as placeholders"); + is ($hash{nowt}, undef, + "undef values should not be misunderstood as placeholders (again)"); }