forked from moose/Moose
/
moose-meta-typecoercion.t
60 lines (46 loc) · 1.15 KB
/
moose-meta-typecoercion.t
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
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;