make inlining a bit more easily extensible
[gitmo/Class-MOP.git] / t / 014_attribute_introspection.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Test::Fatal;
6
7 use Class::MOP;
8
9 {
10     my $attr = Class::MOP::Attribute->new('$test');
11     is( $attr->meta, Class::MOP::Attribute->meta,
12         '... instance and class both lead to the same meta' );
13 }
14
15 {
16     my $meta = Class::MOP::Attribute->meta();
17     isa_ok( $meta, 'Class::MOP::Class' );
18
19     my @methods = qw(
20         new
21         clone
22
23         initialize_instance_slot
24         _set_initial_slot_value
25
26         name
27         has_accessor      accessor
28         has_writer        writer
29         has_write_method  get_write_method  get_write_method_ref
30         has_reader        reader
31         has_read_method   get_read_method   get_read_method_ref
32         has_predicate     predicate
33         has_clearer       clearer
34         has_builder       builder
35         has_init_arg      init_arg
36         has_default       default           is_default_a_coderef
37         has_initializer   initializer
38         has_insertion_order insertion_order _set_insertion_order
39
40         definition_context
41
42         slots
43         get_value
44         set_value
45         get_raw_value
46         set_raw_value
47         set_initial_value
48         has_value
49         clear_value
50
51         associated_class
52         attach_to_class
53         detach_from_class
54
55         accessor_metaclass
56
57         associated_methods
58         associate_method
59
60         process_accessors
61         _process_accessors
62         install_accessors
63         remove_accessors
64
65         _inline_get_value
66         _inline_set_value
67         _inline_has_value
68         _inline_clear_value
69         _inline_instance_get
70         _inline_instance_set
71         _inline_instance_has
72         _inline_instance_clear
73
74         _new
75     );
76
77     is_deeply(
78         [
79             sort Class::MOP::Mixin::AttributeCore->meta->get_method_list,
80             $meta->get_method_list
81         ],
82         [ sort @methods ],
83         '... our method list matches'
84     );
85
86     foreach my $method_name (@methods) {
87         ok( $meta->find_method_by_name($method_name),
88             '... Class::MOP::Attribute->find_method_by_name(' . $method_name . ')' );
89     }
90
91     my @attributes = (
92         'name',
93         'accessor',
94         'reader',
95         'writer',
96         'predicate',
97         'clearer',
98         'builder',
99         'init_arg',
100         'initializer',
101         'definition_context',
102         'default',
103         'associated_class',
104         'associated_methods',
105         'insertion_order',
106     );
107
108     is_deeply(
109         [
110             sort Class::MOP::Mixin::AttributeCore->meta->get_attribute_list,
111             $meta->get_attribute_list
112         ],
113         [ sort @attributes ],
114         '... our attribute list matches'
115     );
116
117     foreach my $attribute_name (@attributes) {
118         ok( $meta->find_attribute_by_name($attribute_name),
119                   '... Class::MOP::Attribute->find_attribute_by_name('
120                 . $attribute_name
121                 . ')' );
122     }
123
124     # We could add some tests here to make sure that
125     # the attribute have the appropriate
126     # accessor/reader/writer/predicate combinations,
127     # but that is getting a little excessive so I
128     # wont worry about it for now. Maybe if I get
129     # bored I will do it.
130 }
131
132 done_testing;