more refactoring to roles
[gitmo/MooseX-MetaDescription.git] / t / 001_basic.t
CommitLineData
c13295c8 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More no_plan => 1;
7use Test::Exception;
8
9BEGIN {
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
45my $foo_class = Foo->meta;
de7ba0e9 46is($foo_class->metadescription->descriptor, $foo_class, '... got the circular ref');
c13295c8 47
48my $bar_attr = Foo->meta->get_attribute('bar');
de7ba0e9 49is($bar_attr->metadescription->descriptor, $bar_attr, '... got the circular ref');
c13295c8 50
51my $baz_attr = Foo->meta->get_attribute('baz');
de7ba0e9 52is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref');
c13295c8 53
54# check the actual descs
55
56foreach 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