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