make non-lazy builder work
[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
6048a053 19my @ca = qw( Delegatee LazyAttribute ManyNames Mapping ObjectCount ReadOnlyAttribute WeakAttribute Built LazyBuilt );
a5e3ddfd 20
21is_deeply( [ sort HasClassAttribute->meta()->get_class_attribute_list() ],
22 [ sort @ca ],
23 'HasClassAttribute get_class_attribute_list gets all class attributes' );
24
25is_deeply( [ sort map { $_->name() } HasClassAttribute->meta()->get_all_attributes() ],
26 [ 'size' ],
27 'HasClassAttribute get_all_attributes only finds size attribute' );
28
29is_deeply( [ sort map { $_->name() } HasClassAttribute->meta()->get_all_class_attributes() ],
30 [ sort @ca ],
31 'HasClassAttribute get_all_class_attributes gets all class attributes' );
32
33is_deeply( [ sort keys %{ HasClassAttribute->meta()->get_class_attribute_map() } ],
34 [ sort @ca ],
35 'HasClassAttribute get_class_attribute_map gets all class attributes' );
36
37is_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
41ok( ! Child->meta()->has_class_attribute('ObjectCount'),
42 q{has_class_attribute('ObjectCount') returns false for Child} );
43
44ok( Child->meta()->has_class_attribute('YetAnotherAttribute'),
45 q{has_class_attribute('YetAnotherAttribute') returns true for Child} );
46
47ok( Child->can('YetAnotherAttribute'),
48 'Child has accessor for YetAnotherAttribute' );
49
50ok( Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
51 'Child has class attribute value for YetAnotherAttribute' );
52
53Child->meta()->remove_class_attribute('YetAnotherAttribute');
54
55ok( ! Child->meta()->has_class_attribute('YetAnotherAttribute'),
56 q{... has_class_attribute('YetAnotherAttribute') returns false after remove_class_attribute} );
57
58ok( ! Child->can('YetAnotherAttribute'),
59 'accessor for YetAnotherAttribute has been removed' );
60
61ok( ! Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
62 'Child does not have a class attribute value for YetAnotherAttribute' );