Moved some code to a shared mixin role so we can apply a role to the role metaclass
[gitmo/MooseX-ClassAttribute.git] / t / 03-introspection.t
CommitLineData
a5e3ddfd 1use strict;
2use warnings;
3
4use lib 't/lib';
5
076543d6 6use Test::More tests => 14;
a5e3ddfd 7
8# We just want the class definitions in here.
9use SharedTests;
10
11
12ok( HasClassAttribute->meta()->has_class_attribute('ObjectCount'),
13 q{has_class_attribute('ObjectCount') returns true} );
14
15ok( HasClassAttribute->meta()->get_class_attribute('ObjectCount')
16 ->meta()->does_role('MooseX::ClassAttribute::Role::Meta::Attribute'),
17 'get_class_attribute_list returns an object which does the MooseX::ClassAttribute::Role::Meta::Attribute role' );
18
8207dfe7 19my @ca = qw( Delegatee
20 LazyAttribute
21 ManyNames
22 Mapping
23 ObjectCount
24 ReadOnlyAttribute
25 WeakAttribute
26 Built
27 LazyBuilt
28 Triggerish
29 );
a5e3ddfd 30
31is_deeply( [ sort HasClassAttribute->meta()->get_class_attribute_list() ],
32 [ sort @ca ],
33 'HasClassAttribute get_class_attribute_list gets all class attributes' );
34
35is_deeply( [ sort map { $_->name() } HasClassAttribute->meta()->get_all_attributes() ],
36 [ 'size' ],
37 'HasClassAttribute get_all_attributes only finds size attribute' );
38
39is_deeply( [ sort map { $_->name() } HasClassAttribute->meta()->get_all_class_attributes() ],
40 [ sort @ca ],
41 'HasClassAttribute get_all_class_attributes gets all class attributes' );
42
43is_deeply( [ sort keys %{ HasClassAttribute->meta()->get_class_attribute_map() } ],
44 [ sort @ca ],
45 'HasClassAttribute get_class_attribute_map gets all class attributes' );
46
47is_deeply( [ sort map { $_->name() } Child->meta()->get_all_class_attributes() ],
48 [ sort ( @ca, 'YetAnotherAttribute' ) ],
49 'Child get_class_attribute_map gets all class attributes' );
50
51ok( ! Child->meta()->has_class_attribute('ObjectCount'),
52 q{has_class_attribute('ObjectCount') returns false for Child} );
53
54ok( Child->meta()->has_class_attribute('YetAnotherAttribute'),
55 q{has_class_attribute('YetAnotherAttribute') returns true for Child} );
56
57ok( Child->can('YetAnotherAttribute'),
58 'Child has accessor for YetAnotherAttribute' );
59
60ok( Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
61 'Child has class attribute value for YetAnotherAttribute' );
62
63Child->meta()->remove_class_attribute('YetAnotherAttribute');
64
65ok( ! Child->meta()->has_class_attribute('YetAnotherAttribute'),
66 q{... has_class_attribute('YetAnotherAttribute') returns false after remove_class_attribute} );
67
68ok( ! Child->can('YetAnotherAttribute'),
69 'accessor for YetAnotherAttribute has been removed' );
70
71ok( ! Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
72 'Child does not have a class attribute value for YetAnotherAttribute' );