Skip to content
Newer
Older
100644 129 lines (104 sloc) 3.46 KB
33d23c3 [spectest] Some tests for mixing in roles with 'does'.
jnthn authored Jun 19, 2008
1 use v6;
2 use Test;
f362fbd @tadzik Tests for RT #100782
tadzik authored Nov 15, 2011
3 plan 27;
33d23c3 [spectest] Some tests for mixing in roles with 'does'.
jnthn authored Jun 19, 2008
4
25e6fd9 [t/spec] fix roles smartlinks
moritz authored May 7, 2009
5 # L<S14/Run-time Mixins/>
c2f8fec [t] and [t/spec] (two train travels worth of changes):
moritz authored Dec 14, 2008
6
33d23c3 [spectest] Some tests for mixing in roles with 'does'.
jnthn authored Jun 19, 2008
7 role R1 { method test { 42 } }
8 class C1 { }
9
10 my $x = C1.new();
11 $x does R1;
12 is $x.test, 42, 'method from a role can be mixed in';
e3bb48e Tests for calling mixed in methods with .?, .+ and .*.
jnthn authored Apr 11, 2009
13 is $x.?test, 42, '.? form of call works on a mixed-in role';
78dff06 @colomon Fudge for niecza.
colomon authored Jan 6, 2012
14 #?niecza skip 'NYI dottyop form .+'
e3bb48e Tests for calling mixed in methods with .?, .+ and .*.
jnthn authored Apr 11, 2009
15 is $x.+test, 42, '.+ form of call works on a mixed-in role';
78dff06 @colomon Fudge for niecza.
colomon authored Jan 6, 2012
16 #?niecza skip 'NYI dottyop form .*'
e3bb48e Tests for calling mixed in methods with .?, .+ and .*.
jnthn authored Apr 11, 2009
17 is $x.*test, 42, '.* form of call works on a mixed-in role';
33d23c3 [spectest] Some tests for mixing in roles with 'does'.
jnthn authored Jun 19, 2008
18
19
20 role R2 { method test { 42 } }
21 class C2 { has $.x }
22 my $y = C2.new(x => 100);
23 is $y.x, 100, 'initialization sanity check';
24 $y does R2;
25 is $y.test, 42, 'method from role was mixed in';
26 is $y.x, 100, 'mixing in did not destroy old value';
27
28
29 role R3 { has $.answer is rw }
30 class C3 { has $.x }
720c254 [spectest] A couple more mixin tests, for does (R1, R2) and does Answ…
jnthn authored Jun 19, 2008
31 $y = C3.new(x => 100);
33d23c3 [spectest] Some tests for mixing in roles with 'does'.
jnthn authored Jun 19, 2008
32 $y does R3;
33 $y.answer = 42;
34 is $y.x, 100, 'mixing in with attributes did not destroy existing ones';
35 is $y.answer, 42, 'mixed in new attributes';
36
37
720c254 [spectest] A couple more mixin tests, for does (R1, R2) and does Answ…
jnthn authored Jun 19, 2008
38 $y = C3.new(x => 100);
39 $y does (R2, R3);
40 $y.answer = 13;
41 is $y.x, 100, 'multi-role mixin preserved existing values';
42 is $y.answer, 13, 'attribute from multi-role mixing OK';
43 is $y.test, 42, 'method from other role was OK too';
44
45
7767ea6 [t/spec] fudge mixin.t for rakudo
moritz authored May 6, 2010
46 {
47 role Answer { has $.answer is rw }
2327d69 @jnthn Unfudge a test for Rakudo. Along the way, make it not attempt to mix …
jnthn authored Jan 17, 2012
48 my $x = 0 but Answer(42);
7767ea6 [t/spec] fudge mixin.t for rakudo
moritz authored May 6, 2010
49 is $x.answer, 42, 'role mix-in with initialization value worked';
50 is $x, 0, 'mixing into Int still makes it function as an Int';
51 }
4612e1b [spectest] A couple more tests for mixins, to cover a bug fixed today…
jnthn authored Aug 7, 2008
52
2327d69 @jnthn Unfudge a test for Rakudo. Along the way, make it not attempt to mix …
jnthn authored Jan 16, 2012
53
7767ea6 [t/spec] fudge mixin.t for rakudo
moritz authored May 6, 2010
54 {
2327d69 @jnthn Unfudge a test for Rakudo. Along the way, make it not attempt to mix …
jnthn authored Jan 16, 2012
55 my $x = C1.new();
7767ea6 [t/spec] fudge mixin.t for rakudo
moritz authored May 6, 2010
56 role A { has $.a is rw }
57 role B { has $.b is rw }
58 $x does A(1);
59 $x does B(2);
60 is $x.a, 1, 'mixining in two roles one after the other';
61 is $x.b, 2, 'mixining in two roles one after the other';
62 }
d900b6b [t/spec] Test for does at the point of declaration.
jnthn authored Apr 20, 2009
63
f77aead [mixin.t] a better fix is to move the block boundary
lwall authored May 7, 2010
64
d900b6b [t/spec] Test for does at the point of declaration.
jnthn authored Apr 20, 2009
65 #?rakudo skip 'mixin at the point of declaration is compile time'
78dff06 @colomon Fudge for niecza.
colomon authored Jan 6, 2012
66 #?niecza skip 'Trait does not available on variables'
d900b6b [t/spec] Test for does at the point of declaration.
jnthn authored Apr 20, 2009
67 {
f77aead [mixin.t] a better fix is to move the block boundary
lwall authored May 7, 2010
68 my @array does R1;
69 is @array.test, 42, 'mixing in a role at the point of declaration works';
70
d900b6b [t/spec] Test for does at the point of declaration.
jnthn authored Apr 20, 2009
71 my $x;
72 BEGIN { $x = @array.test }
73 is $x, 42, 'mixing in at point of declaration at compile time';
74 }
720c254 [spectest] A couple more mixin tests, for does (R1, R2) and does Answ…
jnthn authored Jun 19, 2008
75
25e6fd9 [t/spec] fix roles smartlinks
moritz authored May 7, 2009
76 # L<S14/Run-time Mixins/"but only if the role supplies exactly one attribute">
9657e08 [t/spec] test for parameterized mixin
moritz authored May 3, 2009
77
78 {
79 role R4a {
80 # no attribute here
81 }
82 role R4b {
83 has $.x is rw;
84 }
85 role R4c {
86 has $.x;
87 has $.y;
88 }
89
90 dies_ok { my $x = 4; $x does R4a(3) },
91 '"does role(param)" does not work without attribute';
92 lives_ok { my $x = 4; $x does R4b(3) },
93 '"does role(param)" does work with one attribute';
94 dies_ok { my $x = 4; $x does R4c(3) },
95 '"does role(param)" does not work with two attributes';
96 is ([] does R4b("foo")).x, 'foo',
97 'can mix R4b into an Array, and access the attribute';
98 }
99
fd874aa [t/spec] test for RT #69654 - mixing in method with "does" should mak…
moritz authored Jul 5, 2010
100 # RT #69654
78dff06 @colomon Fudge for niecza.
colomon authored Jan 6, 2012
101 #?niecza skip 'Unable to resolve method methods in class ClassHOW'
fd874aa [t/spec] test for RT #69654 - mixing in method with "does" should mak…
moritz authored Jul 5, 2010
102 {
103 role ProvidesFoo { method foo { } }
104 class NoFoo { };
105 is (NoFoo.new does ProvidesFoo).^methods(:local)>>.name, 'foo',
106 'mixin with "does" lists method during introspection';
107 }
9657e08 [t/spec] test for parameterized mixin
moritz authored May 3, 2009
108
b5503f3 @moritz test for mixing into a Rat, RT #99986
moritz authored Sep 29, 2011
109 # RT #99986
110 {
111 lives_ok { 3/2 but role { } }, 'can mix into a Rat';
112 }
113
70c5eb7 @tadzik Tests for RT #77184
tadzik authored Nov 12, 2011
114 # RT #77184
78dff06 @colomon Fudge for niecza.
colomon authored Jan 6, 2012
115 #?niecza skip 'Twigil ! is only valid on attribute definitions'
c487222 @jnthn Fudge a (dubious) test.
jnthn authored Jan 15, 2012
116 #?rakudo skip 'Twigil ! is only valid on attribute definitions'
70c5eb7 @tadzik Tests for RT #77184
tadzik authored Nov 12, 2011
117 {
118 lives_ok { role A { my $!foo; }; role B { my $!foo; }; class C does A does B {} }, 'RT #77184'
119 }
120
f362fbd @tadzik Tests for RT #100782
tadzik authored Nov 15, 2011
121 # RT #100782
122 {
123 my $a = 0 but True;
124 is +$a, 0, 'RT #100782 1/2';
125 is ?$a, Bool::True, 'RT #100782 2/2';
126 }
127
33d23c3 [spectest] Some tests for mixing in roles with 'does'.
jnthn authored Jun 19, 2008
128 # vim: syn=perl6
Something went wrong with that request. Please try again.