Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 115 lines (91 sloc) 2.532 kB
ebc0a2c [t/spec]
moritz authored
1 use v6;
2 use Test;
a8fc23f [t/spec] tests for RT #69254, role composition can transport inheritance
moritz authored
3 plan 22;
ebc0a2c [t/spec]
moritz authored
4
605c16f [t/spec] fix some of the S12/Roles smartlinks
moritz authored
5 # L<S14/Roles/"Roles may be composed into a class at compile time">
c2f8fec [t] and [t/spec] (two train travels worth of changes):
moritz authored
6
ebc0a2c [t/spec]
moritz authored
7 role rA {
8 method mA1 {
9 'mA1';
10 }
11 method mA2 {
12 'mA2';
13 }
14 };
15
16 role rB {
17 method mB1 {
18 'mB1';
19 }
20 method mB2 {
21 'mB2';
22 }
23 };
24
25 class C1 does rA {
26 method mC1 {
27 'mC1';
28 }
29 };
30
31 my $x = C1.new();
32
33 is $x.mC1, 'mC1', 'Can call method of class with mixed in role';
34 is $x.mA1, 'mA1', 'Call first method from role';
35 is $x.mA2, 'mA2', 'Call second method from role';
36
37 class C2 does rA does rB {
38 method mC2 {
39 'mC2';
40 }
41 }
42
43 my $y = C2.new();
44
45 is $y.mC2, 'mC2', 'Can call method of class with two roles mixed in';
46 is $y.mA1, 'mA1', 'Can call mixed in method (two roles) 1';
47 is $y.mA2, 'mA2', 'Can call mixed in method (two roles) 2';
48 is $y.mB1, 'mB1', 'Can call mixed in method (two roles) 3';
49 is $y.mB2, 'mB2', 'Can call mixed in method (two roles) 4';
50
e376edf [t/spec] Test for RT #64002
kyle authored
51 ok C2 ~~ rA, 'class matches first role';
52 ok C2 ~~ rB, 'class matches second role';
53 ok rA !~~ C2, 'first role does not match class';
54 ok rB !~~ C2, 'second role does not match class';
55
56 role RT64002 does rA does rB {}
57 #?rakudo 2 todo 'RT #64002'
58 ok RT64002 ~~ rA, 'role matches first role it does';
59 ok RT64002 ~~ rB, 'role matches second role it does';
60 ok rA !~~ RT64002, 'role not matched by first role it does';
61 ok rB !~~ RT64002, 'role not matched by second role it does';
62
86dbfdc Fixes from moritz++ to do the test properly
mattw authored
63 {
975b429 [t/spec] indent lines in composition.t to not confuse the fudge script
moritz authored
64 class D1 does rA {
65 method mA1 {
66 'D1.mA1';
67 }
a8fc3f9 test for RT #62200: classes overriding methods from roles
mattw authored
68 }
69
975b429 [t/spec] indent lines in composition.t to not confuse the fudge script
moritz authored
70 my $z = D1.new();
a8fc3f9 test for RT #62200: classes overriding methods from roles
mattw authored
71
975b429 [t/spec] indent lines in composition.t to not confuse the fudge script
moritz authored
72 is $z.mA1, 'D1.mA1', 'Can override method in a role with method in a class';
86dbfdc Fixes from moritz++ to do the test properly
mattw authored
73 }
a8fc3f9 test for RT #62200: classes overriding methods from roles
mattw authored
74
afb3675 [t/spec] Unfudge test for RT#63330.
jnthn authored
75 # diamond composition
2f37cb1 [t/spec] tests for RT #63330 and RT #63332
moritz authored
76 {
77 role DA {
78 method foo { "OH HAI" };
79 }
80 role DB does DA { }
81 role DC does DA { }
82 class DD does DB does DC { };
83 is DD.new.foo, 'OH HAI', 'diamond role composition';
84 class DE is DB is DC { };
85 is DE.new.foo, 'OH HAI', 'same with punning and inheritance';
86 }
87
4898b49 [t/spec] Test for RT #69919
kyle authored
88 # RT #69919
89 {
90 role RT69919 {
91 my $lex = 'Luthor';
92 method rt69919 { return $lex }
93 }
94 class IL does RT69919 {}
95
96 is IL.new.rt69919, 'Luthor', 'access lexical declared in role from method called via class that does the role';
97 }
98
a8fc23f [t/spec] tests for RT #69254, role composition can transport inheritance
moritz authored
99
100 # inheritance through role composition - specced in A12
101 # RT 69254
102 {
103 class irA {};
104 role irB is irA {};
105 class irC does irB {};
106 ok irC ~~ irB, 'role composition worked';
107 ok irC ~~ irA, 'role composition transported inheritance';
108
109 }
110
111
4898b49 [t/spec] Test for RT #69919
kyle authored
112 done_testing;
113
ebc0a2c [t/spec]
moritz authored
114 # vim: syn=perl6
Something went wrong with that request. Please try again.