Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 119 lines (101 sloc) 4.083 kb
297e783 [t] and [t/spec]
moritz authored
1 use v6;
2
3 use Test;
4
5 plan 28;
6
7 =begin pod
8
756a2cd [t/spec] more smartlink fixing
moritz authored
9 Parameterized role tests, see L<S14/Roles>
297e783 [t] and [t/spec]
moritz authored
10
11 Might need some more review and love --moritz
12
13 =end pod
14
15 #?pugs emit skip_rest('parameterized roles'); exit;
16 #?pugs emit =begin SKIP
17
25e6fd9 [t/spec] fix roles smartlinks
moritz authored
18 # L<S14/Run-time Mixins/may be parameterized>
d540c40 [t/spec] Reviewed S14-role/parameterized-mixin.t. We got away with mi…
jnthn authored
19 role InitialAttribVal[$val] {
297e783 [t] and [t/spec]
moritz authored
20 has $.attr = $val;
d540c40 [t/spec] Reviewed S14-role/parameterized-mixin.t. We got away with mi…
jnthn authored
21 }
297e783 [t] and [t/spec]
moritz authored
22
d540c40 [t/spec] Reviewed S14-role/parameterized-mixin.t. We got away with mi…
jnthn authored
23 my $a = 0;
297e783 [t] and [t/spec]
moritz authored
24 lives_ok {$a does InitialAttribVal[42]},
25 "imperative does to apply a parametrized role (1)";
f9ffca4 [t/spec] Update perameterized roles test that checks mixins to match …
jnthn authored
26 is $a.attr, 42,
297e783 [t] and [t/spec]
moritz authored
27 "attribute was initialized correctly (1)";
f9ffca4 [t/spec] Update perameterized roles test that checks mixins to match …
jnthn authored
28 ok $a.HOW.does($a, InitialAttribVal),
297e783 [t] and [t/spec]
moritz authored
29 ".HOW.does gives correct information (1-1)";
30 ok $a.^does(InitialAttribVal),
31 ".^does gives correct information (1-1)";
f9ffca4 [t/spec] Update perameterized roles test that checks mixins to match …
jnthn authored
32 ok $a.HOW.does($a, InitialAttribVal[42]),
297e783 [t] and [t/spec]
moritz authored
33 ".HOW.does gives correct information (1-2)";
f9ffca4 [t/spec] Update perameterized roles test that checks mixins to match …
jnthn authored
34 ok $a.^does(InitialAttribVal[42]),
297e783 [t] and [t/spec]
moritz authored
35 ".^does gives correct information (1-2)";
36
d540c40 [t/spec] Reviewed S14-role/parameterized-mixin.t. We got away with mi…
jnthn authored
37 my $b = 0;
f9ffca4 [t/spec] Update perameterized roles test that checks mixins to match …
jnthn authored
38 lives_ok { $b does InitialAttribVal[23] },
297e783 [t] and [t/spec]
moritz authored
39 "imperative does to apply a parametrized role (2)";
f9ffca4 [t/spec] Update perameterized roles test that checks mixins to match …
jnthn authored
40 is $b.attr, 23,
297e783 [t] and [t/spec]
moritz authored
41 "attribute was initialized correctly (2)";
ecb0510 [t/spec] Unfudge some .does parameterized roles tests for Rakudo now …
jnthn authored
42 ok $b.HOW.does($b, InitialAttribVal),
297e783 [t] and [t/spec]
moritz authored
43 ".HOW.does gives correct information (2-1)";
f9ffca4 [t/spec] Update perameterized roles test that checks mixins to match …
jnthn authored
44 ok $b.^does(InitialAttribVal),
297e783 [t] and [t/spec]
moritz authored
45 ".^does gives correct information (2-1)";
ecb0510 [t/spec] Unfudge some .does parameterized roles tests for Rakudo now …
jnthn authored
46 ok $b.HOW.does($b, InitialAttribVal[23]),
297e783 [t] and [t/spec]
moritz authored
47 ".HOW.does gives correct information (2-2)";
f9ffca4 [t/spec] Update perameterized roles test that checks mixins to match …
jnthn authored
48 ok $b.^does(InitialAttribVal[23]),
297e783 [t] and [t/spec]
moritz authored
49 ".^does gives correct information (2-2)";
50
51
52
0477942 some more smartlinks updated
szabgab authored
53 # L<S14/Parametric Roles/main type is generic by default>
297e783 [t] and [t/spec]
moritz authored
54 role InitialAttribType[::vartype] {
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
55 method hi(vartype $foo) { 42 } #OK not used
297e783 [t] and [t/spec]
moritz authored
56 }
d540c40 [t/spec] Reviewed S14-role/parameterized-mixin.t. We got away with mi…
jnthn authored
57 my $c = 0;
f9ffca4 [t/spec] Update perameterized roles test that checks mixins to match …
jnthn authored
58 lives_ok { $c does InitialAttribType[Code] },
297e783 [t] and [t/spec]
moritz authored
59 "imperative does to apply a parametrized role (3)";
ecb0510 [t/spec] Unfudge some .does parameterized roles tests for Rakudo now …
jnthn authored
60 ok $c.HOW.does($c, InitialAttribType),
297e783 [t] and [t/spec]
moritz authored
61 ".HOW.does gives correct information (3-1)";
62 ok $c.^does(InitialAttribType),
63 ".^does gives correct information (3-1)";
ecb0510 [t/spec] Unfudge some .does parameterized roles tests for Rakudo now …
jnthn authored
64 ok $c.HOW.does($c, InitialAttribType[Code]),
297e783 [t] and [t/spec]
moritz authored
65 ".HOW.does gives correct information (3-2)";
66 ok $c.^does(InitialAttribType[Code]),
67 ".^does gives correct information (3-2)";
f9ffca4 [t/spec] Update perameterized roles test that checks mixins to match …
jnthn authored
68 is $c.hi(sub {}), 42,
297e783 [t] and [t/spec]
moritz authored
69 "type information was processed correctly (1)";
70 dies_ok { $c.hi("not a code object") },
71 "type information was processed correctly (2)";
72
73
74 # Parameterized role using both a parameter which will add to the "long name"
75 # of the role and one which doesn't.
76 # (Explanation: This one is easier. The two attributes $.type and $.name will
77 # be predefined (using the role parameterization). The $type adds to the long
78 # name of the role, $name does not. Such:
79 # my $a does InitialAttribBoth["foo", "bar"];
80 # my $b does InitialAttribBoth["foo", "grtz"];
81 # $a ~~ InitialAttribBoth ==> true
82 # $b ~~ InitialAttribBoth ==> true
83 # $a ~~ InitialAttribBoth["foo"] ==> true
84 # $b ~~ InitialAttribBoth["foo"] ==> true
85 # $a ~~ InitialAttribBoth["foo", "bar"] ==> false
86 # $b ~~ InitialAttribBoth["foo", "grtz"] ==> false
87 # Heavy stuff, eh?)
ecb0510 [t/spec] Unfudge some .does parameterized roles tests for Rakudo now …
jnthn authored
88 role InitialAttribBoth[Str $type;; Str $name] {
297e783 [t] and [t/spec]
moritz authored
89 has $.type = $type;
90 has $.name = $name;
91 }
d540c40 [t/spec] Reviewed S14-role/parameterized-mixin.t. We got away with mi…
jnthn authored
92 my $d = 0;
f9ffca4 [t/spec] Update perameterized roles test that checks mixins to match …
jnthn authored
93 lives_ok { $d does InitialAttribBoth["type1", "name1"] },
297e783 [t] and [t/spec]
moritz authored
94 "imperative does to apply a parametrized role (4)";
d540c40 [t/spec] Reviewed S14-role/parameterized-mixin.t. We got away with mi…
jnthn authored
95 ok $d.HOW.does($d, InitialAttribBoth),
297e783 [t] and [t/spec]
moritz authored
96 ".HOW.does gives correct information (4-1)";
d540c40 [t/spec] Reviewed S14-role/parameterized-mixin.t. We got away with mi…
jnthn authored
97 ok $d.^does(InitialAttribBoth),
297e783 [t] and [t/spec]
moritz authored
98 ".^does gives correct information (4-1)";
ecb0510 [t/spec] Unfudge some .does parameterized roles tests for Rakudo now …
jnthn authored
99 #?rakudo 4 skip '.does with parametric roles'
d540c40 [t/spec] Reviewed S14-role/parameterized-mixin.t. We got away with mi…
jnthn authored
100 # Are these really right? Trying to supply one parameter to a role that
101 # needs two? Even if the second doesn't participate in the multi dispatch,
102 # it still exists as a role parameter that needs supplying. Maybe we do
103 # not create multiple role variants though...but these are almost certainly
104 # not correct. -- jnthn
105 ok $d.HOW.does($d, InitialAttribBoth["type1"]),
297e783 [t] and [t/spec]
moritz authored
106 ".HOW.does gives correct information (4-2)";
d540c40 [t/spec] Reviewed S14-role/parameterized-mixin.t. We got away with mi…
jnthn authored
107 ok $d.^does(InitialAttribBoth["type1"]),
297e783 [t] and [t/spec]
moritz authored
108 ".^does gives correct information (4-2)";
d540c40 [t/spec] Reviewed S14-role/parameterized-mixin.t. We got away with mi…
jnthn authored
109 ok !$d.HOW.does($d, InitialAttribBoth["type1", "name1"]),
297e783 [t] and [t/spec]
moritz authored
110 ".HOW.does gives correct information (4-3)";
d540c40 [t/spec] Reviewed S14-role/parameterized-mixin.t. We got away with mi…
jnthn authored
111 ok !$d.^does(InitialAttribBoth["type1", "name1"]),
297e783 [t] and [t/spec]
moritz authored
112 ".^does gives correct information (4-3)";
f9ffca4 [t/spec] Update perameterized roles test that checks mixins to match …
jnthn authored
113 is $d.type, "type1", ".type works correctly";
114 is $d.name, "name1", ".name works correctly";
297e783 [t] and [t/spec]
moritz authored
115
116 #?pugs emit =end SKIP
117
118 # vim: ft=perl6
Something went wrong with that request. Please try again.