give the initializer a test
[gitmo/Class-MOP.git] / t / 014_attribute_introspection.t
CommitLineData
5659d76e 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
0ab65f99 6use Test::More tests => 58;
5659d76e 7use Test::Exception;
8
9BEGIN {
1d68af04 10 use_ok('Class::MOP');
5659d76e 11}
12
13{
013b1897 14 my $attr = Class::MOP::Attribute->new('$test');
15 is($attr->meta, Class::MOP::Attribute->meta, '... instance and class both lead to the same meta');
16}
17
18{
5659d76e 19 my $meta = Class::MOP::Attribute->meta();
20 isa_ok($meta, 'Class::MOP::Class');
1d68af04 21
5659d76e 22 my @methods = qw(
aa448b16 23 meta
5659d76e 24 new clone
1d68af04 25
bd4e03f9 26 initialize_instance_slot
1d68af04 27
5659d76e 28 name
29 has_accessor accessor
1bd2739a 30 has_writer writer get_write_method get_write_method_ref
31 has_reader reader get_read_method get_read_method_ref
5659d76e 32 has_predicate predicate
7d28758b 33 has_clearer clearer
1d68af04 34 has_builder builder
5659d76e 35 has_init_arg init_arg
495af518 36 has_default default is_default_a_coderef
0ab65f99 37 has_initializer initializer
1d68af04 38
c57c8b10 39 slots
16e960bd 40 get_value
41 set_value
3545c727 42 has_value
43 clear_value
1d68af04 44
5659d76e 45 associated_class
1d68af04 46 attach_to_class detach_from_class
47
ba38bf08 48 accessor_metaclass
1d68af04 49
3545c727 50 associated_methods
51 associate_method
1d68af04 52
5659d76e 53 process_accessors
54 install_accessors
55 remove_accessors
56 );
1d68af04 57
5659d76e 58 is_deeply(
5659d76e 59 [ sort $meta->get_method_list ],
7d28758b 60 [ sort @methods ],
1d68af04 61 '... our method list matches');
62
5659d76e 63 foreach my $method_name (@methods) {
64 ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
65 }
1d68af04 66
c23184fc 67 my @attributes = (
68 '$!name',
69 '$!accessor',
70 '$!reader',
71 '$!writer',
72 '$!predicate',
73 '$!clearer',
1d68af04 74 '$!builder',
c23184fc 75 '$!init_arg',
76 '$!default',
77 '$!associated_class',
78 '@!associated_methods',
1bd2739a 79 );
5659d76e 80
81 is_deeply(
5659d76e 82 [ sort $meta->get_attribute_list ],
7d28758b 83 [ sort @attributes ],
5659d76e 84 '... our attribute list matches');
1d68af04 85
5659d76e 86 foreach my $attribute_name (@attributes) {
1d68af04 87 ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')');
5659d76e 88 }
1d68af04 89
90 # We could add some tests here to make sure that
91 # the attribute have the appropriate
92 # accessor/reader/writer/predicate combinations,
93 # but that is getting a little excessive so I
94 # wont worry about it for now. Maybe if I get
5659d76e 95 # bored I will do it.
2d711cc8 96}