/
is-readonly.t
54 lines (40 loc) 路 1.33 KB
/
is-readonly.t
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
use v6;
use Test;
# L<S06/"Parameter traits"/"=item is readonly">
# should be moved with other subroutine tests?
{
my $a is readonly := 42;
is $a, 42, "basic declaration of a 'is readonly' variable works";
dies_ok { $a = 23 }, "a var declared with 'is readonly' is readonly (1)";
is $a, 42, "a var declared with 'is readonly' is readonly (2)";
}
{
my $a is readonly;
ok !$a, "declaration of an 'is readonly' var without supplying a container to bind to works";
try { $a := 42 };
is $a, 42, "binding the variable now works";
#?pugs todo 'feature'
dies_ok { $a := 17 }, "but binding it again does not work";
}
{
my $a is readonly;
ok !(try { VAR($a).defined }), ".VAR returns undefined on an uninitialized var declared with 'is readonly'";
$a := 42;
#?pugs todo 'feature'
ok (try { VAR($a).defined }), ".VAR returns defined now";
}
{
my $a = 3;
#?pugs todo 'feature'
ok (try { VAR($a).defined }), ".VAR on a plain normal initialized variable returns true";
}
# RT #65900
{
my ($rt65900 is readonly) = 5;
is $rt65900, 5, 'my ($x is readonly) can take assignment';
dies_ok { $rt65900 = 'ro' }, 'dies on assignment to readonly variable';
dies_ok { (my $rt65900 is readonly) = 5 },
'dies on assignment to (my $x is readonly)';
}
done;
# vim: ft=perl6