X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F13_typedecorator.t;h=a73cebeb74d341f8c6aee8be805f67c7bd884508;hb=e9dc30af81ed775a6ac0a0f0c1daad021e5569f6;hp=a418d1b22a2ef0d2cbb2c0e92140513266923040;hpb=ae2796571e9fac6b5109ecd08d6aaaa1cd3df893;p=gitmo%2FMooseX-Types.git diff --git a/t/13_typedecorator.t b/t/13_typedecorator.t index a418d1b..a73cebe 100644 --- a/t/13_typedecorator.t +++ b/t/13_typedecorator.t @@ -9,7 +9,7 @@ use lib "$FindBin::Bin/lib"; { package Test::MooseX::TypeLibrary::TypeDecorator; - + use Moose; use MooseX::Types::Moose qw( Int Str ArrayRef HashRef Object @@ -19,27 +19,27 @@ use lib "$FindBin::Bin/lib"; AtLeastOneInt Jobs SubOfMyArrayRefInt01 WierdIntegersArrayRef1 WierdIntegersArrayRef2 ); - + has 'arrayrefbase' => (is=>'rw', isa=>MyArrayRefBase, coerce=>1); has 'arrayrefint01' => (is=>'rw', isa=>MyArrayRefInt01, coerce=>1); has 'arrayrefint02' => (is=>'rw', isa=>MyArrayRefInt02, coerce=>1); has 'arrayrefint03' => (is=>'rw', isa=>MyArrayRefBase[Int]); has 'StrOrArrayRef_attr' => (is=>'rw', isa=>StrOrArrayRef); has 'AtLeastOneInt_attr' => (is=>'rw', isa=>AtLeastOneInt); - has 'pipeoverloading' => (is=>'rw', isa=>Int|Str); + has 'pipeoverloading' => (is=>'rw', isa=>Int|Str); has 'deep' => (is=>'rw', isa=>ArrayRef[ArrayRef[HashRef[Int]]] ); has 'deep2' => (is=>'rw', isa=>ArrayRef[Int|ArrayRef[HashRef[Int|Object]]] ); has 'enum' => (is=>'rw', isa=>Jobs); has 'SubOfMyArrayRefInt01_attr' => (is=>'rw', isa=>SubOfMyArrayRefInt01); has 'WierdIntegersArrayRef1_attr' => (is=>'rw', isa=>WierdIntegersArrayRef1); - has 'WierdIntegersArrayRef2_attr' => (is=>'rw', isa=>WierdIntegersArrayRef2); + has 'WierdIntegersArrayRef2_attr' => (is=>'rw', isa=>WierdIntegersArrayRef2); } ## Make sure we have a 'create object sanity check' ok my $type = Test::MooseX::TypeLibrary::TypeDecorator->new(), => 'Created some sort of object'; - + isa_ok $type, 'Test::MooseX::TypeLibrary::TypeDecorator' => "Yes, it's the correct kind of object"; @@ -47,13 +47,13 @@ isa_ok $type, 'Test::MooseX::TypeLibrary::TypeDecorator' ok $type->arrayrefbase([qw(a b c d e)]) => 'Assigned arrayrefbase qw(a b c d e)'; - + is_deeply $type->arrayrefbase, [qw(a b c d e)], => 'Assignment is correct'; ok $type->arrayrefbase('d,e,f') => 'Assignment arrayrefbase d,e,f to test coercion'; - + is_deeply $type->arrayrefbase, [qw(d e f)], => 'Assignment and coercion is correct'; @@ -61,22 +61,22 @@ is_deeply $type->arrayrefbase, [qw(d e f)], ok $type->arrayrefint01([qw(1 2 3)]) => 'Assignment arrayrefint01 qw(1 2 3)'; - + is_deeply $type->arrayrefint01, [qw(1 2 3)], => 'Assignment is correct'; ok $type->arrayrefint01('4.5.6') => 'Assigned arrayrefint01 4.5.6 to test coercion from Str'; - + is_deeply $type->arrayrefint01, [qw(4 5 6)], => 'Assignment and coercion is correct'; ok $type->arrayrefint01({a=>7,b=>8}) => 'Assigned arrayrefint01 {a=>7,b=>8} to test coercion from HashRef'; - + is_deeply $type->arrayrefint01, [qw(7 8)], => 'Assignment and coercion is correct'; - + like exception { $type->arrayrefint01([qw(a b c)]) }, qr/Attribute \(arrayrefint01\) does not pass the type constraint/ => 'Dies when values are strings'; @@ -85,42 +85,42 @@ like exception { ok $type->arrayrefint02([qw(1 2 3)]) => 'Assigned arrayrefint02 qw(1 2 3)'; - + is_deeply $type->arrayrefint02, [qw(1 2 3)], => 'Assignment is correct'; ok $type->arrayrefint02('4:5:6') => 'Assigned arrayrefint02 4:5:6 to test coercion from Str'; - + is_deeply $type->arrayrefint02, [qw(4 5 6)], => 'Assignment and coercion is correct'; ok $type->arrayrefint02({a=>7,b=>8}) => 'Assigned arrayrefint02 {a=>7,b=>8} to test coercion from HashRef'; - + is_deeply $type->arrayrefint02, [qw(7 8)], => 'Assignment and coercion is correct'; - + ok $type->arrayrefint02({a=>'AA',b=>'BBB', c=>'CCCCCCC'}) => "Assigned arrayrefint02 {a=>'AA',b=>'BBB', c=>'CCCCCCC'} to test coercion from HashRef"; - + is_deeply $type->arrayrefint02, [qw(2 3 7)], => 'Assignment and coercion is correct'; ok $type->arrayrefint02({a=>[1,2],b=>[3,4]}) => "Assigned arrayrefint02 {a=>[1,2],b=>[3,4]} to test coercion from HashRef"; - + is_deeply $type->arrayrefint02, [qw(1 2 3 4)], => 'Assignment and coercion is correct'; - -# test arrayrefint03 + +# test arrayrefint03 ok $type->arrayrefint03([qw(11 12 13)]) => 'Assigned arrayrefint01 qw(11 12 13)'; - + is_deeply $type->arrayrefint03, [qw(11 12 13)], => 'Assignment is correct'; - + like exception { $type->arrayrefint03([qw(a b c)]) }, qr/Attribute \(arrayrefint03\) does not pass the type constraint/ => 'Dies when values are strings'; @@ -132,7 +132,7 @@ ok $type->StrOrArrayRef_attr('string') ok $type->StrOrArrayRef_attr([1,2,3]) => 'arrayref part of union is good'; - + like exception { $type->StrOrArrayRef_attr({a=>111}); }, qr/Attribute \(StrOrArrayRef_attr\) does not pass the type constraint/ => 'Correctly failed to use a hashref'; @@ -144,7 +144,7 @@ ok $type->AtLeastOneInt_attr([1,2]), is_deeply $type->AtLeastOneInt_attr, [1,2] => "Got expected values."; - + like exception { $type->AtLeastOneInt_attr([]); }, qr/Attribute \(AtLeastOneInt_attr\) does not pass the type constraint/ => 'properly fails to assign as []'; @@ -157,7 +157,7 @@ like exception { ok $type->pipeoverloading(1) => 'Integer for union test accepted'; - + ok $type->pipeoverloading('a') => 'String for union test accepted'; @@ -172,7 +172,7 @@ ok $type->deep([[{a=>1,b=>2},{c=>3,d=>4}],[{e=>5}]]) is_deeply $type->deep, [[{a=>1,b=>2},{c=>3,d=>4}],[{e=>5}]], => 'Assignment is correct'; - + like exception { $type->deep({a=>1,b=>2}); }, qr/Attribute \(deep\) does not pass the type constraint/ => 'Deep Constraints properly fail'; @@ -184,7 +184,7 @@ ok $type->deep2([[{a=>1,b=>2},{c=>3,d=>4}],[{e=>5}]]) is_deeply $type->deep2, [[{a=>1,b=>2},{c=>3,d=>4}],[{e=>5}]], => 'Assignment is correct'; - + like exception { $type->deep2({a=>1,b=>2}); }, qr/Attribute \(deep2\) does not pass the type constraint/ => 'Deep Constraints properly fail'; @@ -200,14 +200,14 @@ ok $type->deep2([[{a=>1,b=>2},{c=>3,d=>$type}],[{e=>5}]]) is_deeply $type->deep2, [[{a=>1,b=>2},{c=>3,d=>$type}],[{e=>5}]], => 'Assignment is correct'; - + ok $type->deep2([1,2,3]) => 'Assigned deep2 to [1,2,3]'; is_deeply $type->deep2, [1,2,3], => 'Assignment is correct'; - + ## Test jobs ok $type->enum('Programming') @@ -225,20 +225,20 @@ ok $type->SubOfMyArrayRefInt01_attr([15,20,25]) is_deeply $type->SubOfMyArrayRefInt01_attr, [15,20,25], => 'Assignment is correct'; - + like exception { $type->SubOfMyArrayRefInt01_attr([15,5,20]); }, qr/Attribute \(SubOfMyArrayRefInt01_attr\) does not pass the type constraint/ => 'SubOfMyArrayRefInt01 Constraints properly fail'; -## test WierdIntegersArrayRef1 +## test WierdIntegersArrayRef1 ok $type->WierdIntegersArrayRef1_attr([5,10,1000]) => 'Assigned deep2 to [5,10,1000]'; is_deeply $type->WierdIntegersArrayRef1_attr, [5,10,1000], => 'Assignment is correct'; - + like exception { $type->WierdIntegersArrayRef1_attr({a=>1,b=>2}); }, qr/Attribute \(WierdIntegersArrayRef1_attr\) does not pass the type constraint/ @@ -254,14 +254,14 @@ like exception { }, qr/Attribute \(WierdIntegersArrayRef1_attr\) does not pass the type constraint/ => 'Constraints properly fail'; -## test WierdIntegersArrayRef2 +## test WierdIntegersArrayRef2 ok $type->WierdIntegersArrayRef2_attr([5,10,$type]) => 'Assigned deep2 to [5,10,$type]'; is_deeply $type->WierdIntegersArrayRef2_attr, [5,10,$type], => 'Assignment is correct'; - + like exception { $type->WierdIntegersArrayRef2_attr({a=>1,b=>2}); }, qr/Attribute \(WierdIntegersArrayRef2_attr\) does not pass the type constraint/