Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 97 lines (82 sloc) 3.078 kB
193c892 [t/spec] Rename S14-traits/basic.t to variables.t to better indicate …
jnthn authored
1 use v6;
2 use Test;
3
b99ebea @jnthn Test submethods and traits interaction.
jnthn authored
4 plan 15;
193c892 [t/spec] Rename S14-traits/basic.t to variables.t to better indicate …
jnthn authored
5
6 # L<S14/Traits/>
3f79756 @moritz port a few trait tests to the new spec
moritz authored
7 {
8 role description {
9 has $.description is rw;
10 }
193c892 [t/spec] Rename S14-traits/basic.t to variables.t to better indicate …
jnthn authored
11
17368d0 @moritz fix up traits and importing tests
moritz authored
12 multi trait_mod:<is>(Routine $code, description, $arg) {
13 $code does description($arg)
3f79756 @moritz port a few trait tests to the new spec
moritz authored
14 }
60cabaf @jnthn Correct routine trait test (which didn't even parse!) and todo one te…
jnthn authored
15 multi trait_mod:<is>(Routine $code, description) {
17368d0 @moritz fix up traits and importing tests
moritz authored
16 $code does description('missing description!')
3f79756 @moritz port a few trait tests to the new spec
moritz authored
17 }
17368d0 @moritz fix up traits and importing tests
moritz authored
18 multi trait_mod:<is>(Routine $code, Str :$described!) {
19 $code does description($described);
3f79756 @moritz port a few trait tests to the new spec
moritz authored
20 }
17368d0 @moritz fix up traits and importing tests
moritz authored
21 multi trait_mod:<is>(Routine $code, Bool :$described!) {
3f79756 @moritz port a few trait tests to the new spec
moritz authored
22 $code does description("missing description!");
23 }
193c892 [t/spec] Rename S14-traits/basic.t to variables.t to better indicate …
jnthn authored
24
25
3f79756 @moritz port a few trait tests to the new spec
moritz authored
26 sub answer() is description('computes the answer') { 42 }
27 sub faildoc() is description { "fail" }
28 is answer(), 42, 'can call sub that has had a trait applied to it by role name with arg';
29 is &answer.description, 'computes the answer', 'description role applied and set with argument';
30 is faildoc(), "fail", 'can call sub that has had a trait applied to it by role name without arg';
31 is &faildoc.description, 'missing description!', 'description role applied without argument';
193c892 [t/spec] Rename S14-traits/basic.t to variables.t to better indicate …
jnthn authored
32
3f79756 @moritz port a few trait tests to the new spec
moritz authored
33 sub cheezburger is described("tasty") { "nom" }
34 sub lolcat is described { "undescribable" }
193c892 [t/spec] Rename S14-traits/basic.t to variables.t to better indicate …
jnthn authored
35
3f79756 @moritz port a few trait tests to the new spec
moritz authored
36 is cheezburger(), "nom", 'can call sub that has had a trait applied to it by named param with arg';
37 is &cheezburger.description, 'tasty', 'named trait handler applied other role set with argument';
38 is lolcat(), "undescribable", 'can call sub that has had a trait applied to it by named param without arg';
39 is &lolcat.description, 'missing description!', 'named trait handler applied other role without argument';
40 }
193c892 [t/spec] Rename S14-traits/basic.t to variables.t to better indicate …
jnthn authored
41
65aa5bd [t/spec] Tests for RT #69893, wrapping subroutines in traits
moritz authored
42 {
43 my $recorder = '';
3f79756 @moritz port a few trait tests to the new spec
moritz authored
44 multi trait_mod:<is>(Routine $c, :$woowoo!) {
65aa5bd [t/spec] Tests for RT #69893, wrapping subroutines in traits
moritz authored
45 $c.wrap: sub {
46 $recorder ~= 'wrap';
47 }
48 }
49 sub foo is woowoo { };
9f47446 @lizmat s/lives_ok/lives-ok/g
lizmat authored
50 lives-ok &foo, 'Can call subroutine that was wrapped by a trait';
60cabaf @jnthn Correct routine trait test (which didn't even parse!) and todo one te…
jnthn authored
51 #?rakudo todo 'trait mod / .wrap interaction'
65aa5bd [t/spec] Tests for RT #69893, wrapping subroutines in traits
moritz authored
52 is $recorder, 'wrap', 'and the wrapper has been called once';
53 }
54
de07434 @kyleha [S14-traits/routines.t] Test for RT 112664
kyleha authored
55 # RT 112664
56 {
8922597 @lizmat Fix test by limiting to Routine, rather than anything
lizmat authored
57 multi trait_mod:<is>(Routine $m, :$a!) {
89f0409 @TimToady warning suppression, mostly "not used"
TimToady authored
58 multi y(|) { my $x = $m } #OK not used
de07434 @kyleha [S14-traits/routines.t] Test for RT 112664
kyleha authored
59 $m.wrap(&y)
60 }
61 sub rt112664 is a {}
62
9f47446 @lizmat s/lives_ok/lives-ok/g
lizmat authored
63 lives-ok { rt112664 },
de07434 @kyleha [S14-traits/routines.t] Test for RT 112664
kyleha authored
64 '[BUG] multi without proto gets wrong lexical lookup chain (RT 112664)';
65 }
66
1a144b7 @bbkr declaration of a sub with an unknown trait mentions trait_mod:<is> in…
bbkr authored
67 # RT 74092
68 {
5bab36f @FROGGS eval => EVAL in S14 to S32
FROGGS authored
69 try { EVAL 'sub yulia is krassivaya { }' };
0650e78 @lizmat Fudge now failing test, correct another for current error message format
lizmat authored
70 diag $!
71 if !ok "$!" ~~ /'unknown trait'/,
1a144b7 @bbkr declaration of a sub with an unknown trait mentions trait_mod:<is> in…
bbkr authored
72 'declaration of a sub with an unknown trait mentions trait_mod:<is> in dispatch error';
73 }
74
68efa9a @jnthn Test for wrapping in a trait_mod.
jnthn authored
75 {
76 multi trait_mod:<is>(Routine $r, :$trait_that_wraps!) {
77 $r.wrap(-> |c { 2 * callsame; })
78 }
79 sub wrappee($a, $b) is trait_that_wraps { 42 };
80 is wrappee(1, 2), 84, 'wrapping a routine at compile time makes it soft';
81 }
82
b99ebea @jnthn Test submethods and traits interaction.
jnthn authored
83 {
84 multi trait_mod:<is>(Routine $r, :$test_trait!) {
85 $r does role { #`( I only came for the type change ) }
86 }
87 my class A {
88 submethod m() is test_trait { 42 }
89 }
90 my class B is A { }
91 is A.m, 42, 'Applying traits to submethods works';
92 throws-like { B.m }, X::Method::NotFound,
93 'Applying traits to submethods retains submethod semantics';
94 }
95
193c892 [t/spec] Rename S14-traits/basic.t to variables.t to better indicate …
jnthn authored
96 # vim: ft=perl6
Something went wrong with that request. Please try again.