Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 178 lines (135 sloc) 4.146 kb
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
1 use Test;
ec38923 @moritz test for 1.*WHAT (which is forbidden), RT #72818
moritz authored
2 plan 32;
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
3
4 # L<S12/"Calling sets of methods">
5
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
6 # Some basic tests with only single-dispatch in operation.
7 class A {
8 has $.cnt is rw;
9 method foo { $.cnt += 4 }
10 }
11 class B is A {
12 method foo { $.cnt += 2 }
13 }
14 class C is B {
15 method foo { $.cnt += 1 }
16 }
17
18 {
19 my $c = C.new();
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
20
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
21 $c.cnt = 0;
22 $c.?foo();
23 is $c.cnt, 1, '.? calls first matching method';
dfc18a4 [t] more system, require, does, defer, label cleanup
lwall authored
24
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
25 $c.cnt = 0;
26 $c.*foo();
27 is $c.cnt, 7, '.* calls up inheritance hierarchy';
dfc18a4 [t] more system, require, does, defer, label cleanup
lwall authored
28
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
29 $c.cnt = 0;
30 $c.+foo();
31 is $c.cnt, 7, '.+ calls up inheritance hierarchy';
32
62e2e2f [t/spec]: Clean up (and unfudge) some tests involving Nil, sink, and un...
pmichaud authored
33 is $c.?bar(), Nil, '.? on undefined method gives Nil';
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
34
35 my $lived = 0;
36 try { $c.+bar(); $lived = 1; }
37 is $lived, 0, '.+ on undefined method is an error';
38
d1a6687 @lizmat class.*bar returns Parcel, not Nil
lizmat authored
39 is_deeply $c.*bar(), (), '.* on undefined method gives Nil';
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
40
41 my $foo = "foo";
42
43 $c.cnt = 0;
44 $c.?"$foo"();
45 is $c.cnt, 1, '.? with dynamic method name';
46
47 $c.cnt = 0;
48 $c.*"$foo"();
49 is $c.cnt, 7, '.* with dynamic method name';
50
51 $c.cnt = 0;
52 $c.+"$foo"();
53 is $c.cnt, 7, '.+ with dynamic method name';
54
9d68b77 @moritz fudge calling_sets.t for rakudo, and use dies_ok instead of a custom con...
moritz authored
55 dies_ok { $c."?foo"() }, '? at start of dynamic name does not imply .?';
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
56
9d68b77 @moritz fudge calling_sets.t for rakudo, and use dies_ok instead of a custom con...
moritz authored
57 dies_ok { $c."+foo"() }, '+ at start of dynamic name does not imply .+';
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
58
9d68b77 @moritz fudge calling_sets.t for rakudo, and use dies_ok instead of a custom con...
moritz authored
59 dies_ok { $c."*foo"() }, '* at start of dynamic name does not imply .*';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
60 }
61
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
62
63 # Some tests involiving .?, .+ and .* with multi-methods.
64 class D {
65 has $.cnt is rw;
66 multi method foo() { $.cnt++ }
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
67 multi method foo(Int $x) { $.cnt++ } #OK not used
68 multi method foo($x) { $.cnt++ } #OK not used
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
69 }
70 class E is D {
71 multi method foo() { $.cnt++ }
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
72 multi method foo($x) { $.cnt++ } #OK not used
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
73 }
74
9d68b77 @moritz fudge calling_sets.t for rakudo, and use dies_ok instead of a custom con...
moritz authored
75 #?rakudo skip 'ambiguous dispatch'
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
76 {
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
77 my $e = E.new();
78
79 $e.cnt = 0;
80 $e.foo();
81 is $e.cnt, 1, 'dispatch to one sanity test';
82
83 $e.cnt = 0;
84 $e.?foo();
85 is $e.cnt, 1, '.? calls first matching multi method';
86
87 $e.cnt = 0;
88 $e.*foo();
89 is $e.cnt, 2, '.* calls up inheritance hierarchy and all possible multis';
90
91 $e.cnt = 0;
92 $e.*foo(2.5);
93 is $e.cnt, 2, '.* calls up inheritance hierarchy and all possible multis';
94
95 $e.cnt = 0;
96 $e.*foo(2);
97 is $e.cnt, 3, '.* calls up inheritance hierarchy and all possible multis';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
98
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
99 $e.cnt = 0;
100 $e.+foo();
101 is $e.cnt, 2, '.+ calls up inheritance hierarchy and all possible multis';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
102
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
103 $e.cnt = 0;
104 $e.+foo(2.5);
105 is $e.cnt, 2, '.+ calls up inheritance hierarchy and all possible multis';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
106
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
107 $e.cnt = 0;
108 $e.+foo(2);
109 is $e.cnt, 3, '.+ calls up inheritance hierarchy and all possible multis';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
110
62e2e2f [t/spec]: Clean up (and unfudge) some tests involving Nil, sink, and un...
pmichaud authored
111 is $e.?foo("lol", "no", "match"), Nil, '.? when no possible multis gives Nil';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
112
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
113 my $lived = 0;
a0b5cce [t/spec] Tweaks to a test, in light of Num -> Rat for literals like 2.5....
jnthn authored
114 try { $e.+foo("lol", "no", "match"); $lived = 1; }
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
115 is $lived, 0, '.+ with no matching multis is an error';
116
a0b5cce [t/spec] Tweaks to a test, in light of Num -> Rat for literals like 2.5....
jnthn authored
117 is ($e.*foo("lol", "no", "match")).elems, 0, '.* when no possible multis gives empty list';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
118 }
119
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
120 # Some tests to make sure we walk methods from roles too.
121 role R1 {
122 multi method mm { $.cnt += 1 }
123 multi method sm { $.cnt += 2 }
124 }
125 role R2 {
126 multi method mm { $.cnt += 3 }
127 }
128 class F does R1 {
129 has $.cnt is rw;
130 }
131 class G is F does R2 {
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
132 }
133
134 {
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
135 my $g = G.new();
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
136
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
137 $g.cnt = 0;
138 $g.?sm();
139 is $g.cnt, 2, 'single dispatch method from role found with .?';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
140
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
141 $g.cnt = 0;
142 $g.+sm();
143 is $g.cnt, 2, 'single dispatch method from role found with .+';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
144
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
145 $g.cnt = 0;
146 $g.*sm();
147 is $g.cnt, 2, 'single dispatch method from role found with .*';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
148
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
149 $g.cnt = 0;
150 $g.?mm();
151 is $g.cnt, 3, 'multi dispatch method from role found with .?';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
152
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to separ...
jnthn authored
153 $g.cnt = 0;
154 $g.+mm();
155 is $g.cnt, 4, 'multi dispatch method from role found with .+';
156
157 $g.cnt = 0;
158 $g.*mm();
159 is $g.cnt, 4, 'multi dispatch method from role found with .*';
160 }
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
161
dca5723 [t/spec] Test for a bug Rakudo used to have that I just fixed; not sure ...
jnthn authored
162 class MMT1 {
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
163 multi method foo($x) { 42 } #OK not used
dca5723 [t/spec] Test for a bug Rakudo used to have that I just fixed; not sure ...
jnthn authored
164 }
165 class MMT2 is MMT1 {
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
166 multi method foo(Int $x) { "oh noes" } #OK not used
dca5723 [t/spec] Test for a bug Rakudo used to have that I just fixed; not sure ...
jnthn authored
167 }
168 is MMT2.new.?foo("lol"), 42, '.? when initial multi does not match will find next one up';
169
4c3f797 [t/spec] test for RT #72790: $obj.?nonexistent() should return Nil, not ...
moritz authored
170 {
171 my @list = MMT1.new.?nonexistent();
172 is +@list, 0, '.?nonexisent() returns Nil';
173 }
174
ec38923 @moritz test for 1.*WHAT (which is forbidden), RT #72818
moritz authored
175 eval_dies_ok '1.*WHAT', '.WHAT is a macro and cannoted be .*ed';
176
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S12-m...
Auzon authored
177 # vim: ft=perl6
Something went wrong with that request. Please try again.