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