DEATH TO ALL zionist ELLIPSES
[gitmo/Moose.git] / t / 030_roles / 024_role_composition_methods.t
CommitLineData
fb1e11d5 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
7ff56534 6use Test::More tests => 19;
fb1e11d5 7use Test::Exception;
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
1808c2da 50 is($c->name, 'Role::Foo|Role::Bar', 'got the composite role name');
d03bd989 51
fb1e11d5 52 lives_ok {
53 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
1808c2da 54 } 'this succeeds as expected';
d03bd989 55
fb1e11d5 56 is_deeply(
57 [ sort $c->get_method_list ],
58 [ 'bar', 'foo' ],
1808c2da 59 'got the right list of methods'
fb1e11d5 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
1808c2da 73 is($c->name, 'Role::Foo|Role::FooConflict', 'got the composite role name');
d03bd989 74
fb1e11d5 75 lives_ok {
76 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
1808c2da 77 } 'this succeeds as expected';
d03bd989 78
fb1e11d5 79 is_deeply(
80 [ sort $c->get_method_list ],
81 [],
1808c2da 82 'got the right list of methods'
d03bd989 83 );
84
fb1e11d5 85 is_deeply(
86 [ sort $c->get_required_method_list ],
87 [ 'foo' ],
1808c2da 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
1808c2da 104 is($c->name, 'Role::Foo|Role::Bar|Role::FooConflict|Role::BarConflict', 'got the composite role name');
fb1e11d5 105
106 lives_ok {
107 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
1808c2da 108 } 'this succeeds as expected';
fb1e11d5 109
110 is_deeply(
111 [ sort $c->get_method_list ],
112 [],
1808c2da 113 'got the right list of methods'
d03bd989 114 );
115
fb1e11d5 116 is_deeply(
117 [ sort $c->get_required_method_list ],
118 [ 'bar', 'foo' ],
1808c2da 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
1808c2da 133 is($c->name, 'Role::Foo|Role::AnotherFooConflict', 'got the composite role name');
d03bd989 134
fb1e11d5 135 lives_ok {
136 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
1808c2da 137 } 'this succeeds as expected';
d03bd989 138
fb1e11d5 139 is_deeply(
140 [ sort $c->get_method_list ],
141 [ 'baz' ],
1808c2da 142 'got the right list of methods'
d03bd989 143 );
144
fb1e11d5 145 is_deeply(
146 [ sort $c->get_required_method_list ],
147 [ 'foo' ],
1808c2da 148 'got the right list of required methods'
d03bd989 149 );
fb1e11d5 150}
151