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
|
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Moose();
{
my $exception = exception {
my $method = Moose::Meta::TypeConstraint::Enum->new( values => []);
};
like(
$exception,
qr/You must have at least one value to enumerate through/,
"an Array ref of zero length is given as values");
isa_ok(
$exception,
"Moose::Exception::MustHaveAtLeastOneValueToEnumerate",
"an Array ref of zero length is given as values");
}
{
my $exception = exception {
my $method = Moose::Meta::TypeConstraint::Enum->new( values => [undef]);
};
like(
$exception,
qr/Enum values must be strings, not undef/,
"undef is given to values");
isa_ok(
$exception,
"Moose::Exception::EnumValuesMustBeString",
"undef is given to values");
}
{
my $arrayRef = [1,2,3];
my $exception = exception {
my $method = Moose::Meta::TypeConstraint::Enum->new( values => [$arrayRef]);
};
like(
$exception,
qr/\QEnum values must be strings, not '$arrayRef'/,
"an array ref is given instead of a string");
#Enum values must be strings, not 'ARRAY(0x191d1b8)'
isa_ok(
$exception,
"Moose::Exception::EnumValuesMustBeString",
"an array ref is given instead of a string");
is(
$exception->value,
$arrayRef,
"an array ref is given instead of a string");
}
done_testing;
|