Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 93 lines (74 sloc) 2.092 kB
59fcce5 [t] cleaned up attributes/recursive.t and moved to spec/
moritz authored
1 use v6;
2
3 use Test;
4
88d78c6 [t/spec] Test for RT #67236
kyle authored
5 plan 19;
59fcce5 [t] cleaned up attributes/recursive.t and moved to spec/
moritz authored
6
7 =begin pod
8
9 Test attributes with recursively typed attributes
10
11 =end pod
12
13 #L<S12/Attributes>
14 {
15 class A {
16 has A $.attr is rw;
17 };
18
19 my A $a;
20 my A $b;
21 lives_ok {
22 $a .= new();
23 $b .= new(:attr($a));
24 }, 'Can instantiate class with recursively-typed attribute';
25 isa_ok $a, 'A', 'Sanity check, $a is of type A';
26 ok $b.attr === $a, "Recursively-typed attribute stores correctly";
27 lives_ok { $a.attr = $b; }, "Cycles are fine";
28 ok $b.attr.attr === $b, "Cycles resolve correctly";
29 }
30
31 #L<S12/Attributes/"Class attributes are declared">
0eaeed3 [t/spec] Re-fudge S12-attributes/recursive.t for current Rakudo; we p…
jnthn authored
32 #?rakudo skip 'class attributes NYI'
59fcce5 [t] cleaned up attributes/recursive.t and moved to spec/
moritz authored
33 {
34 class B {
35 my B $.attr is rw;
36 };
37
38 my B $a;
39 lives_ok {
40 $a .= new();
41 B.attr = $a;
42 }, "Can instantiate class with recursively-typed class lexical";
43 ok B.attr === $a, "Recursively-typed class lexical stores correctly";
44
45 }
46
47 #L<S12/Methods/current lexically-determined class ::?CLASS>
c1f35a8 [t/spec] fix plan in recursive.t, fudge for rakudo
moritz authored
48 #?rakudo skip '::?CLASS'
59fcce5 [t] cleaned up attributes/recursive.t and moved to spec/
moritz authored
49 {
50 class C {
51 has ::?CLASS $.attr is rw;
52 };
53
54 my C $a;
55 my C $b;
56 lives_ok {
57 $a .= new();
58 $b .= new(:attr($a));
59 }, 'Can instantiate class with ::?CLASS attribute';
60 is $b.attr, $a, '::?CLASS attribute stores correctly';
61 lives_ok { $a.attr = $b; }, '::?CLASS cycles are fine';
62 ok $b.attr.attr === $b, '::?CLASS cycles resolve correctly';
63 lives_ok { $a.attr .= new(); }, 'Can instantiate attribute of type ::?CLASS';
64 isa_ok $a.attr, C, '::?CLASS instantiates to correct class';
65
66
67 class D is C { };
68 my D $d;
69 lives_ok {
70 $d .= new();
71 $d.attr .= new();
72 }, 'Can instantiate derived class with ::?CLASS attribute';
ba8e84a [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
73 #?pugs todo 'bug'
74 isa_ok $d.attr, C, '::?CLASS is lexical, not virtual';
59fcce5 [t] cleaned up attributes/recursive.t and moved to spec/
moritz authored
75 }
76
88d78c6 [t/spec] Test for RT #67236
kyle authored
77 # RT #67236
78 {
79 class Z {
80 has Z @.as is rw;
81 }
82
83 my $good_a = Z.new;
84 lives_ok { $good_a.as[0] = Z.new }, 'can assign';
85 isa_ok $good_a.as[0], Z;
86
87 my $bad_a = Z.new;
88 lives_ok { $bad_a.as.push( Z.new ) }, 'can push';
89 isa_ok $bad_a.as[0], Z;
90 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
91
92 # vim: ft=perl6
Something went wrong with that request. Please try again.