Make several role attribute tests todo
[gitmo/Mouse.git] / t / 030_roles / 001_meta_role.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 26;
7 use Test::Exception;
8
9 use Test::Mouse;
10 use Mouse::Meta::Role;
11 use lib 't/lib';
12 use MooseCompat;
13
14 {
15     package FooRole;
16
17     our $VERSION = '0.01';
18
19     sub foo { 'FooRole::foo' }
20 }
21
22 my $foo_role = Mouse::Meta::Role->initialize('FooRole');
23 isa_ok($foo_role, 'Mouse::Meta::Role');
24 #isa_ok($foo_role, 'Class::MOP::Module');
25
26 is($foo_role->name, 'FooRole', '... got the right name of FooRole');
27 is($foo_role->version, '0.01', '... got the right version of FooRole');
28
29 # methods ...
30
31 ok($foo_role->has_method('foo'), '... FooRole has the foo method');
32 is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method');
33
34 isa_ok($foo_role->get_method('foo'), 'Mouse::Meta::Role::Method');
35
36 is_deeply(
37     [ $foo_role->get_method_list() ],
38     [ 'foo' ],
39     '... got the right method list');
40
41 # attributes ...
42
43 is_deeply(
44     [ $foo_role->get_attribute_list() ],
45     [],
46     '... got the right attribute list');
47
48 ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
49
50 lives_ok {
51     $foo_role->add_attribute('bar' => (is => 'rw', isa => 'Foo'));
52 } '... added the bar attribute okay';
53
54 is_deeply(
55     [ $foo_role->get_attribute_list() ],
56     [ 'bar' ],
57     '... got the right attribute list');
58
59 ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
60
61 {
62     local $TODO = 'Mouse does not support role attributes';
63     is_deeply(
64         join('|', %{$foo_role->get_attribute('bar')}),
65         join('|', %{+{ is => 'rw', isa => 'Foo' }}),
66         '... got the correct description of the bar attribute');
67 }
68 lives_ok {
69     $foo_role->add_attribute('baz' => (is => 'ro'));
70 } '... added the baz attribute okay';
71
72 is_deeply(
73     [ sort $foo_role->get_attribute_list() ],
74     [ 'bar', 'baz' ],
75     '... got the right attribute list');
76
77 ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
78
79 is_deeply(
80     $foo_role->get_attribute('baz')->{is},
81     'ro',
82     '... got the correct description of the baz attribute');
83
84 lives_ok {
85     $foo_role->remove_attribute('bar');
86 } '... removed the bar attribute okay';
87
88 is_deeply(
89     [ $foo_role->get_attribute_list() ],
90     [ 'baz' ],
91     '... got the right attribute list');
92
93 ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
94 ok($foo_role->has_attribute('baz'), '... FooRole does still have the baz attribute');
95
96 # method modifiers
97
98 ok(!$foo_role->has_before_method_modifiers('boo'), '... no boo:before modifier');
99
100 my $method = sub { "FooRole::boo:before" };
101 lives_ok {
102     $foo_role->add_before_method_modifier('boo' => $method);
103 } '... added a method modifier okay';
104
105 ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier');
106 is(($foo_role->get_before_method_modifiers('boo'))[0], $method, '... got the right method back');
107
108 is_deeply(
109     [ $foo_role->get_method_modifier_list('before') ],
110     [ 'boo' ],
111     '... got the right list of before method modifiers');