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