Re: [PATCH] ...while $var = glob(...)
[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;
9print "1..15\n";
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
33eval { $hash{'three'} = 3 };
34#warn "$@";
35ok($@ =~ /^Attempt to access to key 'three' in fixed hash/);
36
37eval { print "# oops" if $hash{'four'}};
38#warn "$@";
39ok($@ =~ /^Attempt to access to key 'four' in fixed hash/);
40
41eval { $hash{"\x{2323}"} = 3 };
42#warn "$@";
43ok($@ =~ /^Attempt to access to key '(.*)' in fixed hash/);
44#ok(ord($1) == 0x2323);
45
46eval { delete $hash{'one'}};
47#warn "$@";
48ok($@ =~ /^Attempt to access to key 'one' in fixed hash/);
49
50ok(exists $hash{'one'});
51
52ok(!exists $hash{'three'});
53
54ok(access::readonly(%hash,0));
55
56ok(!access::readonly(%hash));
57
58my $scalar = 1;
59ok(!access::readonly($scalar));
60
61ok(!access::readonly($scalar,1));
62
63eval { $scalar++ };
64#warn $@;
65ok($@ =~ /^Modification of a read-only value attempted/);
66
67ok(access::readonly($scalar,0));
68
69ok(!access::readonly($scalar));
70
71