Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Replace old multi-dispatch tests. Multi-method dispatch is now in a s…
Browse files Browse the repository at this point in the history
…eparate test file, added yesterday. 51-multi.t will now just test multi subs. Needs more tests, but does cover arity based dispatch and that the proto functions as it should - being called first then delegating to the multi-dispatcher.
  • Loading branch information
jnthn committed Jan 16, 2011
1 parent c759804 commit 46a10cd
Showing 1 changed file with 13 additions and 49 deletions.
62 changes: 13 additions & 49 deletions t/nqp/51-multi.t
@@ -1,49 +1,13 @@
#! nqp

say("1..7");

our multi sub foo(Float $f) {
say("ok 1");
}

our multi sub foo(NQP::Grammar $f) {
say("ok 2");
}

our multi sub foo($def) {
say($def);
}

foo(42.01);
foo(NQP::Grammar.new);
foo("ok 3");

class Foo {
our multi method bar(Float $f) {
say("ok 4");
};

our multi method bar($f) {
say($f);
};
};

my $f := Foo.new;
$f.bar(43.5 - 0.5);
$f.bar("ok 5");


class Bar {
our multi method foo($x, :$opt?) {
say($x);
}

our multi method foo(Float $x, :$opt?) {
say("ok 6");
}
}

my $b := Bar.new;
$b.foo(43.5 - 0.5);
$b.foo("ok 7");

plan(4);

proto foo($a, $b?) { * }
multi foo($a) { 1 }
multi foo($a, $b) { 2 }
ok(foo('omg') == 1);
ok(foo('omg', 'wtf') == 2);

proto bar($a?) { 'omg' ~ {*} ~ 'bbq' }
multi bar() { 'wtf' }
multi bar($a) { 'lol' }
ok(bar() eq 'omgwtfbbq');
ok(bar(42) eq 'omglolbbq');

0 comments on commit 46a10cd

Please sign in to comment.