Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 133 lines (110 sloc) 4.802 kb
972003e8 » jnthn
2008-07-26 [spectest] Add some tests for various bits of the multi sub syntax.
1 use v6;
2
3 use Test;
4
f30f0d53 » moritz
2010-07-16 [t/spec] tests for RT #75136: declaring a multi just returns the curr…
5 plan *;
972003e8 » jnthn
2008-07-26 [spectest] Add some tests for various bits of the multi sub syntax.
6
c2f8fec1 » moritz
2008-12-14 [t] and [t/spec] (two train travels worth of changes):
7 # L<S06/Routine modifiers/>
8 # L<S06/Parameters and arguments/>
9
972003e8 » jnthn
2008-07-26 [spectest] Add some tests for various bits of the multi sub syntax.
10 # multi sub with signature
11 multi sub foo() { "empty" }
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
12 multi sub foo($a) { "one" } #OK not used
972003e8 » jnthn
2008-07-26 [spectest] Add some tests for various bits of the multi sub syntax.
13 is(foo(), "empty", "multi sub with empty signature");
14 is(foo(42), "one", "multi sub with parameter list");
15
16 # multi sub without signature
17 multi sub bar { "empty" }
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
18 multi sub bar($a) { "one" } #OK not used
972003e8 » jnthn
2008-07-26 [spectest] Add some tests for various bits of the multi sub syntax.
19 is(bar(), "empty", "multi sub with no signature");
20 is(bar(42), "one", "multi sub with parameter list");
21
22 # multi without a routine type
23 multi baz { "empty" }
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
24 multi baz($a) { "one" } #OK not used
972003e8 » jnthn
2008-07-26 [spectest] Add some tests for various bits of the multi sub syntax.
25 is(baz(), "empty", "multi with no signature");
26 is(baz(42), "one", "multi with parameter list");
d329ac84 » jnthn
2008-12-10 [t/spec] Add a test for the ;; syntax.
27
28 # multi with some parameters not counting in dispatch (;;) - note that if the
1e2c1f07 » Util
2009-10-09 [t/spec] 11 typos in 6 files.
29 # second parameter is counted as part of the dispatch, then invoking with 2
d329ac84 » jnthn
2008-12-10 [t/spec] Add a test for the ;; syntax.
30 # ints means they are tied candidates as one isn't narrower than the other.
31 # (Note Int is narrower than Num - any two types where one is narrower than
32 # the other will do it, though.)
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
33 multi foo(Int $a, Num $b) { 1 } #OK not used
34 multi foo(Num $a, Int $b) { 2 } #OK not used
35 multi bar(Int $a;; Num $b) { 1 } #OK not used
36 multi bar(Num $a;; Int $b) { 2 } #OK not used
d329ac84 » jnthn
2008-12-10 [t/spec] Add a test for the ;; syntax.
37 my $lived = 0;
38 try { foo(1,1); $lived = 1 }
39 is($lived, 0, "dispatch tied as expected");
40 is(bar(1,1), 1, "not tied as only first type in the dispatch");
d9ac4d66 » jnthn
2008-12-10 [rakudo] Tests to make sure that declaring anonymous routines with on…
41
42 # not allowed to declare anonymous routines with only, multi or proto.
ae475457 » moritz
2008-12-10 [t/spec] fix plan in S06-multi/syntax.t; use eval_dies_ok for terser …
43 eval_dies_ok 'only sub {}', 'anonymous only sub is an error';
44 eval_dies_ok 'multi sub {}', 'anonymous multi sub is an error';
45 eval_dies_ok 'proto sub {}', 'anonymous proto sub is an error';
46 eval_dies_ok 'only {}', 'anonymous only is an error';
47 eval_dies_ok 'multi {}', 'anonymous multi is an error';
48 eval_dies_ok 'proto {}', 'anonymous proto is an error';
49 eval_dies_ok 'class A { only method {} }', 'anonymous only method is an error';
50 eval_dies_ok 'class B { multi method {} }', 'anonymous multi method is an error';
51 eval_dies_ok 'class C { proto method {} }', 'anonymous proto method is an error';
d5356479 » jnthn
2009-03-13 [t/spec] Test for .WHAT on a multi.
52
2970d761 » lwall
2009-05-02 [syntax.t] relax isa Multi to ~~ Multi
53 ok(&foo ~~ Multi, 'a multi does Multi');
71ee4480 » kyle
2009-10-26 [t/spec] Tests for RT #65672, multi does Callable
54 ok(&foo ~~ Callable, 'a multi does Callable');
96e97df4 » jnthn
2010-02-09 [t/spec] Generalize a test I 'corrected' a couple of days back.
55 ok(~&foo ~~ /foo/, 'a multi stringifies sensibly');
992bbb15 » ron
2009-04-26 add test for override of builtin, RT 58948
56
c15d1cfe » masak
2009-05-01 [t/spec/S06-multi/syntax.t] unfudged two tests
57 # note - example in ticket [perl #58948] a bit more elaborate
7d5f283a » ron
2009-04-27 improve testing for mmd builtin override RT #58948
58 {
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
59 multi sub max($a, $b, $c) {return 9} #OK not used
7d5f283a » ron
2009-04-27 improve testing for mmd builtin override RT #58948
60
285bebe9 » jnthn
2010-02-08 [t/spec] Corrections and an unfudging for a multi test.
61 lives_ok { max(1, 2, 3) }, 'use multi method to override builtin lives';
7d5f283a » ron
2009-04-27 improve testing for mmd builtin override RT #58948
62 is eval('max(1, 2, 3)'), 9, 'use multi method to override builtin';
63 }
692c4173 » jnthn
2009-05-20 [t/spec] Several tests to cover a couple of now-resolved RT tickets.
64
65 # named and slurpy interaction - there have been bugs in the past on this front
66 {
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
67 multi nsi_1(Int $x, Bool :$flag, *@vals) { "nsi 1" }; #OK not used
692c4173 » jnthn
2009-05-20 [t/spec] Several tests to cover a couple of now-resolved RT tickets.
68 is nsi_1(1), 'nsi 1', 'interaction between named and slurpy (1)';
69 is nsi_1(1, 2, 3, 4, 5), 'nsi 1', 'interaction between named and slurpy (2)';
70
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
71 multi nsi_2(Bool :$baz = Bool::False, *@vals) { "nsi 2" }; #OK not used
692c4173 » jnthn
2009-05-20 [t/spec] Several tests to cover a couple of now-resolved RT tickets.
72 is nsi_2(:baz(Bool::True), 1, 2, 3), 'nsi 2', 'interaction between named and slurpy (3)';
73 is nsi_2(1, 2, 3), 'nsi 2', 'interaction between named and slurpy (4)';
74 }
7f29bc53 » kyle
2009-08-08 [t/spec] Add vim: lines everywhere.
75
aa7a0097 » kyle
2009-08-10 [t/spec] Test for RT #68234
76 # RT #68234
77 {
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
78 multi rt68234(:$key!) { 'with key' }; #OK not used
79 multi rt68234(*%_) { 'unknown' }; #OK not used
aa7a0097 » kyle
2009-08-10 [t/spec] Test for RT #68234
80 is rt68234(:key), 'with key', 'can find multi method with key';
81 #?rakudo skip 'RT #68234'
82 is rt68234(:unknown), 'unknown', 'can find multi method with slurpy';
83 }
84
7dc19f98 » jnthn
2009-08-19 [t/spec] Tests for a copule of arity based multi-dispatch bugs.
85 # RT #68158
86 {
87 multi rt68158() { 1 }
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
88 multi rt68158(*@x) { 2 } #OK not used
7dc19f98 » jnthn
2009-08-19 [t/spec] Tests for a copule of arity based multi-dispatch bugs.
89 is rt68158(), 1, 'non-slurpy wins over slurpy';
90 is rt68158(9), 2, 'slurpy called when non-slurpy can not bind';
91 }
92
93 # RT #64922
94 {
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
95 multi rt64922($x, %h?) { 1 } #OK not used
96 multi rt64922(@x) { 2 } #OK not used
7dc19f98 » jnthn
2009-08-19 [t/spec] Tests for a copule of arity based multi-dispatch bugs.
97 is rt64922(1), 1, 'optional parameter does not break type-based candidate sorting';
98 is rt64922([1,2]), 2, 'optional parameter does not break type-based candidate sorting';
99 }
100
71ee4480 » kyle
2009-10-26 [t/spec] Tests for RT #65672, multi does Callable
101 # RT #65672
102 {
103 multi rt65672() { 99 }
104 multi rt65672($x) { $x }
105 sub rt65672caller( &x ) { &x() }
106 is rt65672caller( &rt65672 ), 99, 'multi can be passed as callable';
107 }
108
fa251bae » jnthn
2010-06-05 [t/spec] Add a test for the multi leakage but I accidentally in the R…
109 # We had a bug where the multiness leaked into a sub, so we got errors
110 # about anonymous methods not being allowed to be multi.
111 {
112 multi sub kangaroo() { return method () { self * 2 } }
113 my $m = kangaroo();
114 is 21.$m(), 42, 'can write anonymous methods inside multi subs';
115 }
116
f30f0d53 » moritz
2010-07-16 [t/spec] tests for RT #75136: declaring a multi just returns the curr…
117
118 # RT #75136
119 # a multi declaration should only return the current candidate, not the whole
120 # set of candidates.
121 {
122 multi sub koala(Int $x) { 42 * $x };
123
124 my $x = multi sub koala(Str $x) { 42 ~ $x }
125 is $x.candidates.elems,
126 1, 'multi sub declaration returns just the current candidate';
127 is $x('moep'), '42moep', 'and that candidate works';
128 dies_ok { $x(23) }, '... and does not contain the full multiness';
129 }
130
71ee4480 » kyle
2009-10-26 [t/spec] Tests for RT #65672, multi does Callable
131 done_testing;
132
7f29bc53 » kyle
2009-08-08 [t/spec] Add vim: lines everywhere.
133 # vim: ft=perl6
Something went wrong with that request. Please try again.