Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 191 lines (151 sloc) 6.951 kb
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
1 use v6;
2 use Test;
d2482f41 » mberends
2010-08-22 replace plan *; with number of tests S03-S06
3 plan 51;
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
4
5 # type based dispatching
6 #
7 #L<S06/"Longname parameters">
8 #L<S12/"Multisubs and Multimethods">
9
1e12d97f » bbkr
2010-06-28 [t/spec/S06-multi/type-based.t] tests for RT #72750 Make Inf and NaN …
10 multi foo (5) { "Constant" }
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
11 multi foo (Int $bar) { "Int " ~ $bar }
12 multi foo (Str $bar) { "Str " ~ $bar }
38d86464 » jnthn
2010-02-09 [t/spec] Catch up on s/Num/Rat/ spec change for thingies like 1.4.
13 multi foo (Rat $bar) { "Rat " ~ $bar }
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
14 multi foo (Bool $bar) { "Bool " ~ $bar }
7d3cc6e4 » jnthn
2011-07-29 A couple of spec updates to S06-multi/syntax.t.
15 multi foo (Regex $bar) { "Regex " ~ gist(WHAT( $bar )) } # since Rule's don't stringify
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
16 multi foo (Sub $bar) { "Sub " ~ $bar() }
2ec15abc » ihrd
2009-08-24 [spec] tweak S06-multi/type-based.t tests comments to be correct
17 multi foo (@bar) { "Positional " ~ join(', ', @bar) }
18 multi foo (%bar) { "Associative " ~ join(', ', %bar.keys.sort) }
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
19 multi foo (IO $fh) { "IO" } #OK not used
1e12d97f » bbkr
2010-06-28 [t/spec/S06-multi/type-based.t] tests for RT #72750 Make Inf and NaN …
20 multi foo (Inf) { "Inf" }
21 multi foo (NaN) { "NaN" }
22
23 is foo(5), 'Constant', 'dispatched to the constant sub';
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
24
25 is(foo(2), 'Int 2', 'dispatched to the Int sub');
1e12d97f » bbkr
2010-06-28 [t/spec/S06-multi/type-based.t] tests for RT #72750 Make Inf and NaN …
26 is(foo('test'), 'Str test', 'dispatched to the Str sub');
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
27
28 my $num = '4';
38d86464 » jnthn
2010-02-09 [t/spec] Catch up on s/Num/Rat/ spec change for thingies like 1.4.
29 is(foo(1.4), 'Rat 1.4', 'dispatched to the Num sub');
672abda9 » moritz
2010-09-22 [type-based.t] fix another Bool stringification usage
30 is(foo(1 == 1), 'Bool ' ~ True, 'dispatched to the Bool sub');
a524b513 » pmichaud
2009-04-28 [t/spec]: protoobjects stringify to shortname plus parens (S12)
31 is(foo(/a/),'Regex Regex()','dispatched to the Rule sub');
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
32 is(foo(sub { 'baz' }), 'Sub baz', 'dispatched to the Sub sub');
33
34 my @array = ('foo', 'bar', 'baz');
2ec15abc » ihrd
2009-08-24 [spec] tweak S06-multi/type-based.t tests comments to be correct
35 is(foo(@array), 'Positional foo, bar, baz', 'dispatched to the Positional sub');
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
36
37 my %hash = ('foo' => 1, 'bar' => 2, 'baz' => 3);
2ec15abc » ihrd
2009-08-24 [spec] tweak S06-multi/type-based.t tests comments to be correct
38 is(foo(%hash), 'Associative bar, baz, foo', 'dispatched to the Associative sub');
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
39
40 is(foo($*ERR), 'IO', 'dispatched to the IO sub');
41
1e12d97f » bbkr
2010-06-28 [t/spec/S06-multi/type-based.t] tests for RT #72750 Make Inf and NaN …
42 is foo(Inf), 'Inf', 'dispatched to the Inf sub';
43 is foo(NaN), 'NaN', 'dispatched to the NaN sub';
44
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
45 # You're allowed to omit the "sub" when declaring a multi sub.
46 # L<S06/"Routine modifiers">
47
7be6b56c » jnthn
2010-07-15 [t/spec] wtf? How'd this end up as Multi, not multi? Corrected test.
48 multi declared_wo_sub (Int $x) { 1 } #OK not used
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
49 multi declared_wo_sub (Str $x) { 2 } #OK not used
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
50 is declared_wo_sub(42), 1, "omitting 'sub' when declaring 'multi sub's works (1)";
51 is declared_wo_sub("42"), 2, "omitting 'sub' when declaring 'multi sub's works (2)";
52
53 # Test for slurpy MMDs
7d3cc6e4 » jnthn
2011-07-29 A couple of spec updates to S06-multi/syntax.t.
54 proto mmd(*@) {} # L<S06/"Routine modifiers">
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
55 multi mmd () { 1 }
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
56 multi mmd (*$x, *@xs) { 2 } #OK not used
b9eb5913 » moritz
2008-07-27 [spec] moved blocks/multi_sub.t to spec/
57
58 is(mmd(), 1, 'Slurpy MMD to nullary');
59 is(mmd(1,2,3), 2, 'Slurpy MMD to listop via args');
60 is(mmd(1..3), 2, 'Slurpy MMD to listop via list');
61
3088a5a0 » moritz
2009-01-19 [t/spec] simple multi dispatch tests for sigil-implied type constraints
62 {
63 my %h = (:a<b>, :c<d>);
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
64 multi sub sigil-t (&code) { 'Callable' } #OK not used
65 multi sub sigil-t ($any) { 'Any' } #OK not used
66 multi sub sigil-t (@ary) { 'Positional' } #OK not used
67 multi sub sigil-t (%h) { 'Associative' } #OK not used
3088a5a0 » moritz
2009-01-19 [t/spec] simple multi dispatch tests for sigil-implied type constraints
68 is sigil-t(1), 'Any', 'Sigil-based dispatch (Any)';
69 is sigil-t({ $_ }), 'Callable', 'Sigil-based dispatch (Callable)';
70 is sigil-t(<a b c>), 'Positional','Sigil-based dispatch (Arrays)';
71 is sigil-t(%h), 'Associative','Sigil-based dispatch (Associative)';
72
73 }
7c332e4c » moritz
2009-02-17 [t/spec] tests for rt #63276
74
75 {
76
7d7a3a1e » lwall
2009-10-16 [type-based.t] supply missing Stone class, remove spurious semicolons
77 class Scissor { }
78 class Paper { }
79 class Stone { }
7c332e4c » moritz
2009-02-17 [t/spec] tests for rt #63276
80
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
81 multi wins(Scissor $x, Paper $y) { 1 } #OK not used
82 multi wins(::T $x, T $y) { 0 } #OK not used
83 multi wins($x, $y) { -1 } #OK not used
7c332e4c » moritz
2009-02-17 [t/spec] tests for rt #63276
84
85 is wins(Scissor.new, Paper.new), 1, 'Basic sanity';
86 is wins(Paper.new, Paper.new), 0, 'multi dispatch with ::T generics';
87 is wins(Paper.new, Scissor.new), -1, 'fallback if there is a ::T variant';
88
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
89 multi wins2(Scissor $x, Paper $y) { 1 } #OK not used
7d7a3a1e » lwall
2009-10-16 [type-based.t] supply missing Stone class, remove spurious semicolons
90 multi wins2($x, $y where { $x.WHAT eq $y.WHAT }) { 0 }
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
91 multi wins2($x, $y) { -1 } #OK not used
15faec1e » moritz
2010-05-07 fix a function call in S06-multi/type-based.t
92 is wins2(Scissor.new, Paper.new), 1, 'Basic sanity 2';
93 is wins2(Paper.new, Paper.new), 0, 'multi dispatch with faked generics';
94 is wins2(Paper.new, Scissor.new), -1, 'fallback if there is a faked generic';
c3d70da2 » moritz
2009-10-15 [t/spec] tests for RT #69798
95
96 # now try again with anonymous parameters (see RT #69798)
97 multi wins_anon(Scissor $, Paper $) { 1 }
98 multi wins_anon(Paper $, Stone $) { 1 }
99 multi wins_anon(Stone $, Scissor $) { 1 }
100 multi wins_anon(::T $, T $) { 0 }
101 multi wins_anon( $, $) { -1 }
102
103 is wins_anon(Scissor, Paper), 1, 'MMD with anonymous parameters (1)';
104 is wins_anon(Paper, Paper), 0, 'MMD with anonymous parameters (2)';
105 is wins_anon(Stone, Paper), -1, 'MMD with anonymous parameters (3)';
106
0dcb2aab » moritz
2009-02-17 [t/spec] simple tests for multis and subset types, bacek++
107 }
108
c3d70da2 » moritz
2009-10-15 [t/spec] tests for RT #69798
109
0dcb2aab » moritz
2009-02-17 [t/spec] simple tests for multis and subset types, bacek++
110 {
7d7a3a1e » lwall
2009-10-16 [type-based.t] supply missing Stone class, remove spurious semicolons
111 multi m($x,$y where { $x==$y }) { 0 }
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
112 multi m($x,$y) { 1 } #OK not used
7c332e4c » moritz
2009-02-17 [t/spec] tests for rt #63276
113
0dcb2aab » moritz
2009-02-17 [t/spec] simple tests for multis and subset types, bacek++
114 is m(2, 3), 1, 'subset types involving mulitple parameters (fallback)';
115 is m(1, 1), 0, 'subset types involving mulitple parameters (success)';
7c332e4c » moritz
2009-02-17 [t/spec] tests for rt #63276
116 }
117
502162b2 » moritz
2009-03-04 [t/spec] exercise bare "oh I feel so Haskell" sigils in signatures
118 {
7d7a3a1e » lwall
2009-10-16 [type-based.t] supply missing Stone class, remove spurious semicolons
119 multi f2 ($) { 1 }
120 multi f2 ($, $) { 2 }
121 multi f2 ($, $, $) { 3 }
122 multi f2 ($, $, @) { '3+' }
502162b2 » moritz
2009-03-04 [t/spec] exercise bare "oh I feel so Haskell" sigils in signatures
123 is f2(3), 1, 'arity-based dispatch to ($)';
124 is f2('foo', f2(3)), 2, 'arity-based dispatch to ($, $)';
125 is f2('foo', 4, 8), 3, 'arity-based dispatch to ($, $, $)';
126 is f2('foo', 4, <a b>), '3+', 'arity-based dispatch to ($, $, @)';
127 }
128
129 {
7d7a3a1e » lwall
2009-10-16 [type-based.t] supply missing Stone class, remove spurious semicolons
130 multi f3 ($ where 0 ) { 1 }
131 multi f3 ($x) { $x + 1 }
502162b2 » moritz
2009-03-04 [t/spec] exercise bare "oh I feel so Haskell" sigils in signatures
132 is f3(0), 1, 'can dispatch to "$ where 0"';
133 is f3(3), 4, '... and the ordinary dispatch still works';
134 }
7c332e4c » moritz
2009-02-17 [t/spec] tests for rt #63276
135
8854e887 » moritz
2009-06-12 [t/spec] RT #65674, multi subs in classes
136 # multi dispatch on typed containers
e39b7449 » jnthn
2010-02-16 [t/spec] Re-fudging of various multi-dispatch tests; we handle the ma…
137 #?rakudo skip 'typed array and hash containers are NYI'
5e0b5ea2 » moritz
2009-04-08 [t/spec] basic tests for dispatch on typed arrays
138 {
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
139 multi f4 (Int @a ) { 'Array of Int' } #OK not used
140 multi f4 (Str @a ) { 'Array of Str' } #OK not used
141 multi f4 (Array @a) { 'Array of Array' } #OK not used
142 multi f4 (Int %a) { 'Hash of Int' } #OK not used
143 multi f4 (Str %a) { 'Hash of Str' } #OK not used
144 multi f4 (Array %a) { 'Hash of Array' } #OK not used
5e0b5ea2 » moritz
2009-04-08 [t/spec] basic tests for dispatch on typed arrays
145
146 my Int @a = 3, 4;
147 my Str @b = <foo bar>;
148 my Array @c = [1, 2], [3, 4];
149
fb132dd7 » moritz
2009-04-08 [t/spec] add (failing) tests for dispatch on typed hashes
150 my Int %a = a => 1, b => 2;
151 my Str %b = :a<b>, :b<c>;
152 my Array %c = a => [1, 2], b => [3, 4];
153
154 is f4(%a), 'Hash of Int', 'can dispatch on typed Hash (Int)';
155 is f4(%b), 'Hash of Str', 'can dispatch on typed Hash (Str)';
156 is f4(%c), 'Hash of Array', 'can dispatch on typed Hash (Array)';
157
158 is f4(@a), 'Array of Int', 'can dispatch on typed Array (Int)';
159 is f4(@b), 'Array of Str', 'can dispatch on typed Array (Str)';
160 is f4(@c), 'Array of Array', 'can dispatch on typed Array (Array)';
5e0b5ea2 » moritz
2009-04-08 [t/spec] basic tests for dispatch on typed arrays
161 }
162
8854e887 » moritz
2009-06-12 [t/spec] RT #65674, multi subs in classes
163 # make sure that multi sub dispatch also works if the sub is defined
164 # in a class (was a Rakudo regression, RT #65674)
165
166 {
167 class A {
9dee84a5 » jnthn
2010-04-04 [t/spec] Happy our again!
168 our multi sub a(Int $x) { 'Int ' ~ $x }
169 our multi sub a(Str $x) { 'Str ' ~ $x }
8854e887 » moritz
2009-06-12 [t/spec] RT #65674, multi subs in classes
170 }
171
172 is A::a(3), 'Int 3', 'multis in classes (1)';
173 is A::a('f'), 'Str f', 'multis in classes (2)';
174 dies_ok { A::a([4, 5]) }, 'multis in classes (3)';
175 }
5e0b5ea2 » moritz
2009-04-08 [t/spec] basic tests for dispatch on typed arrays
176
8bddfc69 » kyle
2009-07-03 [t/spec] Added a few tests I don't completely understand based on an IRC
177 {
7d7a3a1e » lwall
2009-10-16 [type-based.t] supply missing Stone class, remove spurious semicolons
178 multi x(@a, @b where { @a.elems == @b.elems }) { 1 }
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
179 multi x(@a, @b) { 2 } #OK not used
9c826fdd » moritz
2009-07-05 [t/spec] more test descriptions
180 is x([1,2],[3,4]), 1, 'where-clause that uses multiple params (1)';
181 is x([1],[2,3,4]), 2, 'where-clause that uses multiple params (1)';
8bddfc69 » kyle
2009-07-03 [t/spec] Added a few tests I don't completely understand based on an IRC
182
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
183 multi y(::T $x, T $y) { 1 } #OK not used
184 multi y($x, $y) { 2 } #OK not used
9c826fdd » moritz
2009-07-05 [t/spec] more test descriptions
185 is y(1, 2), 1, 'generics in multis (+)';
186 is y(1, 2.5), 2, 'generics in multis (-)';
8bddfc69 » kyle
2009-07-03 [t/spec] Added a few tests I don't completely understand based on an IRC
187 }
188
e76dd4c7 » moritz
2010-12-31 s/done_testing/done/ as per recent S24 changes
189 done;
c3d70da2 » moritz
2009-10-15 [t/spec] tests for RT #69798
190
7c332e4c » moritz
2009-02-17 [t/spec] tests for rt #63276
191 # vim: ft=perl6
Something went wrong with that request. Please try again.