diff options
Diffstat (limited to 't/exceptions/moose-meta-typeconstraint-parameterized.t')
-rw-r--r-- | t/exceptions/moose-meta-typeconstraint-parameterized.t | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/t/exceptions/moose-meta-typeconstraint-parameterized.t b/t/exceptions/moose-meta-typeconstraint-parameterized.t new file mode 100644 index 0000000..ae685a8 --- /dev/null +++ b/t/exceptions/moose-meta-typeconstraint-parameterized.t @@ -0,0 +1,83 @@ +use strict; +use warnings; + +use Test::More; +use Test::Fatal; + +{ + my $exception = exception { + Moose::Meta::TypeConstraint::Parameterized->new( name => "TestType" ); + }; + + like( + $exception, + qr/You cannot create a Higher Order type without a type parameter/, + "type_parameter not given"); + + isa_ok( + $exception, + 'Moose::Exception::CannotCreateHigherOrderTypeWithoutATypeParameter', + "type_parameter not given"); + + is( + $exception->type_name, + "TestType", + "type_parameter not given"); +} + +{ + my $exception = exception { + Moose::Meta::TypeConstraint::Parameterized->new( name => "TestType2", + type_parameter => 'Int' + ); + }; + + like( + $exception, + qr/The type parameter must be a Moose meta type/, + "'Int' is not a Moose::Meta::TypeConstraint"); + + isa_ok( + $exception, + 'Moose::Exception::TypeParameterMustBeMooseMetaType', + "'Int' is not a Moose::Meta::TypeConstraint"); + + is( + $exception->type_name, + "TestType2", + "'Int' is not a Moose::Meta::TypeConstraint"); +} + +{ + my $exception = exception { + package Foo; + use Moose; + + has 'foo' => ( + is => 'ro', + isa => 'Int[Xyz]', + ); + }; + + like( + $exception, + qr/\QThe Int[Xyz] constraint cannot be used, because Int doesn't subtype or coerce from a parameterizable type./, + "invalid isa given to foo"); + + isa_ok( + $exception, + 'Moose::Exception::TypeConstraintCannotBeUsedForAParameterizableType', + "invalid isa given to foo"); + + is( + $exception->type_name, + "Int[Xyz]", + "invalid isa given to foo"); + + is( + $exception->parent_type_name, + 'Int', + "invalid isa given to foo"); +} + +done_testing; |