Tidy all code
[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;
7
8 # We just want the class definitions in here.
9 use SharedTests;
10
11 ok(
12     HasClassAttribute->meta()->has_class_attribute('ObjectCount'),
13     q{has_class_attribute('ObjectCount') returns true}
14 );
15
16 ok(
17     HasClassAttribute->meta()->get_class_attribute('ObjectCount')->meta()
18         ->does_role('MooseX::ClassAttribute::Trait::Attribute'),
19     'get_class_attribute_list returns an object which does the MooseX::ClassAttribute::Trait::Attribute role'
20 );
21
22 my @ca = qw( Delegatee
23     LazyAttribute
24     ManyNames
25     Mapping
26     ObjectCount
27     ReadOnlyAttribute
28     WeakAttribute
29     Built
30     LazyBuilt
31     Triggerish
32     TriggerRecord
33 );
34
35 is_deeply(
36     [ sort HasClassAttribute->meta()->get_class_attribute_list() ],
37     [ sort @ca ],
38     'HasClassAttribute get_class_attribute_list gets all class attributes'
39 );
40
41 is_deeply(
42     [
43         sort map { $_->name() }
44             HasClassAttribute->meta()->get_all_attributes()
45     ],
46     ['size'],
47     'HasClassAttribute get_all_attributes only finds size attribute'
48 );
49
50 is_deeply(
51     [
52         sort map { $_->name() }
53             HasClassAttribute->meta()->get_all_class_attributes()
54     ],
55     [ sort @ca ],
56     'HasClassAttribute get_all_class_attributes gets all class attributes'
57 );
58
59 is_deeply(
60     [ sort keys %{ HasClassAttribute->meta()->get_class_attribute_map() } ],
61     [ sort @ca ],
62     'HasClassAttribute get_class_attribute_map gets all class attributes'
63 );
64
65 is_deeply(
66     [ sort map { $_->name() } Child->meta()->get_all_class_attributes() ],
67     [ sort ( @ca, 'YetAnotherAttribute' ) ],
68     'Child get_class_attribute_map gets all class attributes'
69 );
70
71 ok(
72     !Child->meta()->has_class_attribute('ObjectCount'),
73     q{has_class_attribute('ObjectCount') returns false for Child}
74 );
75
76 ok(
77     Child->meta()->has_class_attribute('YetAnotherAttribute'),
78     q{has_class_attribute('YetAnotherAttribute') returns true for Child}
79 );
80
81 ok(
82     Child->can('YetAnotherAttribute'),
83     'Child has accessor for YetAnotherAttribute'
84 );
85
86 ok(
87     Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
88     'Child has class attribute value for YetAnotherAttribute'
89 );
90
91 Child->meta()->remove_class_attribute('YetAnotherAttribute');
92
93 ok(
94     !Child->meta()->has_class_attribute('YetAnotherAttribute'),
95     q{... has_class_attribute('YetAnotherAttribute') returns false after remove_class_attribute}
96 );
97
98 ok(
99     !Child->can('YetAnotherAttribute'),
100     'accessor for YetAnotherAttribute has been removed'
101 );
102
103 ok(
104     !Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
105     'Child does not have a class attribute value for YetAnotherAttribute'
106 );
107
108 done_testing();