Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test to exercise sequentially resolved multis (See issue #765) #766

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions S12-subset/multi-sequential.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use v6;
use Test;
use lib $?FILE.IO.parent(2).add("packages/Test-Helpers");
use Test::Util;

=begin description

Tests the cases where multi-dispatch is resolved sequentially (e.g. ambiguous subsets/where clauses)

=end description

# L<S12/"Types and Subtypes">

plan 2;

# https://github.com/Raku/roast/issues/7651
group-of 2 => 'ambiguous subset matches resolved sequentially' => {
# note: godzilla is both a monster and a hero
subset Monster of Str where { $_ eq any( <godzilla gammera ghidra golem> ) };
subset Hero of Str where { $_ eq any( <godzilla beowulf ultraman inframan> ) };

group-of 2 => 'two multis based on subsets' => {
multi sub classify (Monster $name) {
return "$name is a monster";
}
multi sub classify (Hero $name) {
return "$name is a hero";
}
is( classify('ultraman'), "ultraman is a hero",
"Testing that the multi with the only subset match runs.");
is( classify('godzilla'), "godzilla is a monster",
"Testing ambiguous case runs first multi that matches.");
}
group-of 2 => 'two multis reversed' => {
# here the same multis are defined in a different order
multi sub classify (Hero $name) {
return "$name is a hero";
}
multi sub classify (Monster $name) {
return "$name is a monster";
}
is( classify('ultraman'), "ultraman is a hero",
"Testing that the multi with the only subset match runs.");
is( classify('godzilla'), "godzilla is a hero",
"Testing ambiguous case runs first multi that matches.");
}
}


group-of 1 => 'negative case' => {
multi sub classify (Hero $name) {
return "$name is a hero";
}
throws-like { classify('doris_day') }, Exception,
"Testing that disallowed strings throw exceptions.";
}