df220136e1d65026f89b7f482790da2445bd5c57
[gitmo/MooseX-MetaDescription.git] / t / 001_basic.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 metaclass 'MooseX::MetaDescription::Meta::Class';
16     use Moose;
17     
18     __PACKAGE__->meta->description->{'Hello'} = 'World';
19     
20     has 'bar' => (
21         metaclass   => 'MooseX::MetaDescription::Meta::Attribute',
22         is          => 'ro',
23         isa         => 'Str',   
24         default     => sub { 'Foo::bar' },
25         description => {
26             baz   => 'Foo::bar::baz',
27             gorch => 'Foo::bar::gorch',
28         }
29     );
30     
31     has 'baz' => (
32         traits      => [ 'MooseX::MetaDescription::Meta::Attribute::Trait' ],
33         is          => 'ro',
34         isa         => 'Str',   
35         default     => sub { 'Foo::baz' },
36         description => {
37             bar   => 'Foo::baz::bar',
38             gorch => 'Foo::baz::gorch',
39         }
40     );    
41 }
42
43 # check the meta-desc
44
45 my $foo_class = Foo->meta;
46 is($foo_class->metadescription->descriptor, $foo_class, '... got the circular ref');
47
48 my $bar_attr = Foo->meta->get_attribute('bar');
49 is($bar_attr->metadescription->descriptor, $bar_attr, '... got the circular ref');
50
51 my $baz_attr = Foo->meta->get_attribute('baz');
52 is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref');
53
54 # check the actual descs
55
56 foreach my $foo ('Foo', Foo->new) {
57     is_deeply(
58         $foo->meta->description,
59         { 'Hello' => 'World' },
60         '... got the right class description'
61     );
62
63     is_deeply(
64         $foo->meta->get_attribute('bar')->description,
65         {
66             baz   => 'Foo::bar::baz',
67             gorch => 'Foo::bar::gorch',
68         },
69         '... got the right class description'
70     );
71
72     is_deeply(
73         $foo->meta->get_attribute('baz')->description,
74         {
75             bar   => 'Foo::baz::bar',
76             gorch => 'Foo::baz::gorch',
77         },
78         '... got the right class description'
79     );
80 }
81