5 use Test::More tests => 26;
8 use lib "$FindBin::Bin/lib";
11 package Test::MooseX::TypeLibrary::TypeDecorator;
14 use MooseX::Types::Moose qw(
17 use DecoratorLibrary qw(
18 MyArrayRefBase MyArrayRefInt01 MyArrayRefInt02
21 has 'arrayrefbase' => (is=>'rw', isa=>MyArrayRefBase, coerce=>1);
22 has 'arrayrefint01' => (is=>'rw', isa=>MyArrayRefInt01, coerce=>1);
23 has 'arrayrefint02' => (is=>'rw', isa=>MyArrayRefInt02, coerce=>1);
24 has 'arrayrefint03' => (is=>'rw', isa=>MyArrayRefBase[Int]);
27 ## Make sure we have a 'create object sanity check'
29 ok my $type = Test::MooseX::TypeLibrary::TypeDecorator->new(),
30 => 'Created some sort of object';
32 isa_ok $type, 'Test::MooseX::TypeLibrary::TypeDecorator'
33 => "Yes, it's the correct kind of object";
35 ## test arrayrefbase normal and coercion
37 ok $type->arrayrefbase([qw(a b c)])
38 => 'Assigned arrayrefbase qw(a b c)';
40 is_deeply $type->arrayrefbase, [qw(a b c)],
41 => 'Assignment is correct';
43 ok $type->arrayrefbase('d,e,f')
44 => 'Assignment arrayrefbase d,e,f to test coercion';
46 is_deeply $type->arrayrefbase, [qw(d e f)],
47 => 'Assignment and coercion is correct';
49 ## test arrayrefint01 normal and coercion
51 ok $type->arrayrefint01([qw(1 2 3)])
52 => 'Assignment arrayrefint01 qw(1 2 3)';
54 is_deeply $type->arrayrefint01, [qw(1 2 3)],
55 => 'Assignment is correct';
57 ok $type->arrayrefint01('4.5.6')
58 => 'Assigned arrayrefint01 4.5.6 to test coercion from Str';
60 is_deeply $type->arrayrefint01, [qw(4 5 6)],
61 => 'Assignment and coercion is correct';
63 ok $type->arrayrefint01({a=>7,b=>8})
64 => 'Assigned arrayrefint01 {a=>7,b=>8} to test coercion from HashRef';
66 is_deeply $type->arrayrefint01, [qw(7 8)],
67 => 'Assignment and coercion is correct';
70 $type->arrayrefint01([qw(a b c)])
71 }, qr/Attribute \(arrayrefint01\) does not pass the type constraint/ => 'Dies when values are strings';
73 ## test arrayrefint02 normal and coercion
75 ok $type->arrayrefint02([qw(1 2 3)])
76 => 'Assigned arrayrefint02 qw(1 2 3)';
78 is_deeply $type->arrayrefint02, [qw(1 2 3)],
79 => 'Assignment is correct';
81 ok $type->arrayrefint02('4:5:6')
82 => 'Assigned arrayrefint02 4:5:6 to test coercion from Str';
84 is_deeply $type->arrayrefint02, [qw(4 5 6)],
85 => 'Assignment and coercion is correct';
87 ok $type->arrayrefint02({a=>7,b=>8})
88 => 'Assigned arrayrefint02 {a=>7,b=>8} to test coercion from HashRef';
90 is_deeply $type->arrayrefint02, [qw(7 8)],
91 => 'Assignment and coercion is correct';
93 ok $type->arrayrefint02({a=>'AA',b=>'BBB', c=>'CCCCCCC'})
94 => "Assigned arrayrefint02 {a=>'AA',b=>'BBB', c=>'CCCCCCC'} to test coercion from HashRef";
96 is_deeply $type->arrayrefint02, [qw(2 3 7)],
97 => 'Assignment and coercion is correct';
99 ok $type->arrayrefint02({a=>[1,2],b=>[3,4]})
100 => "Assigned arrayrefint02 {a=>[1,2],b=>[3,4]} to test coercion from HashRef";
102 is_deeply $type->arrayrefint02, [qw(1 2 3 4)],
103 => 'Assignment and coercion is correct';
107 ok $type->arrayrefint03([qw(11 12 13)])
108 => 'Assigned arrayrefint01 qw(11 12 13)';
110 is_deeply $type->arrayrefint03, [qw(11 12 13)],
111 => 'Assignment is correct';
114 $type->arrayrefint03([qw(a b c)])
115 }, qr/Attribute \(arrayrefint03\) does not pass the type constraint/ => 'Dies when values are strings';