diff options
Diffstat (limited to 't/exceptions/moose-meta-typecoercion.t')
-rw-r--r-- | t/exceptions/moose-meta-typecoercion.t | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/t/exceptions/moose-meta-typecoercion.t b/t/exceptions/moose-meta-typecoercion.t new file mode 100644 index 0000000..50a73ab --- /dev/null +++ b/t/exceptions/moose-meta-typecoercion.t @@ -0,0 +1,59 @@ +use strict; +use warnings; + +use Test::More; +use Test::Fatal; + +use Moose::Util::TypeConstraints; + +{ + subtype 'typeInt', + as 'Int'; + + my $exception = exception { + coerce 'typeInt', + from 'xyz'; + }; + + like( + $exception, + qr/\QCould not find the type constraint (xyz) to coerce from/, + "xyz is not a valid type constraint"); + + isa_ok( + $exception, + "Moose::Exception::CouldNotFindTypeConstraintToCoerceFrom", + "xyz is not a valid type constraint"); + + is( + $exception->constraint_name, + "xyz", + "xyz is not a valid type constraint"); +} + +{ + subtype 'typeInt', + as 'Int'; + + my $exception = exception { + coerce 'typeInt', from 'Int', via { "123" }; + coerce 'typeInt', from 'Int', via { 12 }; + }; + + like( + $exception, + qr/\QA coercion action already exists for 'Int'/, + "coercion already exists"); + + isa_ok( + $exception, + "Moose::Exception::CoercionAlreadyExists", + "coercion already exists"); + + is( + $exception->constraint_name, + "Int", + "coercion already exists"); +} + +done_testing; |