Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 49 lines (37 sloc) 1.342 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
use v6;
use Test;

plan 9;

=begin pod

Tests for lexical roles delcared with 'my role'

=end pod

# L<S12/Classes>

# A few basic tests.
eval_lives_ok 'my role R1 {}', 'my role parses OK';
eval_lives_ok '{ my role R2 {} }; { my role R2 {} }',
              'declare roles with the same name in two scopes.';
#?pugs todo
eval_dies_ok '{ my class R3 {}; R3; }; R3',
              'scope is correctly restricted';

{
    my role Model {
        method catwalk() { 'ooh pretty!' }
    }

    is Model.gist, '(Model)', 'lexical role type object stringifies OK';
    is Model.catwalk, 'ooh pretty!', 'can pun lexical role';

    my class SuperModel does Model {
    }
    ok SuperModel ~~ Model, 'lexical role can be composed and smart-matches';
    my $sm = SuperModel.new();
    ok $sm ~~ Model, 'instance smart-matches against lexical role too';
    is $sm.catwalk, 'ooh pretty!', 'can call composed method';
}

{
    # This one was a former Rakudo bug.
    my role Drinking { method go-to-bar() { "glug" } }
    my role Gymnastics { method go-to-bar() { "ouch" } }
    my class DrunkGymnast does Gymnastics does Drinking {
        method go-to-bar() { self.Gymnastics::go-to-bar() }
    }
    is DrunkGymnast.new.go-to-bar, "ouch", 'the $obj.RoleName::meth() syntax works on lexical roles';
}

# vim: ft=perl6
Something went wrong with that request. Please try again.