fix punctuation
[gitmo/Moose.git] / t / roles / role_composition_methods.t
CommitLineData
fb1e11d5 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use Test::More;
b10dde3a 7use Test::Fatal;
fb1e11d5 8
7ff56534 9use Moose::Meta::Role::Application::RoleSummation;
10use Moose::Meta::Role::Composite;
fb1e11d5 11
12{
13 package Role::Foo;
14 use Moose::Role;
d03bd989 15
16 sub foo { 'Role::Foo::foo' }
17
fb1e11d5 18 package Role::Bar;
19 use Moose::Role;
20
21 sub bar { 'Role::Bar::bar' }
d03bd989 22
fb1e11d5 23 package Role::FooConflict;
d03bd989 24 use Moose::Role;
25
26 sub foo { 'Role::FooConflict::foo' }
27
fb1e11d5 28 package Role::BarConflict;
29 use Moose::Role;
d03bd989 30
fb1e11d5 31 sub bar { 'Role::BarConflict::bar' }
d03bd989 32
fb1e11d5 33 package Role::AnotherFooConflict;
d03bd989 34 use Moose::Role;
fb1e11d5 35 with 'Role::FooConflict';
36
37 sub baz { 'Role::AnotherFooConflict::baz' }
38}
39
40# test simple attributes
41{
42 my $c = Moose::Meta::Role::Composite->new(
43 roles => [
44 Role::Foo->meta,
45 Role::Bar->meta,
46 ]
47 );
48 isa_ok($c, 'Moose::Meta::Role::Composite');
49
d03bd989 50 is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
51
b10dde3a 52 is( exception {
fb1e11d5 53 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
b10dde3a 54 }, undef, '... this succeeds as expected' );
d03bd989 55
fb1e11d5 56 is_deeply(
57 [ sort $c->get_method_list ],
58 [ 'bar', 'foo' ],
59 '... got the right list of methods'
60 );
61}
62
63# test simple conflict
64{
65 my $c = Moose::Meta::Role::Composite->new(
66 roles => [
67 Role::Foo->meta,
68 Role::FooConflict->meta,
69 ]
70 );
71 isa_ok($c, 'Moose::Meta::Role::Composite');
72
d03bd989 73 is($c->name, 'Role::Foo|Role::FooConflict', '... got the composite role name');
74
b10dde3a 75 is( exception {
fb1e11d5 76 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
b10dde3a 77 }, undef, '... this succeeds as expected' );
d03bd989 78
fb1e11d5 79 is_deeply(
80 [ sort $c->get_method_list ],
81 [],
82 '... got the right list of methods'
d03bd989 83 );
84
fb1e11d5 85 is_deeply(
86 [ sort $c->get_required_method_list ],
87 [ 'foo' ],
88 '... got the right list of required methods'
d03bd989 89 );
fb1e11d5 90}
91
92# test complex conflict
93{
94 my $c = Moose::Meta::Role::Composite->new(
95 roles => [
96 Role::Foo->meta,
d03bd989 97 Role::Bar->meta,
fb1e11d5 98 Role::FooConflict->meta,
d03bd989 99 Role::BarConflict->meta,
fb1e11d5 100 ]
101 );
102 isa_ok($c, 'Moose::Meta::Role::Composite');
103
d03bd989 104 is($c->name, 'Role::Foo|Role::Bar|Role::FooConflict|Role::BarConflict', '... got the composite role name');
fb1e11d5 105
b10dde3a 106 is( exception {
fb1e11d5 107 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
b10dde3a 108 }, undef, '... this succeeds as expected' );
fb1e11d5 109
110 is_deeply(
111 [ sort $c->get_method_list ],
112 [],
113 '... got the right list of methods'
d03bd989 114 );
115
fb1e11d5 116 is_deeply(
117 [ sort $c->get_required_method_list ],
118 [ 'bar', 'foo' ],
119 '... got the right list of required methods'
d03bd989 120 );
fb1e11d5 121}
122
123# test simple conflict
124{
125 my $c = Moose::Meta::Role::Composite->new(
126 roles => [
127 Role::Foo->meta,
128 Role::AnotherFooConflict->meta,
129 ]
130 );
131 isa_ok($c, 'Moose::Meta::Role::Composite');
132
d03bd989 133 is($c->name, 'Role::Foo|Role::AnotherFooConflict', '... got the composite role name');
134
b10dde3a 135 is( exception {
fb1e11d5 136 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
b10dde3a 137 }, undef, '... this succeeds as expected' );
d03bd989 138
fb1e11d5 139 is_deeply(
140 [ sort $c->get_method_list ],
141 [ 'baz' ],
142 '... got the right list of methods'
d03bd989 143 );
144
fb1e11d5 145 is_deeply(
146 [ sort $c->get_required_method_list ],
147 [ 'foo' ],
148 '... got the right list of required methods'
d03bd989 149 );
fb1e11d5 150}
151
a28e50e4 152done_testing;