Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 63 lines (49 sloc) 1.331 kb
28d6e6d [spectest] A couple of basic tests for role attribute composition.
jnthn authored
1 use v6;
2 use Test;
9a4c899 add a test for attribute in BUILD signature in roles
Moritz Lenz authored
3 plan 7;
28d6e6d [spectest] A couple of basic tests for role attribute composition.
jnthn authored
4
605c16f [t/spec] fix some of the S12/Roles smartlinks
moritz authored
5 # L<S14/Roles/"Roles may have attributes">
c2f8fec [t] and [t/spec] (two train travels worth of changes):
moritz authored
6
9a4c899 add a test for attribute in BUILD signature in roles
Moritz Lenz authored
7 {
8 role R1 {
9 has $!a1;
10 has $.a2 is rw;
11 };
12
13 class C1 does R1 {
14 method set_a1($val) {
15 $!a1 = $val;
16 }
17 method get_a1 {
18 $!a1
19 }
20 };
21
22 my $x = C1.new();
23
24 $x.set_a1('abc');
25 is $x.get_a1, 'abc', 'Can set and get class-private attr from role';
26
27 $x.a2 = 'xyz';
28 is $x.a2, 'xyz', 'Public attribute gets accessor/mutator composed';
29 }
28d6e6d [spectest] A couple of basic tests for role attribute composition.
jnthn authored
30
01852cb [spectest] Couple more tests for attribute composition.
jnthn authored
31
32 role R2 {
33 has Int $!a;
34 }
35
36 eval_dies_ok 'class C3 does R2 { has $!a }', 'Roles with conflicing attributes';
2f365ed [t/spec] Get rid of same type = composition OK test.
jnthn authored
37 eval_dies_ok 'class C2 does R2 { has Int $!a }', 'Same name, same type will also conflicts';
01852cb [spectest] Couple more tests for attribute composition.
jnthn authored
38
8b2f712 [t/spec] Test for attributes in roles having a default value.
jnthn authored
39 role R3 {
40 has $.x = 42;
41 }
42 class C4 does R3 { }
43 is C4.new.x, 42, 'initializing attributes in a role works';
44
beb83c5 [t/spec] Test for RT#7992.
jnthn authored
45 role R4 { has @!foo; method bar() { @!foo } }
46 class C5 does R4 {
47 has $.baz;
48 }
49 is C5.new().bar(), [], 'Composing an attribute into a class that already has one works';
50
a993413 @coke niecza fudge
coke authored
51 #?niecza skip 'Unhandled exception: Attribute %!e in C6 is defined in C6 but not R6'
9a4c899 add a test for attribute in BUILD signature in roles
Moritz Lenz authored
52 {
53 role R6 {
54 has %!e;
55 method el() { %!e<a> };
56 submethod BUILD(:%!e) { };
57 }
58 class C6 does R6 { };
59 is C6.new(e => { a => 42 }).el, 42, 'can use :%!role_attr in BUILD signature';
60 }
61
28d6e6d [spectest] A couple of basic tests for role attribute composition.
jnthn authored
62 # vim: syn=perl6
Something went wrong with that request. Please try again.