3c3ac02558ef55cf9296b5cad72f862efa4f534c
[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::Role::Meta::Attribute'),
19     'get_class_attribute_list returns an object which does the MooseX::ClassAttribute::Role::Meta::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 );
33
34 is_deeply(
35     [ sort HasClassAttribute->meta()->get_class_attribute_list() ],
36     [ sort @ca ],
37     'HasClassAttribute get_class_attribute_list gets all class attributes'
38 );
39
40 is_deeply(
41     [
42         sort map { $_->name() }
43             HasClassAttribute->meta()->get_all_attributes()
44     ],
45     ['size'],
46     'HasClassAttribute get_all_attributes only finds size attribute'
47 );
48
49 is_deeply(
50     [
51         sort map { $_->name() }
52             HasClassAttribute->meta()->get_all_class_attributes()
53     ],
54     [ sort @ca ],
55     'HasClassAttribute get_all_class_attributes gets all class attributes'
56 );
57
58 is_deeply(
59     [ sort keys %{ HasClassAttribute->meta()->get_class_attribute_map() } ],
60     [ sort @ca ],
61     'HasClassAttribute get_class_attribute_map gets all class attributes'
62 );
63
64 is_deeply(
65     [ sort map { $_->name() } Child->meta()->get_all_class_attributes() ],
66     [ sort ( @ca, 'YetAnotherAttribute' ) ],
67     'Child get_class_attribute_map gets all class attributes'
68 );
69
70 ok(
71     !Child->meta()->has_class_attribute('ObjectCount'),
72     q{has_class_attribute('ObjectCount') returns false for Child}
73 );
74
75 ok(
76     Child->meta()->has_class_attribute('YetAnotherAttribute'),
77     q{has_class_attribute('YetAnotherAttribute') returns true for Child}
78 );
79
80 ok(
81     Child->can('YetAnotherAttribute'),
82     'Child has accessor for YetAnotherAttribute'
83 );
84
85 ok(
86     Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
87     'Child has class attribute value for YetAnotherAttribute'
88 );
89
90 Child->meta()->remove_class_attribute('YetAnotherAttribute');
91
92 ok(
93     !Child->meta()->has_class_attribute('YetAnotherAttribute'),
94     q{... has_class_attribute('YetAnotherAttribute') returns false after remove_class_attribute}
95 );
96
97 ok(
98     !Child->can('YetAnotherAttribute'),
99     'accessor for YetAnotherAttribute has been removed'
100 );
101
102 ok(
103     !Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
104     'Child does not have a class attribute value for YetAnotherAttribute'
105 );
106
107 done_testing();