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