X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F12-error.t;h=e253c783fb9917290974166890248f27f21910bf;hb=9eb6e8c6a5da5d60eb1986db304565b8ea826aed;hp=fcd29dc8644c5b4b8a710d3cc1a8974bc96fb349;hpb=ae99852990e7c7faf5d4f44fc58f144d1b5dd2fd;p=gitmo%2FMooseX-Types-Structured.git diff --git a/t/12-error.t b/t/12-error.t index fcd29dc..e253c78 100644 --- a/t/12-error.t +++ b/t/12-error.t @@ -1,7 +1,7 @@ BEGIN { - use strict; - use warnings; - use Test::More tests=>25; + use strict; + use warnings; + use Test::More tests=>25; } use Moose::Util::TypeConstraints; @@ -29,7 +29,7 @@ like $simple_tuple->validate({a=>1,b=>2}), like $simple_tuple->validate(['a','b']), qr/failed for 'simple_tuple' with value \[ "a", "b" \]/, 'Correctly failed due to "a" not an Int'; - + like $simple_tuple->validate([1,$simple_tuple]), qr/Validation failed for 'simple_tuple' with value \[ 1, MooseX::Meta::TypeConstraint::Structured/, 'Correctly failed due to object not a Str'; @@ -47,11 +47,11 @@ like $simple_tuple->validate([1,'hello','too many']), like $simple_dict->validate([1,2]), qr/ with value \[ 1, 2 \]/, 'Wrong basic type'; - + like $simple_dict->validate({name=>'John',age=>'a'}), qr/failed for 'Int' with value a/, 'Correctly failed due to age not an Int'; - + like $simple_dict->validate({name=>$simple_dict,age=>1}), qr/with value { age: 1, name: MooseX:/, 'Correctly failed due to object not a Str'; @@ -63,12 +63,12 @@ like $simple_dict->validate({name=>'John'}), like $simple_dict->validate({name=>'Vincent', age=>15,extra=>'morethanIneed'}), qr/More values than Type Constraints!/, 'Too Many values'; - + ## TODO some with Optional (or Maybe) and slurpy - + my $optional_tuple = subtype 'optional_tuple', as Tuple[Int,Optional[Str]]; my $optional_dict = subtype 'optional_dict', as Dict[name=>Str,age=>Optional[Int]]; - + like $optional_tuple->validate({a=>1,b=>2}), qr/Validation failed for 'optional_tuple' with value { a: 1, b: 2 }/, 'Wrong basic type'; @@ -76,7 +76,7 @@ like $simple_dict->validate({name=>'Vincent', age=>15,extra=>'morethanIneed'}), like $optional_tuple->validate(['a','b']), qr/failed for 'Int' with value a/, 'Correctly failed due to "a" not an Int'; - + like $optional_tuple->validate([1,$simple_tuple]), qr/failed for 'MooseX::Types::Structured::Optional\[Str\]' with value MooseX/, 'Correctly failed due to object not a Str'; @@ -88,11 +88,11 @@ like $optional_tuple->validate([1,'hello','too many']), like $optional_dict->validate([1,2]), qr/ with value \[ 1, 2 \]/, 'Wrong basic type'; - + like $optional_dict->validate({name=>'John',age=>'a'}), qr/Validation failed for 'MooseX::Types::Structured::Optional\[Int\]' with value a/, 'Correctly failed due to age not an Int'; - + like $optional_dict->validate({name=>$simple_dict,age=>1}), qr/with value { age: 1, name: MooseX:/, 'Correctly failed due to object not a Str'; @@ -100,7 +100,7 @@ like $optional_dict->validate({name=>$simple_dict,age=>1}), like $optional_dict->validate({name=>'Vincent', age=>15,extra=>'morethanIneed'}), qr/More values than Type Constraints!/, 'Too Many values'; - + ## Deeper constraints my $deep_tuple = subtype 'deep_tuple', @@ -112,14 +112,14 @@ my $deep_tuple = subtype 'deep_tuple', age=>Int, ], ]; - + ok $deep_tuple->check([1,{a=>2},{name=>'Vincent',age=>15}]), 'Good Constraint'; - + like $deep_tuple->validate([1,{a=>2},{name=>'Vincent',age=>'Hello'}]), qr/Error is: Validation failed for 'MooseX::Types::Structured::Dict\[name,Str,age,Int\]'/, 'Example deeper error'; - + ## Success Tests... ok !$deep_tuple->validate([1,{a=>2},{name=>'John',age=>40}]), 'Validates ok';