refactor code to allow for class attributes in roles
[gitmo/MooseX-ClassAttribute.git] / t / 03-introspection.t
CommitLineData
a5e3ddfd 1use strict;
2use warnings;
3
4use lib 't/lib';
5
ee29de7b 6use Test::More;
a5e3ddfd 7
8# We just want the class definitions in here.
9use SharedTests;
10
a3ced883 11ok(
12 HasClassAttribute->meta()->has_class_attribute('ObjectCount'),
13 q{has_class_attribute('ObjectCount') returns true}
14);
a5e3ddfd 15
a3ced883 16ok(
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);
a5e3ddfd 21
8207dfe7 22my @ca = qw( Delegatee
a3ced883 23 LazyAttribute
24 ManyNames
25 Mapping
26 ObjectCount
27 ReadOnlyAttribute
28 WeakAttribute
29 Built
30 LazyBuilt
31 Triggerish
32);
33
34is_deeply(
35 [ sort HasClassAttribute->meta()->get_class_attribute_list() ],
36 [ sort @ca ],
37 'HasClassAttribute get_class_attribute_list gets all class attributes'
38);
39
40is_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
49is_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
58is_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
64is_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
70ok(
71 !Child->meta()->has_class_attribute('ObjectCount'),
72 q{has_class_attribute('ObjectCount') returns false for Child}
73);
74
75ok(
76 Child->meta()->has_class_attribute('YetAnotherAttribute'),
77 q{has_class_attribute('YetAnotherAttribute') returns true for Child}
78);
79
80ok(
81 Child->can('YetAnotherAttribute'),
82 'Child has accessor for YetAnotherAttribute'
83);
84
85ok(
86 Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
87 'Child has class attribute value for YetAnotherAttribute'
88);
a5e3ddfd 89
90Child->meta()->remove_class_attribute('YetAnotherAttribute');
91
a3ced883 92ok(
93 !Child->meta()->has_class_attribute('YetAnotherAttribute'),
94 q{... has_class_attribute('YetAnotherAttribute') returns false after remove_class_attribute}
95);
a5e3ddfd 96
a3ced883 97ok(
98 !Child->can('YetAnotherAttribute'),
99 'accessor for YetAnotherAttribute has been removed'
100);
a5e3ddfd 101
a3ced883 102ok(
103 !Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
104 'Child does not have a class attribute value for YetAnotherAttribute'
105);
ee29de7b 106
107done_testing();