Regenerate test files
[gitmo/Mouse.git] / t / 030_roles / 002_role.t
CommitLineData
67199842 1#!/usr/bin/perl
fde8e43f 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
67199842 5
6use strict;
7use warnings;
8
fde8e43f 9use Test::More;
10$TODO = q{Mouse is not yet completed};
67199842 11use Test::Exception;
12
13=pod
14
15NOTE:
16
17Should we be testing here that the has & override
6cfa1e5e 18are injecting their methods correctly? In other
67199842 19words, should 'has_method' return true for them?
20
21=cut
22
23{
24 package FooRole;
25 use Mouse::Role;
6cfa1e5e 26
67199842 27 our $VERSION = '0.01';
6cfa1e5e 28
67199842 29 has 'bar' => (is => 'rw', isa => 'Foo');
6cfa1e5e 30 has 'baz' => (is => 'ro');
31
67199842 32 sub foo { 'FooRole::foo' }
6cfa1e5e 33 sub boo { 'FooRole::boo' }
34
67199842 35 before 'boo' => sub { "FooRole::boo:before" };
6cfa1e5e 36
37 after 'boo' => sub { "FooRole::boo:after1" };
38 after 'boo' => sub { "FooRole::boo:after2" };
39
40 around 'boo' => sub { "FooRole::boo:around" };
41
42 override 'bling' => sub { "FooRole::bling:override" };
43 override 'fling' => sub { "FooRole::fling:override" };
44
67199842 45 ::dies_ok { extends() } '... extends() is not supported';
6cfa1e5e 46 ::dies_ok { augment() } '... augment() is not supported';
47 ::dies_ok { inner() } '... inner() is not supported';
67199842 48
49 no Mouse::Role;
50}
51
52my $foo_role = FooRole->meta;
53isa_ok($foo_role, 'Mouse::Meta::Role');
fde8e43f 54isa_ok($foo_role, 'Mouse::Meta::Module');
67199842 55
56is($foo_role->name, 'FooRole', '... got the right name of FooRole');
6cfa1e5e 57is($foo_role->version, '0.01', '... got the right version of FooRole');
67199842 58
59# methods ...
60
6cfa1e5e 61ok($foo_role->has_method('foo'), '... FooRole has the foo method');
62is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method');
67199842 63
64isa_ok($foo_role->get_method('foo'), 'Mouse::Meta::Role::Method');
65
66ok($foo_role->has_method('boo'), '... FooRole has the boo method');
67is($foo_role->get_method('boo')->body, \&FooRole::boo, '... FooRole got the boo method');
68
69isa_ok($foo_role->get_method('boo'), 'Mouse::Meta::Role::Method');
67199842 70
71is_deeply(
72 [ sort $foo_role->get_method_list() ],
1feffa0f 73 [ 'boo', 'foo', 'meta' ],
67199842 74 '... got the right method list');
75
76ok(FooRole->can('foo'), "locally defined methods are still there");
77ok(!FooRole->can('has'), "sugar was unimported");
78
79# attributes ...
80
81is_deeply(
82 [ sort $foo_role->get_attribute_list() ],
83 [ 'bar', 'baz' ],
84 '... got the right attribute list');
85
86ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
87
6cfa1e5e 88my $bar_attr = $foo_role->get_attribute('bar');
89is($bar_attr->{is}, 'rw',
90 'bar attribute is rw');
91is($bar_attr->{isa}, 'Foo',
92 'bar attribute isa Foo');
fde8e43f 93is(ref($bar_attr->{definition_context}), 'HASH',
94 'bar\'s definition context is a hash');
95is($bar_attr->{definition_context}->{package}, 'FooRole',
96 'bar was defined in FooRole');
67199842 97
98ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
99
6cfa1e5e 100my $baz_attr = $foo_role->get_attribute('baz');
101is($baz_attr->{is}, 'ro',
102 'baz attribute is ro');
fde8e43f 103is(ref($baz_attr->{definition_context}), 'HASH',
104 'bar\'s definition context is a hash');
105is($baz_attr->{definition_context}->{package}, 'FooRole',
106 'baz was defined in FooRole');
67199842 107
108# method modifiers
67199842 109
110ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier');
6cfa1e5e 111is(($foo_role->get_before_method_modifiers('boo'))[0]->(),
112 "FooRole::boo:before",
67199842 113 '... got the right method back');
114
115is_deeply(
116 [ $foo_role->get_method_modifier_list('before') ],
117 [ 'boo' ],
118 '... got the right list of before method modifiers');
119
120ok($foo_role->has_after_method_modifiers('boo'), '... now we have a boo:after modifier');
6cfa1e5e 121is(($foo_role->get_after_method_modifiers('boo'))[0]->(),
122 "FooRole::boo:after1",
123 '... got the right method back');
124is(($foo_role->get_after_method_modifiers('boo'))[1]->(),
125 "FooRole::boo:after2",
67199842 126 '... got the right method back');
67199842 127
128is_deeply(
129 [ $foo_role->get_method_modifier_list('after') ],
130 [ 'boo' ],
131 '... got the right list of after method modifiers');
6cfa1e5e 132
67199842 133ok($foo_role->has_around_method_modifiers('boo'), '... now we have a boo:around modifier');
6cfa1e5e 134is(($foo_role->get_around_method_modifiers('boo'))[0]->(),
135 "FooRole::boo:around",
67199842 136 '... got the right method back');
137
138is_deeply(
139 [ $foo_role->get_method_modifier_list('around') ],
140 [ 'boo' ],
141 '... got the right list of around method modifiers');
142
67199842 143## overrides
144
145ok($foo_role->has_override_method_modifier('bling'), '... now we have a bling:override modifier');
6cfa1e5e 146is($foo_role->get_override_method_modifier('bling')->(),
147 "FooRole::bling:override",
67199842 148 '... got the right method back');
149
150ok($foo_role->has_override_method_modifier('fling'), '... now we have a fling:override modifier');
6cfa1e5e 151is($foo_role->get_override_method_modifier('fling')->(),
152 "FooRole::fling:override",
67199842 153 '... got the right method back');
154
155is_deeply(
156 [ sort $foo_role->get_method_modifier_list('override') ],
157 [ 'bling', 'fling' ],
158 '... got the right list of override method modifiers');
159
fde8e43f 160done_testing;