Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add a test for attribute in BUILD signature in roles
also fudge a test that prevents rakudo from running the file
  • Loading branch information
moritz committed Sep 8, 2013
1 parent edae796 commit 9a4c899
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions S14-roles/attributes.t
@@ -1,30 +1,33 @@
use v6;
use Test;
plan 6;
plan 7;

# L<S14/Roles/"Roles may have attributes">

role R1 {
has $!a1;
has $.a2 is rw;
};

class C1 does R1 {
method set_a1($val) {
$!a1 = $val;
}
method get_a1 {
$!a1
}
};

my $x = C1.new();

$x.set_a1('abc');
is $x.get_a1, 'abc', 'Can set and get class-private attr from role';

$x.a2 = 'xyz';
is $x.a2, 'xyz', 'Public attribute gets accessor/mutator composed';
#?rakudo skip 'review test and rakudo'
{
role R1 {
has $!a1;
has $.a2 is rw;
};

class C1 does R1 {
method set_a1($val) {
$!a1 = $val;
}
method get_a1 {
$!a1
}
};

my $x = C1.new();

$x.set_a1('abc');
is $x.get_a1, 'abc', 'Can set and get class-private attr from role';

$x.a2 = 'xyz';
is $x.a2, 'xyz', 'Public attribute gets accessor/mutator composed';
}


role R2 {
Expand All @@ -47,4 +50,14 @@ class C5 does R4 {
}
is C5.new().bar(), [], 'Composing an attribute into a class that already has one works';

{
role R6 {
has %!e;
method el() { %!e<a> };
submethod BUILD(:%!e) { };
}
class C6 does R6 { };
is C6.new(e => { a => 42 }).el, 42, 'can use :%!role_attr in BUILD signature';
}

# vim: syn=perl6

0 comments on commit 9a4c899

Please sign in to comment.