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