Skip to content
Newer
Older
100644 162 lines (125 sloc) 4.39 KB
85bbd8d @lizmat Add use v6 where appropriate
lizmat authored Feb 24, 2016
1 use v6;
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
2 use Test;
0c0b0a1 @jnthn Tests codifying decision on RT #119193.
jnthn authored Nov 19, 2015
3 plan 38;
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
4
5 # L<S12/"Calling sets of methods">
6
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
7 # Some basic tests with only single-dispatch in operation.
8 class A {
9 has $.cnt is rw;
10 method foo { $.cnt += 4 }
11 }
12 class B is A {
13 method foo { $.cnt += 2 }
14 }
15 class C is B {
16 method foo { $.cnt += 1 }
17 }
18
19 {
20 my $c = C.new();
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
21
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
22 $c.cnt = 0;
23 $c.?foo();
24 is $c.cnt, 1, '.? calls first matching method';
dfc18a4 [t] more system, require, does, defer, label cleanup
lwall authored Sep 2, 2008
25
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
26 $c.cnt = 0;
27 $c.*foo();
28 is $c.cnt, 7, '.* calls up inheritance hierarchy';
dfc18a4 [t] more system, require, does, defer, label cleanup
lwall authored Sep 2, 2008
29
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
30 $c.cnt = 0;
31 $c.+foo();
32 is $c.cnt, 7, '.+ calls up inheritance hierarchy';
33
62e2e2f [t/spec]: Clean up (and unfudge) some tests involving Nil, sink, and …
pmichaud authored Jun 26, 2010
34 is $c.?bar(), Nil, '.? on undefined method gives Nil';
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
35
36 my $lived = 0;
37 try { $c.+bar(); $lived = 1; }
38 is $lived, 0, '.+ on undefined method is an error';
39
a87fde4 @lizmat s/is_deeply/is-deeply/g
lizmat authored May 19, 2015
40 is-deeply $c.*bar(), (), '.* on undefined method gives Nil';
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
41
42 my $foo = "foo";
43
44 $c.cnt = 0;
45 $c.?"$foo"();
46 is $c.cnt, 1, '.? with dynamic method name';
47
48 $c.cnt = 0;
49 $c.*"$foo"();
50 is $c.cnt, 7, '.* with dynamic method name';
51
52 $c.cnt = 0;
53 $c.+"$foo"();
54 is $c.cnt, 7, '.+ with dynamic method name';
55
709e414 @lizmat s/dies_ok/dies-ok/g
lizmat authored May 19, 2015
56 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 se…
jnthn authored Dec 9, 2008
57
709e414 @lizmat s/dies_ok/dies-ok/g
lizmat authored May 19, 2015
58 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 se…
jnthn authored Dec 9, 2008
59
709e414 @lizmat s/dies_ok/dies-ok/g
lizmat authored May 19, 2015
60 dies-ok { $c."*foo"() }, '* at start of dynamic name does not imply .*';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
61 }
62
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
63
0c0b0a1 @jnthn Tests codifying decision on RT #119193.
jnthn authored Nov 19, 2015
64 # Some tests involiving .?, .+ and .* with multi-methods. Since .+ and
65 # .* are only about single dispatch, then we end up calling the proto
66 # available at each inheritance level.
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
67 class D {
0c0b0a1 @jnthn Tests codifying decision on RT #119193.
jnthn authored Nov 19, 2015
68 multi method foo() { 'd' }
69 multi method foo(Int $x) { 'dInt' } #OK not used
70 multi method foo($x) { 'dAny' } #OK not used
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
71 }
72 class E is D {
0c0b0a1 @jnthn Tests codifying decision on RT #119193.
jnthn authored Nov 19, 2015
73 multi method foo() { 'e' }
74 multi method foo(Int $x) { 'eInt' } #OK not used
75 multi method foo($x, $y, $z) { 'eAnyAnyAny' } #OK not used
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
76 }
77
0c0b0a1 @jnthn Tests codifying decision on RT #119193.
jnthn authored Nov 19, 2015
78 # RT #119193
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
79 {
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
80 my $e = E.new();
81
0c0b0a1 @jnthn Tests codifying decision on RT #119193.
jnthn authored Nov 19, 2015
82 is $e.foo(), 'e', 'dispatch to one sanity test';
83 is $e.foo(2.5), 'dAny', 'dispatch to one inherited sanity test';
84 dies-ok { $e.foo('omg', 'fail') }, 'dispatch to one with no matching multi (sanity test)';
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
85
0c0b0a1 @jnthn Tests codifying decision on RT #119193.
jnthn authored Nov 19, 2015
86 is $e.?foo(), 'e', '.? gets same result as . if there is a multi (match)';
87 is $e.?foo(2.5), 'dAny', '.? gets same result as . if there is a multi (inherited)';
88 dies-ok { is $e.?foo('omg', 'fail') }, '.? gets same result as . if there is a multi (no match)';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
89
0c0b0a1 @jnthn Tests codifying decision on RT #119193.
jnthn authored Nov 19, 2015
90 is $e.*foo(), <e d>, '.* calls multis up inheritance hierarchy';
91 is $e.*foo(2.5), <dAny dAny>, '.* behaves as single dispatch at each step';
92 dies-ok { $e.*foo(1, 2, 3) }, '.* dies if there is no matching multi in a base class';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
93
0c0b0a1 @jnthn Tests codifying decision on RT #119193.
jnthn authored Nov 19, 2015
94 is $e.*foo(), <e d>, '.* calls multis up inheritance hierarchy';
95 is $e.*foo(2.5), <dAny dAny>, '.* behaves as single dispatch at each step';
96 dies-ok { $e.*foo(Mu) }, '.* dies if there is no matching multi in subclass';
97 dies-ok { $e.*foo(1, 2, 3) }, '.* dies if there is no matching multi in a base class';
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
98
0c0b0a1 @jnthn Tests codifying decision on RT #119193.
jnthn authored Nov 19, 2015
99 is $e.+foo(), <e d>, '.* calls multis up inheritance hierarchy';
100 is $e.+foo(2.5), <dAny dAny>, '.* behaves as single dispatch at each step';
101 dies-ok { $e.+foo(Mu) }, '.* dies if there is no matching multi in subclass';
102 dies-ok { $e.+foo(1, 2, 3) }, '.* dies if there is no matching multi in a base class';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
103 }
104
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
105 # Some tests to make sure we walk methods from roles too.
106 role R1 {
107 multi method mm { $.cnt += 1 }
108 multi method sm { $.cnt += 2 }
109 }
110 role R2 {
111 multi method mm { $.cnt += 3 }
112 }
113 class F does R1 {
114 has $.cnt is rw;
115 }
116 class G is F does R2 {
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
117 }
118
119 {
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
120 my $g = G.new();
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
121
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
122 $g.cnt = 0;
123 $g.?sm();
124 is $g.cnt, 2, 'single dispatch method from role found with .?';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
125
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
126 $g.cnt = 0;
127 $g.+sm();
128 is $g.cnt, 2, 'single dispatch method from role found with .+';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
129
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
130 $g.cnt = 0;
131 $g.*sm();
132 is $g.cnt, 2, 'single dispatch method from role found with .*';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
133
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
134 $g.cnt = 0;
135 $g.?mm();
136 is $g.cnt, 3, 'multi dispatch method from role found with .?';
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
137
267f966 [t/spec] Completely re-work the calling sets tests, allowing us to se…
jnthn authored Dec 9, 2008
138 $g.cnt = 0;
139 $g.+mm();
140 is $g.cnt, 4, 'multi dispatch method from role found with .+';
141
142 $g.cnt = 0;
143 $g.*mm();
144 is $g.cnt, 4, 'multi dispatch method from role found with .*';
145 }
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
146
dca5723 [t/spec] Test for a bug Rakudo used to have that I just fixed; not su…
jnthn authored Aug 14, 2009
147 class MMT1 {
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored Jul 15, 2010
148 multi method foo($x) { 42 } #OK not used
dca5723 [t/spec] Test for a bug Rakudo used to have that I just fixed; not su…
jnthn authored Aug 14, 2009
149 }
150 class MMT2 is MMT1 {
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored Jul 15, 2010
151 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 su…
jnthn authored Aug 14, 2009
152 }
153 is MMT2.new.?foo("lol"), 42, '.? when initial multi does not match will find next one up';
154
4c3f797 [t/spec] test for RT #72790: $obj.?nonexistent() should return Nil, n…
moritz authored Feb 28, 2010
155 {
9f658bf @stmuk fix some more RAKUDO_DEPRECATIONS_FATAL=1
stmuk authored Jun 30, 2015
156 isa-ok MMT1.new.?nonexistent(), Nil, '.?nonexisent() returns Nil';
4c3f797 [t/spec] test for RT #72790: $obj.?nonexistent() should return Nil, n…
moritz authored Feb 28, 2010
157 }
158
19c27b7 @jnthn Expect Exception, not X::AdHoc.
jnthn authored Nov 12, 2015
159 throws-like '1.*WHAT', Exception, '.WHAT is a macro and cannoted be .*ed';
ec38923 @moritz test for 1.*WHAT (which is forbidden), RT #72818
moritz authored Sep 26, 2011
160
20243dc [gsoc_spectest] new tests for lastcall. moved calling_sets to spec/S1…
Auzon authored Jun 15, 2008
161 # vim: ft=perl6
Something went wrong with that request. Please try again.