source: trunk/essentials/dev-lang/perl/lib/Hash/Util.t

Last change on this file was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 9.6 KB
Line 
1#!/usr/bin/perl -Tw
2
3BEGIN {
4 if( $ENV{PERL_CORE} ) {
5 @INC = '../lib';
6 chdir 't';
7 }
8}
9use Test::More tests => 179;
10use strict;
11
12my @Exported_Funcs;
13BEGIN {
14 @Exported_Funcs = qw(lock_keys unlock_keys
15 lock_value unlock_value
16 lock_hash unlock_hash
17 hash_seed
18 );
19 use_ok 'Hash::Util', @Exported_Funcs;
20}
21foreach my $func (@Exported_Funcs) {
22 can_ok __PACKAGE__, $func;
23}
24
25my %hash = (foo => 42, bar => 23, locked => 'yep');
26lock_keys(%hash);
27eval { $hash{baz} = 99; };
28like( $@, qr/^Attempt to access disallowed key 'baz' in a restricted hash/,
29 'lock_keys()');
30is( $hash{bar}, 23 );
31ok( !exists $hash{baz} );
32
33delete $hash{bar};
34ok( !exists $hash{bar} );
35$hash{bar} = 69;
36is( $hash{bar}, 69 );
37
38eval { () = $hash{i_dont_exist} };
39like( $@, qr/^Attempt to access disallowed key 'i_dont_exist' in a restricted hash/ );
40
41lock_value(%hash, 'locked');
42eval { print "# oops" if $hash{four} };
43like( $@, qr/^Attempt to access disallowed key 'four' in a restricted hash/ );
44
45eval { $hash{"\x{2323}"} = 3 };
46like( $@, qr/^Attempt to access disallowed key '(.*)' in a restricted hash/,