X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F010_self_introspection.t;h=24572a5ed6eef5465c83525fb90547a25bd4128a;hb=be7677c7dd446a9fef66fab0f258f5c1826ecc90;hp=ae7407975aab870cd12c4b3a3b5eca58abaa58f1;hpb=6d5355c3845e060d269b664be7b4284c606691b8;p=gitmo%2FClass-MOP.git diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index ae74079..24572a5 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 164; +use Test::More tests => 183; use Test::Exception; BEGIN { @@ -33,18 +33,23 @@ my @class_mop_package_methods = qw( initialize name + namespace - add_package_variable get_package_variable has_package_variable remove_package_variable + add_package_symbol get_package_symbol has_package_symbol remove_package_symbol + list_all_package_symbols remove_package_glob + + _deconstruct_variable_name ); my @class_mop_module_methods = qw( + meta + + version authority identifier ); my @class_mop_class_methods = qw( meta - get_all_metaclasses get_all_metaclass_names get_all_metaclass_instances - initialize reinitialize create create_anon_class instance_metaclass get_meta_instance @@ -52,15 +57,13 @@ my @class_mop_class_methods = qw( construct_instance construct_class_instance clone_instance check_metaclass_compatability - version - attribute_metaclass method_metaclass superclasses class_precedence_list has_method get_method add_method remove_method alias_method get_method_list compute_all_applicable_methods - find_all_methods_by_name find_next_method_by_name + find_method_by_name find_all_methods_by_name find_next_method_by_name add_before_method_modifier add_after_method_modifier add_around_method_modifier @@ -70,7 +73,7 @@ my @class_mop_class_methods = qw( is_mutable is_immutable make_immutable DESTROY - ); +); # check the class ... @@ -100,6 +103,21 @@ foreach my $method_name (@class_mop_package_methods) { } } +## check the module .... + +is_deeply([ sort @class_mop_module_methods ], [ sort $class_mop_module_meta->get_method_list ], '... got the correct method list for module'); + +foreach my $method_name (@class_mop_module_methods) { + ok($class_mop_module_meta->has_method($method_name), '... Class::MOP::Module->has_method(' . $method_name . ')'); + { + no strict 'refs'; + is($class_mop_module_meta->get_method($method_name), + \&{'Class::MOP::Module::' . $method_name}, + '... Class::MOP::Module->get_method(' . $method_name . ') == &Class::MOP::Module::' . $method_name); + } +} + + # check for imported functions which are not methods foreach my $non_method_name (qw( @@ -115,9 +133,11 @@ foreach my $non_method_name (qw( my @class_mop_package_attributes = ( '$:package', + '%:namespace', ); my @class_mop_module_attributes = ( + '$:version', '$:authority' ); my @class_mop_class_attributes = ( @@ -144,7 +164,7 @@ foreach my $attribute_name (@class_mop_class_attributes) { isa_ok($class_mop_class_meta->get_attribute($attribute_name), 'Class::MOP::Attribute'); } -# check package +# check module is_deeply( [ sort @class_mop_package_attributes ], @@ -161,6 +181,23 @@ foreach my $attribute_name (@class_mop_package_attributes) { isa_ok($class_mop_package_meta->get_attribute($attribute_name), 'Class::MOP::Attribute'); } +# check package + +is_deeply( + [ sort @class_mop_module_attributes ], + [ sort $class_mop_module_meta->get_attribute_list ], + '... got the right list of attributes'); + +is_deeply( + [ sort @class_mop_module_attributes ], + [ sort keys %{$class_mop_module_meta->get_attribute_map} ], + '... got the right list of attributes'); + +foreach my $attribute_name (@class_mop_module_attributes) { + ok($class_mop_module_meta->has_attribute($attribute_name), '... Class::MOP::Module->has_attribute(' . $attribute_name . ')'); + isa_ok($class_mop_module_meta->get_attribute($attribute_name), 'Class::MOP::Attribute'); +} + ## check the attributes themselves # ... package @@ -184,7 +221,7 @@ is($class_mop_class_meta->get_attribute('%:attributes')->init_arg, '... Class::MOP::Class %:attributes\'s a init_arg is :attributes'); ok($class_mop_class_meta->get_attribute('%:attributes')->has_default, '... Class::MOP::Class %:attributes has a default'); -is_deeply($class_mop_class_meta->get_attribute('%:attributes')->default, +is_deeply($class_mop_class_meta->get_attribute('%:attributes')->default('Foo'), {}, '... Class::MOP::Class %:attributes\'s a default of {}'); @@ -223,10 +260,10 @@ is($class_mop_class_meta->get_attribute('$:method_metaclass')->default, is($class_mop_class_meta->name, 'Class::MOP::Class', '... Class::MOP::Class->name'); is($class_mop_class_meta->version, $Class::MOP::Class::VERSION, '... Class::MOP::Class->version'); -ok($class_mop_class_meta->has_package_variable('$VERSION'), '... Class::MOP::Class->has_package_variable($VERSION)'); -is(${$class_mop_class_meta->get_package_variable('$VERSION')}, +ok($class_mop_class_meta->has_package_symbol('$VERSION'), '... Class::MOP::Class->has_package_symbol($VERSION)'); +is(${$class_mop_class_meta->get_package_symbol('$VERSION')}, $Class::MOP::Class::VERSION, - '... Class::MOP::Class->get_package_variable($VERSION)'); + '... Class::MOP::Class->get_package_symbol($VERSION)'); is_deeply( [ $class_mop_class_meta->superclasses ], @@ -238,7 +275,8 @@ is_deeply( [ qw/ Class::MOP::Class Class::MOP::Module - Class::MOP::Package + Class::MOP::Package + Class::MOP::Object / ], '... Class::MOP::Class->class_precedence_list == [ Class::MOP::Class Class::MOP::Module Class::MOP::Package ]');