X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F03-introspection.t;h=3c3ac02558ef55cf9296b5cad72f862efa4f534c;hb=ee29de7b83532784ecf67a6a72579f49855b281e;hp=bfe6727ff52e3d34e70346f099e85bf918c031f5;hpb=b2e0e01ec7ccd4771694b1fbd1452d551bc2829f;p=gitmo%2FMooseX-ClassAttribute.git diff --git a/t/03-introspection.t b/t/03-introspection.t index bfe6727..3c3ac02 100644 --- a/t/03-introspection.t +++ b/t/03-introspection.t @@ -3,60 +3,105 @@ use warnings; use lib 't/lib'; -use Test::More tests => 14; +use Test::More; # We just want the class definitions in here. use SharedTests; - -ok( HasClassAttribute->meta()->has_class_attribute('ObjectCount'), - q{has_class_attribute('ObjectCount') returns true} ); - -ok( HasClassAttribute->meta()->get_class_attribute('ObjectCount') - ->meta()->does_role('MooseX::ClassAttribute::Role::Meta::Attribute'), - 'get_class_attribute_list returns an object which does the MooseX::ClassAttribute::Role::Meta::Attribute role' ); - -my @ca = qw( Delegatee LazyAttribute ManyNames Mapping ObjectCount ReadOnlyAttribute WeakAttribute ); - -is_deeply( [ sort HasClassAttribute->meta()->get_class_attribute_list() ], - [ sort @ca ], - 'HasClassAttribute get_class_attribute_list gets all class attributes' ); - -is_deeply( [ sort map { $_->name() } HasClassAttribute->meta()->get_all_attributes() ], - [ 'size' ], - 'HasClassAttribute get_all_attributes only finds size attribute' ); - -is_deeply( [ sort map { $_->name() } HasClassAttribute->meta()->get_all_class_attributes() ], - [ sort @ca ], - 'HasClassAttribute get_all_class_attributes gets all class attributes' ); - -is_deeply( [ sort keys %{ HasClassAttribute->meta()->get_class_attribute_map() } ], - [ sort @ca ], - 'HasClassAttribute get_class_attribute_map gets all class attributes' ); - -is_deeply( [ sort map { $_->name() } Child->meta()->get_all_class_attributes() ], - [ sort ( @ca, 'YetAnotherAttribute' ) ], - 'Child get_class_attribute_map gets all class attributes' ); - -ok( ! Child->meta()->has_class_attribute('ObjectCount'), - q{has_class_attribute('ObjectCount') returns false for Child} ); - -ok( Child->meta()->has_class_attribute('YetAnotherAttribute'), - q{has_class_attribute('YetAnotherAttribute') returns true for Child} ); - -ok( Child->can('YetAnotherAttribute'), - 'Child has accessor for YetAnotherAttribute' ); - -ok( Child->meta()->has_class_attribute_value('YetAnotherAttribute'), - 'Child has class attribute value for YetAnotherAttribute' ); +ok( + HasClassAttribute->meta()->has_class_attribute('ObjectCount'), + q{has_class_attribute('ObjectCount') returns true} +); + +ok( + HasClassAttribute->meta()->get_class_attribute('ObjectCount')->meta() + ->does_role('MooseX::ClassAttribute::Role::Meta::Attribute'), + 'get_class_attribute_list returns an object which does the MooseX::ClassAttribute::Role::Meta::Attribute role' +); + +my @ca = qw( Delegatee + LazyAttribute + ManyNames + Mapping + ObjectCount + ReadOnlyAttribute + WeakAttribute + Built + LazyBuilt + Triggerish +); + +is_deeply( + [ sort HasClassAttribute->meta()->get_class_attribute_list() ], + [ sort @ca ], + 'HasClassAttribute get_class_attribute_list gets all class attributes' +); + +is_deeply( + [ + sort map { $_->name() } + HasClassAttribute->meta()->get_all_attributes() + ], + ['size'], + 'HasClassAttribute get_all_attributes only finds size attribute' +); + +is_deeply( + [ + sort map { $_->name() } + HasClassAttribute->meta()->get_all_class_attributes() + ], + [ sort @ca ], + 'HasClassAttribute get_all_class_attributes gets all class attributes' +); + +is_deeply( + [ sort keys %{ HasClassAttribute->meta()->get_class_attribute_map() } ], + [ sort @ca ], + 'HasClassAttribute get_class_attribute_map gets all class attributes' +); + +is_deeply( + [ sort map { $_->name() } Child->meta()->get_all_class_attributes() ], + [ sort ( @ca, 'YetAnotherAttribute' ) ], + 'Child get_class_attribute_map gets all class attributes' +); + +ok( + !Child->meta()->has_class_attribute('ObjectCount'), + q{has_class_attribute('ObjectCount') returns false for Child} +); + +ok( + Child->meta()->has_class_attribute('YetAnotherAttribute'), + q{has_class_attribute('YetAnotherAttribute') returns true for Child} +); + +ok( + Child->can('YetAnotherAttribute'), + 'Child has accessor for YetAnotherAttribute' +); + +ok( + Child->meta()->has_class_attribute_value('YetAnotherAttribute'), + 'Child has class attribute value for YetAnotherAttribute' +); Child->meta()->remove_class_attribute('YetAnotherAttribute'); -ok( ! Child->meta()->has_class_attribute('YetAnotherAttribute'), - q{... has_class_attribute('YetAnotherAttribute') returns false after remove_class_attribute} ); +ok( + !Child->meta()->has_class_attribute('YetAnotherAttribute'), + q{... has_class_attribute('YetAnotherAttribute') returns false after remove_class_attribute} +); + +ok( + !Child->can('YetAnotherAttribute'), + 'accessor for YetAnotherAttribute has been removed' +); -ok( ! Child->can('YetAnotherAttribute'), - 'accessor for YetAnotherAttribute has been removed' ); +ok( + !Child->meta()->has_class_attribute_value('YetAnotherAttribute'), + 'Child does not have a class attribute value for YetAnotherAttribute' +); -ok( ! Child->meta()->has_class_attribute_value('YetAnotherAttribute'), - 'Child does not have a class attribute value for YetAnotherAttribute' ); +done_testing();