Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
port a few trait tests to the new spec
  • Loading branch information
moritz committed Oct 1, 2011
1 parent 01db9ce commit 3f79756
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions S14-traits/routines.t
Expand Up @@ -4,44 +4,46 @@ use Test;

# L<S14/Traits/>

role description {
has $.description is rw;
}
#?rakudo skip 'role(attrib) initialization'
{
role description {
has $.description is rw;
}

multi trait_mod:<is>(Routine $code, description, $arg) {
$code does description($arg);
}
multi trait_mod:<is>(Routine $code, description) {
$code does description("missing description!");
}
multi trait_mod:<is>(Routine $code, $arg, :$described!) {
$code does description($arg);
}
multi trait_mod:<is>(Routine $code, :$described!) {
$code does description("missing description!");
}
multi trait_mod:<is>(Routine $code, $arg, :$description! {
$code does description($arg);
}
multi trait_mod:<is>(Routine $code, :$description!) {
$code does description("missing description!");
}
multi trait_mod:<is>(Routine $code, $arg, :$described!) {
$code does description($arg);
}
multi trait_mod:<is>(Routine $code, :$described!) {
$code does description("missing description!");
}


sub answer() is description('computes the answer') { 42 }
sub faildoc() is description { "fail" }
is answer(), 42, 'can call sub that has had a trait applied to it by role name with arg';
is &answer.description, 'computes the answer', 'description role applied and set with argument';
is faildoc(), "fail", 'can call sub that has had a trait applied to it by role name without arg';
is &faildoc.description, 'missing description!', 'description role applied without argument';
sub answer() is description('computes the answer') { 42 }
sub faildoc() is description { "fail" }
is answer(), 42, 'can call sub that has had a trait applied to it by role name with arg';
is &answer.description, 'computes the answer', 'description role applied and set with argument';
is faildoc(), "fail", 'can call sub that has had a trait applied to it by role name without arg';
is &faildoc.description, 'missing description!', 'description role applied without argument';

sub cheezburger is described("tasty") { "nom" }
sub lolcat is described { "undescribable" }
sub cheezburger is described("tasty") { "nom" }
sub lolcat is described { "undescribable" }

is cheezburger(), "nom", 'can call sub that has had a trait applied to it by named param with arg';
is &cheezburger.description, 'tasty', 'named trait handler applied other role set with argument';
is lolcat(), "undescribable", 'can call sub that has had a trait applied to it by named param without arg';
is &lolcat.description, 'missing description!', 'named trait handler applied other role without argument';
is cheezburger(), "nom", 'can call sub that has had a trait applied to it by named param with arg';
is &cheezburger.description, 'tasty', 'named trait handler applied other role set with argument';
is lolcat(), "undescribable", 'can call sub that has had a trait applied to it by named param without arg';
is &lolcat.description, 'missing description!', 'named trait handler applied other role without argument';
}

#?rakudo skip 'RT 69893'
{
my $recorder = '';
role woowoo { }
multi trait_mod:<is>(Routine $c, woowoo) {
multi trait_mod:<is>(Routine $c, :$woowoo!) {
$c.wrap: sub {
$recorder ~= 'wrap';
}
Expand Down

0 comments on commit 3f79756

Please sign in to comment.