additional docs
[gitmo/MooseX-MetaDescription.git] / t / 003_inheriting_meta_desc.t
CommitLineData
4b67a690 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 Moose;
16
fb835cf8 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
4b67a690 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
fb835cf8 47my $bar_attr = Foo->meta->find_attribute_by_name('bar');
48isa_ok($bar_attr->metadescription, 'MooseX::MetaDescription::Description');
49is($bar_attr->metadescription->descriptor, $bar_attr, '... got the circular ref');
50
4b67a690 51my $baz_attr = Foo->meta->find_attribute_by_name('baz');
52isa_ok($baz_attr->metadescription, 'MooseX::MetaDescription::Description');
53is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref');
54
55{
fb835cf8 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
4b67a690 63 my $baz_attr = Bar->meta->find_attribute_by_name('baz');
fb835cf8 64
4b67a690 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
fb835cf8 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');
4b67a690 71 is($baz_attr, $baz_attr_2, '... got the same attribute');
72}
73
74# check the actual descs
75
76foreach my $foo ('Foo', Foo->new, 'Bar', Bar->new) {
77
78 is_deeply(
fb835cf8 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(
4b67a690 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}