Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 135 lines (119 sloc) 3.889 kb
a3ea1eb [gsoc_spectest] Fixed typo in S13 test. Added new defer_call and defer_n...
Auzon authored
1 use v6;
2
3 use Test;
4
f3f049b @lizmat Added extra "nextwith()" tests, that are failing for now
lizmat authored
5 plan 21;
a3ea1eb [gsoc_spectest] Fixed typo in S13 test. Added new defer_call and defer_n...
Auzon authored
6
7 # L<S12/"Calling sets of methods"/"Any method can defer to the next candidate method in the list">
8
e1e4684 [t/spec] Tests for RT#66978.
jnthn authored
9 # Simple test, making sure nextwith passes on parameters properly.
10 class A {
11 method a(*@A) {
12 (self.perl, @A)
13 }
14 }
15 class B is A {
16 method a() {
17 nextwith("FIRST ARG", "SECOND ARG")
18 }
19 }
20 {
21 my $instance = B.new;
22 my @result = $instance.a();
23 is @result.elems, 3, 'nextwith passed on right number of parameters';
24 is @result[0], $instance.perl, 'invocant passed on correctly';
25 is @result[1], "FIRST ARG", 'first argument correct';
26 is @result[2], "SECOND ARG", 'second argument correct';
27 }
28
a3ea1eb [gsoc_spectest] Fixed typo in S13 test. Added new defer_call and defer_n...
Auzon authored
29 class Foo {
30 # $.tracker is used to determine the order of calls.
20fa0ed Correct and fudge defer next. Plan to expand it plenty also, we should t...
jnthn authored
31 has $.tracker is rw;
32 multi method doit() {$.tracker ~= 'foo,'}
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
33 multi method doit(Int $num) {$.tracker ~= 'fooint,'} #OK not used
a3ea1eb [gsoc_spectest] Fixed typo in S13 test. Added new defer_call and defer_n...
Auzon authored
34 method show {$.tracker}
35 method clear {$.tracker = ''}
36 }
37
38 class BarNextSame is Foo {
20fa0ed Correct and fudge defer next. Plan to expand it plenty also, we should t...
jnthn authored
39 multi method doit() {$.tracker ~= 'bar,'; nextsame; $.tracker ~= 'ret1,'}
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
40 multi method doit(Int $num) {$.tracker ~= 'barint,'; nextsame; $.tracker ~= 'ret2,'} #OK not used
a3ea1eb [gsoc_spectest] Fixed typo in S13 test. Added new defer_call and defer_n...
Auzon authored
41 }
42
43 {
44 my $o = BarNextSame.new;
45 $o.clear;
46 $o.doit;
47 is($o.show, 'bar,foo,', 'nextsame inheritance test');
48 $o.clear;
49 is($o.show, '', 'sanity test for clearing');
50 $o.doit(5);
20fa0ed Correct and fudge defer next. Plan to expand it plenty also, we should t...
jnthn authored
51 is($o.show, 'barint,fooint,', 'nextsame multimethod/inheritance test');
a3ea1eb [gsoc_spectest] Fixed typo in S13 test. Added new defer_call and defer_n...
Auzon authored
52 }
53
54 class BarNextWithEmpty is Foo {
20fa0ed Correct and fudge defer next. Plan to expand it plenty also, we should t...
jnthn authored
55 multi method doit() {$.tracker ~= 'bar,'; nextwith(); $.tracker ~= 'ret1,'}
266464f @jnthn Update defer-next.t to match latest proto/multi semantics.
jnthn authored
56 multi method doit(Int $num) {$.tracker ~= 'barint,'; nextwith($num); $.tracker ~= 'ret2,'} #OK not used
a3ea1eb [gsoc_spectest] Fixed typo in S13 test. Added new defer_call and defer_n...
Auzon authored
57 }
58 {
59 my $o = BarNextWithEmpty.new;
60 $o.clear;
61 $o.doit;
62 is($o.show, 'bar,foo,', 'nextwith() inheritance test');
63 $o.clear;
64 is($o.show, '', 'sanity test for clearing');
65 $o.doit(5);
266464f @jnthn Update defer-next.t to match latest proto/multi semantics.
jnthn authored
66 is($o.show, 'barint,fooint,', 'nextwith() multimethod/inheritance test');
a3ea1eb [gsoc_spectest] Fixed typo in S13 test. Added new defer_call and defer_n...
Auzon authored
67 }
68
69 class BarNextWithInt is Foo {
266464f @jnthn Update defer-next.t to match latest proto/multi semantics.
jnthn authored
70 multi method doit() {$.tracker ~= 'bar,'; nextwith(); $.tracker ~= 'ret1,'}
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
71 multi method doit(Int $num) {$.tracker ~= 'barint,'; nextwith(42); $.tracker ~= 'ret2,'} #OK not used
a3ea1eb [gsoc_spectest] Fixed typo in S13 test. Added new defer_call and defer_n...
Auzon authored
72 }
73 {
74 my $o = BarNextWithInt.new;
75 $o.clear;
76 $o.doit;
266464f @jnthn Update defer-next.t to match latest proto/multi semantics.
jnthn authored
77 is($o.show, 'bar,foo,', 'nextwith(42) inheritance test');
a3ea1eb [gsoc_spectest] Fixed typo in S13 test. Added new defer_call and defer_n...
Auzon authored
78 $o.clear;
79 is($o.show, '', 'sanity test for clearing');
80 $o.doit(5);
81 is($o.show, 'barint,fooint,', 'nextwith(42) multimethod/inheritance test');
82 }
f81e0ca [t/spec] fudge test that TimToady++ corrected and now does not pass on R...
moritz authored
83
b2a9245 [t/spec] tests for RT #69608: nextwidth() when no more candidates are av...
moritz authored
84 {
85 my $called = 0;
86 class DeferWithoutCandidate {
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
87 multi method a($x) { #OK not used
b2a9245 [t/spec] tests for RT #69608: nextwidth() when no more candidates are av...
moritz authored
88 $called = 1;
89 nextwith();
90 }
91 }
25668e6 @coke Prefer RT #XXXXXX
coke authored
92 #?rakudo todo 'variant of RT #69608'
b2a9245 [t/spec] tests for RT #69608: nextwidth() when no more candidates are av...
moritz authored
93 dies_ok { DeferWithoutCandidate.new.a(1) },
94 'Dies when nextwith() does not find a candidate to dispatch to';
95 is $called, 1, 'but was in the correct method before death';
96 }
97
f3f049b @lizmat Added extra "nextwith()" tests, that are failing for now
lizmat authored
98 {
99 my $r;
100 class AA {
101 proto method l (|) { * }
102 multi method l ( &t, *@list ) {
103 $r ~= '&';
104 $r ~= @list.join;
105 $r;
106 }
107 multi method l ( %t, *@list ) {
108 $r ~= '%';
109 $r ~= @list.join;
184ff24 @lizmat Check new "samewith" functionality
lizmat authored
110 samewith( { %t{$^a} }, @list );
111 # &?ROUTINE.dispatcher()( self, { %t{$^a} }, @list );
f3f049b @lizmat Added extra "nextwith()" tests, that are failing for now
lizmat authored
112 }
113 multi method l ( @t, *@list ) {
114 $r ~= '@';
115 $r ~= @list.join;
184ff24 @lizmat Check new "samewith" functionality
lizmat authored
116 samewith( { @t[$^a] }, @list );
117 # &?ROUTINE.dispatcher()( self, { @t[$^a] }, @list );
f3f049b @lizmat Added extra "nextwith()" tests, that are failing for now
lizmat authored
118 }
119 }
120
121 my $a = AA.new;
122 is $a.l( {$_}, 1,2,3 ), '&123', 'return direct call to code ref candidate';
123 is $r, '&123', "direct call to code ref candidate";
124
125 $r='';
126 is $a.l( my %a, 4,5,6 ), '%456&456', 'return from hash candidate';
127 is $r, '%456&456', "call to hash candidate";
128
129 $r='';
130 is $a.l( my @a, 7,8,9 ), '@789&789', 'return from array candidate';
131 is $r, '@789&789', "call to array candidate";
132 }
133
f81e0ca [t/spec] fudge test that TimToady++ corrected and now does not pass on R...
moritz authored
134 # vim: ft=perl6
Something went wrong with that request. Please try again.