X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F02-constraints.t;h=21cf74adaf05afad38d2f81b5c0cba5c652146e4;hb=335d990612412620aee1b2644aee8464714adcea;hp=270b68c30a663712c0264de267d6cf96f6d6196b;hpb=13cf7c3bca2fb15e1bd70443e3b980c5b857c645;p=gitmo%2FMooseX-Types-Structured.git diff --git a/t/02-constraints.t b/t/02-constraints.t index 270b68c..21cf74a 100644 --- a/t/02-constraints.t +++ b/t/02-constraints.t @@ -1,7 +1,7 @@ BEGIN { use strict; use warnings; - use Test::More tests=>42; + use Test::More tests=>47; use Test::Exception; } @@ -24,7 +24,8 @@ BEGIN { has 'dict_with_tuple' => (is=>'rw', isa=>Dict[key1=>'Str', key2=>Tuple['Int','Str']]); has 'optional_tuple' => (is=>'rw', isa=>Tuple['Int', 'Int', Optional['Int']] ); has 'optional_dict' => (is=>'rw', isa=>Dict[key1=>'Int', Optional[key2=>'Int']] ); - + has 'dict_with_tuple_with_union' => (is=>'rw', isa=>Dict[key1=>'Str|Object', key2=>Tuple['Int','Str|Object']] ); + has 'crazy' => ( is=>'rw', isa=>Tuple @@ -229,4 +230,28 @@ throws_ok sub { $record->optional_dict({key1=>1,key2=>'bad'}); }, qr/Validation failed for 'Int'/ => 'Properly failed for bad value in optional bit'; - \ No newline at end of file + + +## Test dict_with_tuple_with_union: Dict[key1=>'Str|Object', key2=>Tuple['Int','Str|Object']] + +lives_ok sub { + $record->dict_with_tuple_with_union({key1=>'Hello', key2=>[1,'World']}); +} => 'Set tuple attribute without error'; + +throws_ok sub { + $record->dict_with_tuple_with_union({key1=>'Hello', key2=>['World',2]}); +}, qr/Validation failed for 'Int'/ + => 'Threw error on bad constraint'; + +lives_ok sub { + $record->dict_with_tuple_with_union({key1=>$record, key2=>[1,'World']}); +} => 'Set tuple attribute without error'; + +lives_ok sub { + $record->dict_with_tuple_with_union({key1=>'Hello', key2=>[1,$record]}); +} => 'Set tuple attribute without error'; + +throws_ok sub { + $record->dict_with_tuple_with_union({key1=>1, key2=>['World',2]}); +}, qr/Validation failed for 'Int'/ + => 'Threw error on bad constraint'; \ No newline at end of file