use
lib
qw( ./lib ./t/lib ../inc ./inc )
;
{
has
small
=> (
is
=>
"ro"
,
isa
=> SmallInteger);
has
big
=> (
is
=>
"ro"
,
isa
=> BigInteger);
}
is(
exception {
"Local::Class"
->new(
small
=> 9,
big
=> 12) },
undef
,
"some values that should pass their type constraint"
,
);
isnt(
exception {
"Local::Class"
->new(
small
=> 100) },
undef
,
"direct violation of type constraint"
,
);
isnt(
exception {
"Local::Class"
->new(
small
=> 5.5) },
undef
,
"violation of parent type constraint"
,
);
isnt(
exception {
"Local::Class"
->new(
small
=>
"five point five"
) },
undef
,
"violation of grandparent type constraint"
,
);
isnt(
exception {
"Local::Class"
->new(
small
=> []) },
undef
,
"violation of great-grandparent type constraint"
,
);
ok(
Mouse::Util::is_a_type_constraint(BiggerLib::SmallInteger),
"Mouse::Util::is_a_type_constraint accepts Type::Tiny type constraints"
,
);
note
"Coercion..."
;
{
subtype
'MyInt'
, as
'Int'
;
coerce
'MyInt'
, from
'ArrayRef'
, via {
scalar
(
@$_
) };
my
$type
= Types::TypeTiny::to_TypeTiny(find_type_constraint(
'MyInt'
));
::ok(
$type
->has_coercion,
'types converted from Mouse retain coercions'
);
::is(
$type
->coerce([
qw/a b c/
]), 3,
'... which work'
);
}
done_testing;