no more _role_meta crapsvk status!
[gitmo/Moose.git] / t / 040_meta_role.t
CommitLineData
e185c027 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
d63f8289 6use Test::More tests => 23;
e185c027 7use Test::Exception;
8
9BEGIN {
10 use_ok('Moose::Meta::Role');
11}
12
13{
14 package FooRole;
15
16 our $VERSION = '0.01';
17
18 sub foo { 'FooRole::foo' }
19}
20
68efb014 21my $foo_role = Moose::Meta::Role->initialize('FooRole');
e185c027 22isa_ok($foo_role, 'Moose::Meta::Role');
68efb014 23isa_ok($foo_role, 'Class::MOP::Module');
e185c027 24
25is($foo_role->name, 'FooRole', '... got the right name of FooRole');
26is($foo_role->version, '0.01', '... got the right version of FooRole');
27
28# methods ...
29
30ok($foo_role->has_method('foo'), '... FooRole has the foo method');
31is($foo_role->get_method('foo'), \&FooRole::foo, '... FooRole got the foo method');
32
a7d0cd00 33isa_ok($foo_role->get_method('foo'), 'Moose::Meta::Role::Method');
34
e185c027 35is_deeply(
36 [ $foo_role->get_method_list() ],
37 [ 'foo' ],
38 '... got the right method list');
39
40# attributes ...
41
42is_deeply(
43 [ $foo_role->get_attribute_list() ],
44 [],
45 '... got the right attribute list');
46
47ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
48
49lives_ok {
50 $foo_role->add_attribute('bar' => (is => 'rw', isa => 'Foo'));
51} '... added the bar attribute okay';
52
53is_deeply(
54 [ $foo_role->get_attribute_list() ],
55 [ 'bar' ],
56 '... got the right attribute list');
57
58ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
59
60is_deeply(
61 $foo_role->get_attribute('bar'),
62 { is => 'rw', isa => 'Foo' },
63 '... got the correct description of the bar attribute');
64
65lives_ok {
66 $foo_role->add_attribute('baz' => (is => 'ro'));
67} '... added the baz attribute okay';
68
69is_deeply(
70 [ sort $foo_role->get_attribute_list() ],
71 [ 'bar', 'baz' ],
72 '... got the right attribute list');
73
74ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
75
76is_deeply(
77 $foo_role->get_attribute('baz'),
78 { is => 'ro' },
79 '... got the correct description of the baz attribute');
80
81lives_ok {
82 $foo_role->remove_attribute('bar');
83} '... removed the bar attribute okay';
84
85is_deeply(
86 [ $foo_role->get_attribute_list() ],
87 [ 'baz' ],
88 '... got the right attribute list');
89
90ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
91ok($foo_role->has_attribute('baz'), '... FooRole does still have the baz attribute');
92