Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[t/nqp/53-multi-method.t] added
This one doesn't come from nqp-rx. It tests various aspects of proto and multi methods.
- Loading branch information
Carl Masak
committed
Nov 13, 2010
1 parent
24884a9
commit 355ceac
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #! nqp | ||
|
|
||
| plan(4); | ||
|
|
||
| class Foo { | ||
| proto method bar($x?) { * } | ||
| multi method bar() { 42 } | ||
| multi method bar($x) { 2 * $x } | ||
| } | ||
|
|
||
| my $x := Foo.new(); | ||
|
|
||
| if $x.bar() == 42 { | ||
| say("ok 1"); | ||
| } | ||
|
|
||
| if $x.bar(5) == 10 { | ||
| say("ok 2"); | ||
| } | ||
|
|
||
| class Baz is Foo { | ||
| multi method bar() { 37 } | ||
| } | ||
|
|
||
| my $y := Baz.new(); | ||
|
|
||
| say("ok 3 #SKIP invocant narrowness"); | ||
| #if $y.bar() == 37 { | ||
| # say("ok 3"); | ||
| #} | ||
|
|
||
| class Quux is Foo { | ||
| proto method bar() { * } | ||
| multi method bar() { 37 } | ||
| } | ||
|
|
||
| my $z := Quux.new(); | ||
|
|
||
| if $z.bar() == 37 { | ||
| say("ok 4"); | ||
| } |