-
Notifications
You must be signed in to change notification settings - Fork 135
/
rw.t
38 lines (27 loc) · 823 Bytes
/
rw.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
use v6;
use Test;
plan 5;
# L<S12/Attributes/If you declare the class as>
class Foo {
has $.readonly_attr;
}
{
my Foo $foo .= new;
dies_ok { $foo.readonly_attr++ }, "basic sanity";
}
class Bar is rw {
has $.readwrite_attr;
has $.but_not_this is readonly;
}
{
my Bar $bar .= new(but_not_this => 42);
lives_ok { $bar.readwrite_attr++ },
"'is rw' on the class declaration applies to all attributes (1)";
is $bar.readwrite_attr, 1,
"'is rw' on the class declaration applies to all attributes (2)";
dies_ok { $bar.but_not_this = 42 },
"'is readonly' on a specific attribute can overrule the is rw on the class (1)";
is $bar.but_not_this, 42,
"'is readonly' on a specific attribute can overrule the is rw on the class (2)";
}
# vim: ft=perl6