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