fix punctuation
[gitmo/Moose.git] / t / roles / role_composition_methods.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Fatal;
8
9 use Moose::Meta::Role::Application::RoleSummation;
10 use Moose::Meta::Role::Composite;
11
12 {
13     package Role::Foo;
14     use Moose::Role;
15
16     sub foo { 'Role::Foo::foo' }
17
18     package Role::Bar;
19     use Moose::Role;
20
21     sub bar { 'Role::Bar::bar' }
22
23     package Role::FooConflict;
24     use Moose::Role;
25
26     sub foo { 'Role::FooConflict::foo' }
27
28     package Role::BarConflict;
29     use Moose::Role;
30
31     sub bar { 'Role::BarConflict::bar' }
32
33     package Role::AnotherFooConflict;
34     use Moose::Role;
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
50     is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
51
52     is( exception {
53         Moose::Meta::Role::Application::RoleSummation->new->apply($c);
54     }, undef, '... this succeeds as expected' );
55
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
73     is($c->name, 'Role::Foo|Role::FooConflict', '... got the composite role name');
74
75     is( exception {
76         Moose::Meta::Role::Application::RoleSummation->new->apply($c);
77     }, undef, '... this succeeds as expected' );
78
79     is_deeply(
80         [ sort $c->get_method_list ],
81         [],
82         '... got the right list of methods'
83     );
84
85     is_deeply(
86         [ sort $c->get_required_method_list ],
87         [ 'foo' ],
88         '... got the right list of required methods'
89     );
90 }
91
92 # test complex conflict
93 {
94     my $c = Moose::Meta::Role::Composite->new(
95         roles => [
96             Role::Foo->meta,
97             Role::Bar->meta,
98             Role::FooConflict->meta,
99             Role::BarConflict->meta,
100         ]
101     );
102     isa_ok($c, 'Moose::Meta::Role::Composite');
103
104     is($c->name, 'Role::Foo|Role::Bar|Role::FooConflict|Role::BarConflict', '... got the composite role name');
105
106     is( exception {
107         Moose::Meta::Role::Application::RoleSummation->new->apply($c);
108     }, undef, '... this succeeds as expected' );
109
110     is_deeply(
111         [ sort $c->get_method_list ],
112         [],
113         '... got the right list of methods'
114     );
115
116     is_deeply(
117         [ sort $c->get_required_method_list ],
118         [ 'bar', 'foo' ],
119         '... got the right list of required methods'
120     );
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
133     is($c->name, 'Role::Foo|Role::AnotherFooConflict', '... got the composite role name');
134
135     is( exception {
136         Moose::Meta::Role::Application::RoleSummation->new->apply($c);
137     }, undef, '... this succeeds as expected' );
138
139     is_deeply(
140         [ sort $c->get_method_list ],
141         [ 'baz' ],
142         '... got the right list of methods'
143     );
144
145     is_deeply(
146         [ sort $c->get_required_method_list ],
147         [ 'foo' ],
148         '... got the right list of required methods'
149     );
150 }
151
152 done_testing;