Skip to content

Commit

Permalink
test that existing operators can be overloaded
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.pugscode.org/pugs@28124 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information
moritz committed Aug 30, 2009
1 parent 951cb96 commit 15e6240
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion S06-operator-overloading/sub.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 45;
plan 46;

=begin pod
Expand Down Expand Up @@ -302,4 +302,18 @@ Testing operator overloading subroutines
is $frew, 5, 'infix redefinition of += works';
}

{
class MMDTestType {
has $.a is rw;
method add(MMDTestType $b) { $.a ~ $b.a }
}

multi sub infix:<+>(MMDTestType $a, MMDTestType $b) { $a.add($b) };

my MMDTestType $a .= new(a=>'foo');
my MMDTestType $b .= new(a=>'bar');

is $a + $b, 'foobar', 'can overload exiting operators (here: infix:<+>)';
}

# vim: ft=perl6

0 comments on commit 15e6240

Please sign in to comment.