Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 41 lines (31 sloc) 1.446 kb
07d2c53 [t/spec] Add some tests for multi-dispatch based on unpackability
duff authored
1 use v6;
2 use Test;
a288e1f Moritz Lenz RT #76486
moritz authored
3 plan 10;
07d2c53 [t/spec] Add some tests for multi-dispatch based on unpackability
duff authored
4
5 # L<S12/"Multisubs and Multimethods">
6 # L<S06/Unpacking array parameters>
7
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
8 multi sub foo ([$a]) { return "one" } #OK not used
9 multi sub foo ([$a,$b]) { return "two" } #OK not used
10 multi sub foo ([$a,$b,$c]) { return "three" } #OK not used
11 multi sub foo (*[$a,$b,$c,$d]) { return "four" } #OK not used
07d2c53 [t/spec] Add some tests for multi-dispatch based on unpackability
duff authored
12
13 my @a = (1);
14 my @b = (1,2);
15 my @c = (1,2,3);
16 my @d = (1,2,3,4);
17
18 is foo(@a), "one", "multi dispatch on array packed with one element";
19 is foo(@b), "two", "multi dispatch on array packed with two elements";
20 is foo(@c), "three", "multi dispatch on array packed with three elements";
21 is foo(@d), "four", "multi dispatch on array packed with four elements";
22 is foo(1,2,3,4), "four", "multi dispatch on slurpy packed with four elements";
23
68d409b Jonathan Worthington Update a test to match current spec on type object stringification.
jnthn authored
24 multi sub bar ([$a,$b?]) { return "$a|$b.gist()" }
07d2c53 [t/spec] Add some tests for multi-dispatch based on unpackability
duff authored
25 multi sub bar (*[$a,$b,$c?]) { return "$a+$b+$c" }
26
0512ff9 Moritz Lenz more Type() -> (Type) gistification
moritz authored
27 is bar(@a), "1|(Any)", "multi dispatch on array packed with one required element + no optional";
07d2c53 [t/spec] Add some tests for multi-dispatch based on unpackability
duff authored
28 is bar(@b), "1|2", "multi dispatch on array packed with one required element + one optional";
29 is bar(1,2,3), "1+2+3", "multi dispatch on slurpy packed with two required element + one optional";
a288e1f Moritz Lenz RT #76486
moritz authored
30
31 # RT #76486
32 {
33 multi sub a(@a) { 1 ~ @a }
34 multi sub a([]) { 2 ~ [] }
35 my @t = 1,2;
36
37 is a([]), '2', 'Multi-dispatch descends into sub signatures (1)';
38 is a(@t), '11 2', 'Multi-dispatch descends into sub signatures (2)';
39
40 }
Something went wrong with that request. Please try again.