Skip to content
Newer
Older
100644 70 lines (54 sloc) 1.76 KB
dd2b31b [t] move var/is_readonly.t to spec
moritz authored Sep 3, 2008
1 use v6;
2 use Test;
3
1fa9ddf @timo test for RT #71356: readonly trait for private attributes
timo authored Dec 10, 2012
4 plan 14;
6cdc350 @coke pugs fudges
coke authored Feb 26, 2012
5
dd2b31b [t] move var/is_readonly.t to spec
moritz authored Sep 3, 2008
6 # L<S06/"Parameter traits"/"=item is readonly">
7 # should be moved with other subroutine tests?
8
9
10 {
11 my $a is readonly := 42;
12 is $a, 42, "basic declaration of a 'is readonly' variable works";
13
14 dies_ok { $a = 23 }, "a var declared with 'is readonly' is readonly (1)";
15 is $a, 42, "a var declared with 'is readonly' is readonly (2)";
16 }
17
18 {
19 my $a is readonly;
20 ok !$a, "declaration of an 'is readonly' var without supplying a container to bind to works";
21 try { $a := 42 };
22 is $a, 42, "binding the variable now works";
23
f25f151 [t/spec] Change more Pugs todo flags to fudge commands
kyle authored Jun 19, 2009
24 #?pugs todo 'feature'
efe2b30 @coke rakudo fudging
coke authored Oct 8, 2011
25 #?rakudo todo 'todo'
f25f151 [t/spec] Change more Pugs todo flags to fudge commands
kyle authored Jun 19, 2009
26 dies_ok { $a := 17 }, "but binding it again does not work";
dd2b31b [t] move var/is_readonly.t to spec
moritz authored Sep 3, 2008
27 }
28
efe2b30 @coke rakudo fudging
coke authored Oct 8, 2011
29 #?rakudo skip 'segfault'
dd2b31b [t] move var/is_readonly.t to spec
moritz authored Sep 3, 2008
30 {
31 my $a is readonly;
7aab93d [t] excise exists and delete functions
lwall authored Oct 10, 2008
32 ok !(try { VAR($a).defined }), ".VAR returns undefined on an uninitialized var declared with 'is readonly'";
dd2b31b [t] move var/is_readonly.t to spec
moritz authored Sep 3, 2008
33
34 $a := 42;
f25f151 [t/spec] Change more Pugs todo flags to fudge commands
kyle authored Jun 19, 2009
35 ok (try { VAR($a).defined }), ".VAR returns defined now";
dd2b31b [t] move var/is_readonly.t to spec
moritz authored Sep 3, 2008
36 }
37
001e798 @moritz &eval does not catch exceptions.
moritz authored Oct 9, 2011
38 #?rakudo skip 'VAR'
dd2b31b [t] move var/is_readonly.t to spec
moritz authored Sep 3, 2008
39 {
40 my $a = 3;
41
f25f151 [t/spec] Change more Pugs todo flags to fudge commands
kyle authored Jun 19, 2009
42 ok (try { VAR($a).defined }), ".VAR on a plain normal initialized variable returns true";
dd2b31b [t] move var/is_readonly.t to spec
moritz authored Sep 3, 2008
43 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored Aug 8, 2009
44
53c1dec [t/spec] Test for RT #65900
kyle authored Oct 27, 2009
45 # RT #65900
46 {
47 my ($rt65900 is readonly) = 5;
48 is $rt65900, 5, 'my ($x is readonly) can take assignment';
efe2b30 @coke rakudo fudging
coke authored Oct 8, 2011
49 #?rakudo 2 todo 'todo'
6cdc350 @coke pugs fudges
coke authored Feb 27, 2012
50 #?pugs 2 todo
53c1dec [t/spec] Test for RT #65900
kyle authored Oct 27, 2009
51 dies_ok { $rt65900 = 'ro' }, 'dies on assignment to readonly variable';
52
53 dies_ok { (my $rt65900 is readonly) = 5 },
54 'dies on assignment to (my $x is readonly)';
55 }
56
1fa9ddf @timo test for RT #71356: readonly trait for private attributes
timo authored Dec 10, 2012
57 # RT #71356
58 {
59 class C {
60 has $!attr is readonly = 71356;
61 method get-attr() { $!attr }
62 method set-attr($val) { $!attr = $val }
63 }
64 is C.new.get-attr, 71356, 'can read from readonly private attributes';
3ac110d @moritz fudge new, failing test for read-only attributes
moritz authored Dec 11, 2012
65 #?rakudo todo 'readonly attributes'
1fa9ddf @timo test for RT #71356: readonly trait for private attributes
timo authored Dec 10, 2012
66 dies_ok { my $c = C.new; $c.set-attr: 99; }, 'cannot assign to readonly private attribute'
67 }
68
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored Aug 8, 2009
69 # vim: ft=perl6
Something went wrong with that request. Please try again.