Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 98 lines (79 sloc) 2.342 kb
59fcce5 [t] cleaned up attributes/recursive.t and moved to spec/
moritz authored
1 use v6;
2
3 use Test;
4
8b7c044 lizmat Add some more tests for recursively typed attributes
lizmat authored
5 plan 23;
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';
e14fe6a Solomon Foster Fix dodgy test. Fudge for niecza.
colomon authored
25 isa_ok $a, A, 'Sanity check, $a is of type A';
59fcce5 [t] cleaned up attributes/recursive.t and moved to spec/
moritz authored
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
8aaac76 Matthew Wilson fix a bunch of smartlinks in S12, broken by me and TimToady++
diakopter authored
31 #L<S12/Class attributes/"Class attributes are declared">
59fcce5 [t] cleaned up attributes/recursive.t and moved to spec/
moritz authored
32 {
33 class B {
2213769 lizmat Remove unspecced 'is rw' atribute on variables
lizmat authored
34 my B $.attr;
59fcce5 [t] cleaned up attributes/recursive.t and moved to spec/
moritz authored
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
8aaac76 Matthew Wilson fix a bunch of smartlinks in S12, broken by me and TimToady++
diakopter authored
46 #L<S12/Invocants/current lexically-determined class ::?CLASS>
e14fe6a Solomon Foster Fix dodgy test. Fudge for niecza.
colomon authored
47 #?niecza skip 'A type must be provided ???'
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 isa_ok $d.attr, C, '::?CLASS is lexical, not virtual';
59fcce5 [t] cleaned up attributes/recursive.t and moved to spec/
moritz authored
73 }
74
88d78c6 [t/spec] Test for RT #67236
kyle authored
75 # RT #67236
76 {
77 class Z {
8b7c044 lizmat Add some more tests for recursively typed attributes
lizmat authored
78 has Z @.a is rw;
79 has Z %.h is rw;
88d78c6 [t/spec] Test for RT #67236
kyle authored
80 }
81
8b7c044 lizmat Add some more tests for recursively typed attributes
lizmat authored
82 my $z1 = Z.new;
5604403 Will Coleda niecza fudge
coke authored
83 #?niecza todo "https://github.com/sorear/niecza/issues/183"
8b7c044 lizmat Add some more tests for recursively typed attributes
lizmat authored
84 isa_ok $z1.a[0], Z, "check type-object";
85 lives_ok { $z1.a[0] = Z.new }, 'can assign';
86 isa_ok $z1.a[0], Z;
5604403 Will Coleda niecza fudge
coke authored
87 #?niecza todo "https://github.com/sorear/niecza/issues/183"
8b7c044 lizmat Add some more tests for recursively typed attributes
lizmat authored
88 isa_ok $z1.h<k>, Z, "check type-object";
89 lives_ok { $z1.h<k> = Z.new }, 'can assign';
90 isa_ok $z1.h<k>, Z;
91
92 my $z2 = Z.new;
93 lives_ok { $z2.a.push( Z.new ) }, 'can push';
94 isa_ok $z2.a[0], Z;
88d78c6 [t/spec] Test for RT #67236
kyle authored
95 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
96
97 # vim: ft=perl6
Something went wrong with that request. Please try again.