Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 37 lines (27 sloc) 1.048 kb
1f4cbff [t/spec] Add tests for dispatch based upon literal values written in …
jnthn authored
1 use v6;
2
3 use Test;
4
5 plan 7;
6
7 # L<S06/Routine modifiers/>
8 # L<S06/Parameters and arguments/>
9
10 # Simple case.
11 {
12 multi m1("foo") { 1 }
13 multi m1("bar") { 2 }
14
15 is m1("foo"), 1, "literal Str in signature matches value correctly";
16 is m1("bar"), 2, "literal Str in signature matches value correctly";
17 dies_ok { m1("baz") }, "dies if no matching value even if type matches";
18 }
19
20 # More complex case. Here we check that the multis get the right narrowness,
21 # based upon the type of the literal, and are narrower than a candidate of
22 # the same type because they have constraints.
23 {
24 multi m2(1) { "a" }
25 multi m2(2) { "b" }
26 multi m2(Int $x) { "c" }
27 multi m2($x) { "d" }
28
29 is m2(1), "a", 'literal Int in signature matches value correctly';
30 is m2(2), "b", 'literal Int in signature matches value correctly';
31 is m2(3), "c", 'fallback to Int variant which is less narrow than constrained one';
32 is m2("x"), "d", 'if not an Int at all, fall back to Any candidate';
33 }
34
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
35
36 # vim: ft=perl6
Something went wrong with that request. Please try again.