bfe6727ff52e3d34e70346f099e85bf918c031f5
[gitmo/MooseX-ClassAttribute.git] / t / 03-introspection.t
1 use strict;
2 use warnings;
3
4 use lib 't/lib';
5
6 use Test::More tests => 14;
7
8 # We just want the class definitions in here.
9 use SharedTests;
10
11
12 ok( HasClassAttribute->meta()->has_class_attribute('ObjectCount'),
13     q{has_class_attribute('ObjectCount') returns true} );
14
15 ok( 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
19 my @ca = qw( Delegatee LazyAttribute ManyNames Mapping ObjectCount ReadOnlyAttribute WeakAttribute );
20
21 is_deeply( [ sort HasClassAttribute->meta()->get_class_attribute_list() ],
22            [ sort @ca ],
23            'HasClassAttribute get_class_attribute_list gets all class attributes' );
24
25 is_deeply( [ sort map { $_->name() } HasClassAttribute->meta()->get_all_attributes() ],
26            [ 'size' ],
27            'HasClassAttribute get_all_attributes only finds size attribute' );
28
29 is_deeply( [ sort map { $_->name() } HasClassAttribute->meta()->get_all_class_attributes() ],
30            [ sort @ca ],
31            'HasClassAttribute get_all_class_attributes gets all class attributes' );
32
33 is_deeply( [ sort keys %{ HasClassAttribute->meta()->get_class_attribute_map() } ],
34            [ sort @ca ],
35            'HasClassAttribute get_class_attribute_map gets all class attributes' );
36
37 is_deeply( [ sort map { $_->name() } Child->meta()->get_all_class_attributes() ],
38            [ sort ( @ca, 'YetAnotherAttribute' ) ],
39            'Child get_class_attribute_map gets all class attributes' );
40
41 ok( ! Child->meta()->has_class_attribute('ObjectCount'),
42     q{has_class_attribute('ObjectCount') returns false for Child} );
43
44 ok( Child->meta()->has_class_attribute('YetAnotherAttribute'),
45     q{has_class_attribute('YetAnotherAttribute') returns true for Child} );
46
47 ok( Child->can('YetAnotherAttribute'),
48     'Child has accessor for YetAnotherAttribute' );
49
50 ok( Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
51     'Child has class attribute value for YetAnotherAttribute' );
52
53 Child->meta()->remove_class_attribute('YetAnotherAttribute');
54
55 ok( ! Child->meta()->has_class_attribute('YetAnotherAttribute'),
56     q{... has_class_attribute('YetAnotherAttribute') returns false after remove_class_attribute} );
57
58 ok( ! Child->can('YetAnotherAttribute'),
59     'accessor for YetAnotherAttribute has been removed' );
60
61 ok( ! Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
62     'Child does not have a class attribute value for YetAnotherAttribute' );