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