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

Add a test for possible overriding of delegated methods #728

Open
wants to merge 1 commit 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
26 changes: 24 additions & 2 deletions S12-attributes/delegation.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 65;
plan 68;

=begin desc

Expand Down Expand Up @@ -108,7 +108,7 @@ class PairTest {
{
class ReFrontend { has $.backend is rw handles /^hi|oo/ };
ok ReFrontend.new, "class definition using a smartmatch handle worked";

{
my $a;
ok ($a = ReFrontend.new), "basic instantiation worked (3)";
Expand Down Expand Up @@ -202,4 +202,26 @@ class PairTest {
dies-ok { $a.d() }, '... but non existing methods still die';
}

# A class must be able to override a delegated method.
eval-lives-ok q:to/CODE/, "class overrides a delegated method";
role R {
has $.backend handles <Str Int>;
}
class C does R {
method Str { "class C" }
}
CODE

{ # As long as the previous test succeeds, make sure we do override the delegated method.
my role ROverridable {
has $.backend handles <hi cool>;
}
my class Overrider does ROverridable {
method hi { "class C" }
}
my $a = Overrider.new(backend => Backend1.new);
is $a.hi, 'class C', "backend method overriden";
is $a.cool, 1337, "un-overriden backend method is intact";
}

# vim: expandtab shiftwidth=4