Re: [ID 20020109.002] /(?m:...\s*$)/ is not backtracking properly
[p5sagit/p5-mst-13.2.git] / t / lib / access.t
CommitLineData
1b1f1335 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7
8$| = 1;
8aacddc1 9print "1..19\n";
1b1f1335 10
11my $t = 1;
12
13sub 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
28my %hash = ( one => 1, two => 2);;
29ok(!access::readonly(%hash));
30
31ok(!access::readonly(%hash,1));
32
8aacddc1 33ok(!access::readonly($hash{two},1));
34
1b1f1335 35eval { $hash{'three'} = 3 };
36#warn "$@";
37ok($@ =~ /^Attempt to access to key 'three' in fixed hash/);
38
39eval { print "# oops" if $hash{'four'}};
40#warn "$@";
41ok($@ =~ /^Attempt to access to key 'four' in fixed hash/);
42
43eval { $hash{"\x{2323}"} = 3 };
44#warn "$@";
45ok($@ =~ /^Attempt to access to key '(.*)' in fixed hash/);
46#ok(ord($1) == 0x2323);
47
8aacddc1 48eval { delete $hash{'two'}};
49#warn "$@";
50ok($@);
51
1b1f1335 52eval { delete $hash{'one'}};
8aacddc1 53ok(not $@);
54
55ok($hash{two} == 2);
56
57eval { delete $hash{'four'}};
1b1f1335 58#warn "$@";
8aacddc1 59ok($@ =~ /^Attempt to access to key 'four' in fixed hash/);
1b1f1335 60
8aacddc1 61ok(not exists $hash{'one'});
1b1f1335 62
63ok(!exists $hash{'three'});
64
65ok(access::readonly(%hash,0));
66
67ok(!access::readonly(%hash));
68
69my $scalar = 1;
70ok(!access::readonly($scalar));
71
72ok(!access::readonly($scalar,1));
73
74eval { $scalar++ };
75#warn $@;
76ok($@ =~ /^Modification of a read-only value attempted/);
77
78ok(access::readonly($scalar,0));
79
80ok(!access::readonly($scalar));
81
82