adding more tests
[gitmo/MooseX-MetaDescription.git] / t / 003_inheriting_meta_desc.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More no_plan => 1;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('MooseX::MetaDescription');
11 }
12
13 {
14     package Foo;
15     use Moose;
16     
17     has 'bar' => (
18         metaclass   => 'MooseX::MetaDescription::Meta::Attribute',
19         is          => 'ro',
20         isa         => 'Str',   
21         default     => sub { 'Foo::bar' },
22         description => {
23             baz   => 'Foo::bar::baz',
24             gorch => 'Foo::bar::gorch',
25         }
26     );    
27     
28     has 'baz' => (
29         traits      => [ 'MooseX::MetaDescription::Meta::Trait' ],
30         is          => 'ro',
31         isa         => 'Str',   
32         default     => sub { 'Foo::baz' },
33         description => {
34             bar   => 'Foo::baz::bar',
35             gorch => 'Foo::baz::gorch',
36         }
37     );    
38     
39     package Bar;
40     use Moose;
41     
42     extends 'Foo';
43 }
44
45 # check the meta-desc
46
47 my $bar_attr = Foo->meta->find_attribute_by_name('bar');
48 isa_ok($bar_attr->metadescription, 'MooseX::MetaDescription::Description');
49 is($bar_attr->metadescription->descriptor, $bar_attr, '... got the circular ref');
50
51 my $baz_attr = Foo->meta->find_attribute_by_name('baz');
52 isa_ok($baz_attr->metadescription, 'MooseX::MetaDescription::Description');
53 is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref');
54
55 {
56     
57     my $bar_attr = Bar->meta->find_attribute_by_name('bar');
58     
59     can_ok($bar_attr, 'description');    
60     isa_ok($bar_attr->metadescription, 'MooseX::MetaDescription::Description');
61     is($bar_attr->metadescription->descriptor, $bar_attr, '... got the circular ref');
62     
63     my $baz_attr = Bar->meta->find_attribute_by_name('baz');
64     
65     can_ok($baz_attr, 'description');    
66     isa_ok($baz_attr->metadescription, 'MooseX::MetaDescription::Description');
67     is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref');
68     
69     my ($bar_attr_2, $baz_attr_2) = Bar->meta->compute_all_applicable_attributes;
70     is($bar_attr, $bar_attr_2, '... got the same attribute');
71     is($baz_attr, $baz_attr_2, '... got the same attribute');
72 }
73
74 # check the actual descs
75
76 foreach my $foo ('Foo', Foo->new, 'Bar', Bar->new) {
77
78     is_deeply(
79         $foo->meta->find_attribute_by_name('bar')->description,
80         {
81             baz   => 'Foo::bar::baz',
82             gorch => 'Foo::bar::gorch',
83         },
84         '... got the right class description'
85     );
86
87     is_deeply(
88         $foo->meta->find_attribute_by_name('baz')->description,
89         {
90             bar   => 'Foo::baz::bar',
91             gorch => 'Foo::baz::gorch',
92         },
93         '... got the right class description'
94     );
95 }