X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F12_wrapper-definition.t;h=9284eec1eea7d222cbc02ee6879d42d2c0d82914;hb=f5559e1ce7a42af91a0e64915a8cb1e08958ae63;hp=2735246476d9b84489613c34cab78b76193729b0;hpb=c20dc98b99b75137f83b646bb705de4b90e10d45;p=gitmo%2FMooseX-Types.git diff --git a/t/12_wrapper-definition.t b/t/12_wrapper-definition.t index 2735246..9284eec 100644 --- a/t/12_wrapper-definition.t +++ b/t/12_wrapper-definition.t @@ -5,24 +5,27 @@ use strict; use Test::More; use FindBin; use lib "$FindBin::Bin/lib"; +use Moose::Util::TypeConstraints; +BEGIN { coerce 'Str', from 'Int', via { "$_" } } use TestWrapper TestLibrary => [qw( NonEmptyStr IntArrayRef )], Moose => [qw( Str Int )]; + my @tests = ( - [ 'NonEmptyStr', 12, "12", [], "foobar", "" ], - [ 'IntArrayRef', 12, [12], {}, [17, 23], {} ], + [ 'NonEmptyStr', 'TestLibrary::NonEmptyStr', 12, "12", [], "foobar", "" ], + [ 'IntArrayRef', 'TestLibrary::IntArrayRef', 12, [12], {}, [17, 23], {} ], + [ 'Str', 'Str', 12, "12", [], "foo", [777] ], ); -plan tests => (@tests * 8); - # new array ref so we can safely shift from it for my $data (map { [@$_] } @tests) { my $type = shift @$data; + my $full = shift @$data; # Type name export { ok my $code = __PACKAGE__->can($type), "$type() was exported"; - is $code->(), "TestLibrary::$type", "$type() returned correct type name"; + is $code->(), $full, "$type() returned correct type name"; } # coercion handler export @@ -30,7 +33,8 @@ for my $data (map { [@$_] } @tests) { my ($coerce, $coercion_result, $cannot_coerce) = map { shift @$data } 1 .. 3; ok my $code = __PACKAGE__->can("to_$type"), "to_$type() coercion was exported"; is_deeply scalar $code->($coerce), $coercion_result, "to_$type() coercion works"; - ok ! $code->($cannot_coerce), "to_$type() returns false on invalid value"; + eval { $code->($cannot_coerce) }; + is $@, "coercion returned undef\n", "to_$type() died on invalid value"; } # type test handler @@ -39,7 +43,8 @@ for my $data (map { [@$_] } @tests) { ok my $code = __PACKAGE__->can("is_$type"), "is_$type() check was exported"; ok $code->($valid), "is_$type() check true on valid value"; ok ! $code->($invalid), "is_$type() check false on invalid value"; + is ref($code->()), 'CODE', "is_$type() returns test closure without args"; } } - +done_testing;