blob: da7193e6d419037a1ba56a76942a6de3fbab4715 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!./perl
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
}
$| = 1;
print "1..19\n";
my $t = 1;
sub ok
{
my $val = shift;
if ($val)
{
print "ok $t\n";
}
else
{
my ($pack,$file,$line) = caller;
print "not ok $t # $file:$line\n";
}
$t++;
}
my %hash = ( one => 1, two => 2);;
ok(!access::readonly(%hash));
ok(!access::readonly(%hash,1));
ok(!access::readonly($hash{two},1));
eval { $hash{'three'} = 3 };
#warn "$@";
ok($@ =~ /^Attempt to access key 'three' in fixed hash/);
eval { print "# oops" if $hash{'four'}};
#warn "$@";
ok($@ =~ /^Attempt to access key 'four' in fixed hash/);
eval { $hash{"\x{2323}"} = 3 };
#warn "$@";
ok($@ =~ /^Attempt to access key '(.*)' in fixed hash/);
#ok(ord($1) == 0x2323);
eval { delete $hash{'two'}};
#warn "$@";
ok($@);
eval { delete $hash{'one'}};
ok(not $@);
ok($hash{two} == 2);
eval { delete $hash{'four'}};
#warn "$@";
ok($@ =~ /^Attempt to access key 'four' in fixed hash/);
ok(not exists $hash{'one'});
ok(!exists $hash{'three'});
ok(access::readonly(%hash,0));
ok(!access::readonly(%hash));
my $scalar = 1;
ok(!access::readonly($scalar));
ok(!access::readonly($scalar,1));
eval { $scalar++ };
#warn $@;
ok($@ =~ /^Modification of a read-only value attempted/);
ok(access::readonly($scalar,0));
ok(!access::readonly($scalar));
|