From: Dave Rolsky Date: Fri, 5 Sep 2008 14:34:05 +0000 (+0000) Subject: Add tests for introspection methods X-Git-Tag: 0.05~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a5e3ddfd4ab2cbdeea6f3c9769b7a153030e7cc7;hp=169f4cc7086850fa6d68d7bccaa5b5ecda31fe45;p=gitmo%2FMooseX-ClassAttribute.git Add tests for introspection methods --- diff --git a/t/03-introspection.t b/t/03-introspection.t new file mode 100644 index 0000000..6099952 --- /dev/null +++ b/t/03-introspection.t @@ -0,0 +1,63 @@ +use strict; +use warnings; + +use lib 't/lib'; + +use Test::More 'no_plan'; + +# 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 ObjectCount ReadOnlyAttribute WeakAttribute ); +push @ca, 'Mapping' if SharedTests->HasMXAH(); + +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->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' );