Skip to content

Commit

Permalink
Update class-and-instance.t to add tests for class and instance
Browse files Browse the repository at this point in the history
only methods selected by invocant concreteness (eg ::?CLASS:[U|D]:).
GH roast issue #217.
  • Loading branch information
ronaldxs committed Apr 5, 2018
1 parent d9a4a65 commit 503021a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion S12-methods/class-and-instance.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ use v6;

use Test;

plan 8;
plan 12;

class Foo {
has $.foo-bonus;

method bar (Foo $class: $arg) { return 100 + $arg } #OK not used

# xor methods call either class or instance not both
multi method bar-Foo-xor (::?CLASS:U: $arg) { return 10 + $arg }
multi method bar-Foo-xor (::?CLASS:D: $arg) { return 20 + $arg }
method bar-Foo-named-instance (Foo:D $inst: $arg) {
return 20 + $inst.foo-bonus + $arg
}
}

{
Expand All @@ -25,6 +34,16 @@ class Foo {
is($val, 142, '... basic instance method access worked');
}

is(Foo.bar-Foo-xor(42), 52, 'multi method for class not instance');
is(Foo.new.bar-Foo-xor(42), 62, 'multi method for instance not class');
is( Foo.new(:25foo-bonus).bar-Foo-named-instance(42), 87,
'instance only method named invocant'
);
throws-like(
{ Foo.bar-Foo-named-instance(42) }, X::Parameter::InvalidConcreteness,
'correctly refused class invocant for instance only method'
);

class Act {
my method rules() { 'the world' }
our method rocks() { 'the house' }
Expand Down

0 comments on commit 503021a

Please sign in to comment.