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