The great Class::MOP::Instance refactoring
[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 => 43;
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         
28         name
29         has_accessor  accessor
30         has_writer    writer
31         has_reader    reader
32         has_predicate predicate
33         has_init_arg  init_arg
34         has_default   default
35         
36         associated_class
37         attach_to_class detach_from_class
38         
39         generate_accessor_method
40         generate_reader_method
41         generate_writer_method
42         generate_predicate_method
43         
44         process_accessors
45         install_accessors
46         remove_accessors
47
48                 slot_name
49                 allocate_slots
50                 deallocate_slots
51         );
52         
53     is_deeply(
54         [ sort @methods ],
55         [ sort $meta->get_method_list ],
56         '... our method list matches');        
57     
58     foreach my $method_name (@methods) {
59         ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
60     }
61     
62     my @attributes = qw(
63         name accessor reader writer predicate
64         init_arg default associated_class
65         );
66
67     is_deeply(
68         [ sort @attributes ],
69         [ sort $meta->get_attribute_list ],
70         '... our attribute list matches');
71     
72     foreach my $attribute_name (@attributes) {
73         ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')');        
74     }
75     
76     # We could add some tests here to make sure that 
77     # the attribute have the appropriate 
78     # accessor/reader/writer/predicate combinations, 
79     # but that is getting a little excessive so I  
80     # wont worry about it for now. Maybe if I get 
81     # bored I will do it.
82 }