1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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;
|