got rid of all the use_ok junk except for 000_load.t
[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 => 62;
7 use Test::Exception;
8
9 use Class::MOP;
10
11 {
12     my $attr = Class::MOP::Attribute->new('$test');
13     is($attr->meta, Class::MOP::Attribute->meta, '... instance and class both lead to the same meta');
14 }
15
16 {
17     my $meta = Class::MOP::Attribute->meta();
18     isa_ok($meta, 'Class::MOP::Class');
19
20     my @methods = qw(
21         new
22         clone
23
24         initialize_instance_slot
25         _set_initial_slot_value
26
27         name
28         has_accessor      accessor
29         has_writer        writer
30         has_write_method  get_write_method  get_write_method_ref
31         has_reader        reader
32         has_read_method   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
49         detach_from_class
50
51         accessor_metaclass
52
53         associated_methods
54         associate_method
55
56         process_accessors
57         install_accessors
58         remove_accessors
59
60         _new
61         );
62
63     is_deeply(
64         [ sort $meta->get_method_list ],
65         [ sort @methods ],
66         '... our method list matches');
67
68     foreach my $method_name (@methods) {
69         ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
70     }
71
72     my @attributes = (
73         'name',
74         'accessor',
75         'reader',
76         'writer',
77         'predicate',
78         'clearer',
79         'builder',
80         'init_arg',
81         'initializer',
82         'default',
83         'associated_class',
84         'associated_methods',
85     );
86
87     is_deeply(
88         [ sort $meta->get_attribute_list ],
89         [ sort @attributes ],
90         '... our attribute list matches');
91
92     foreach my $attribute_name (@attributes) {
93         ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')');
94     }
95
96     # We could add some tests here to make sure that
97     # the attribute have the appropriate
98     # accessor/reader/writer/predicate combinations,
99     # but that is getting a little excessive so I
100     # wont worry about it for now. Maybe if I get
101     # bored I will do it.
102 }