Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 76 lines (60 sloc) 1.762 kb
59fcce5 [t] cleaned up attributes/recursive.t and moved to spec/
moritz authored
1 use v6;
2
3 use Test;
4
c1f35a8 [t/spec] fix plan in recursive.t, fudge for rakudo
moritz authored
5 plan 15;
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">
32 {
33 class B {
34 my B $.attr is rw;
35 };
36
37 my B $a;
38 lives_ok {
39 $a .= new();
40 B.attr = $a;
41 }, "Can instantiate class with recursively-typed class lexical";
42 ok B.attr === $a, "Recursively-typed class lexical stores correctly";
43
44 }
45
46 #L<S12/Methods/current lexically-determined class ::?CLASS>
c1f35a8 [t/spec] fix plan in recursive.t, fudge for rakudo
moritz authored
47 #?rakudo skip '::?CLASS'
59fcce5 [t] cleaned up attributes/recursive.t and moved to spec/
moritz authored
48 {
49 class C {
50 has ::?CLASS $.attr is rw;
51 };
52
53 my C $a;
54 my C $b;
55 lives_ok {
56 $a .= new();
57 $b .= new(:attr($a));
58 }, 'Can instantiate class with ::?CLASS attribute';
59 is $b.attr, $a, '::?CLASS attribute stores correctly';
60 lives_ok { $a.attr = $b; }, '::?CLASS cycles are fine';
61 ok $b.attr.attr === $b, '::?CLASS cycles resolve correctly';
62 lives_ok { $a.attr .= new(); }, 'Can instantiate attribute of type ::?CLASS';
63 isa_ok $a.attr, C, '::?CLASS instantiates to correct class';
64
65
66 class D is C { };
67 my D $d;
68 lives_ok {
69 $d .= new();
70 $d.attr .= new();
71 }, 'Can instantiate derived class with ::?CLASS attribute';
ba8e84a [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
72 #?pugs todo 'bug'
73 isa_ok $d.attr, C, '::?CLASS is lexical, not virtual';
59fcce5 [t] cleaned up attributes/recursive.t and moved to spec/
moritz authored
74 }
75
Something went wrong with that request. Please try again.