Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5249f858db
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 48 lines (39 sloc) 1.264 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
use v6;

use Test;

plan 13;

#?pugs 99 todo 'anonymous roles'

# L<S14/Roles>
{
  my $a = {:x};
  is $a, {:x}, "basic sanity";
  lives_ok { $a does role { has $.cool = "yeah" }}, "anonymous role mixin";
  is $a, {:x}, "still basic sanity";
  is $a.cool, "yeah", "anonymous role gave us an attribute";
}

# The same, but we story the anonymous role in a variable
{
  my $a = {:x};
  is $a, {:x}, "basic sanity";
  my $role;
  lives_ok { $role = role { has $.cool = "yeah" } }, "anonymous role definition";
  lives_ok { $a does $role }, "anonymous role variable mixin";
  is $a, {:x}, "still basic sanity";
  is $a.cool, "yeah", "anonymous role variable gave us an attribute";
}

# Guarantee roles are really first-class-entities:
{
    sub role_generator(Str $val) {
      return role {
        has $.cool = $val;
      }
    }

  my $a = {:x};
  is $a, {:x}, "basic sanity";
  #?niecza todo 'This is being misinterpreted as an initial value'
  lives_ok {$a does role_generator("hi")}, "role generating function mixin";
  is $a, {:x}, "still basic sanity";
  #?niecza skip 'roles are run once and only capture the protopad'
  #?rakudo skip 'anonymous roles only created once'
  is $a.cool, "hi", "role generating function gave us an attribute";
}

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