use
lib
qw( ./lib ./t/lib ../inc ./inc )
;
{
my
$x
;
sub
FooBarAndDoesQuux () {
$x
||= intersection(
FooBarAndDoesQuux
=> [FooBar, DoesQuux]) } }
isa_ok(
FooBarAndDoesQuux,
'Type::Tiny::Intersection'
,
'FooBarAndDoesQuux'
,
);
isa_ok(
FooBarAndDoesQuux->[0],
'Type::Tiny::Class'
,
'FooBarAndDoesQuux->[0]'
,
);
isa_ok(
FooBarAndDoesQuux->[1],
'Type::Tiny::Role'
,
'FooBarAndDoesQuux->[1]'
,
);
is(
FooBarAndDoesQuux.
""
,
'FooBar&DoesQuux'
,
'stringification good'
,
);
my
$something
=
bless
[] =>
do
{
sub
DOES {
return
1
if
$_
[1] eq
'Quux'
;
$_
[0]->isa(
$_
[0]);
}
__PACKAGE__;
};
should_fail(
"Foo::Bar"
->new, FooBarAndDoesQuux);
should_pass(
"Foo::Baz"
->new, FooBarAndDoesQuux);
should_fail(
$something
, FooBarAndDoesQuux);
my
$something_else
=
bless
[] =>
do
{
sub
DOES {
return
1
if
$_
[1] eq
'Else'
;
$_
[0]->isa(
$_
[0]);
}
__PACKAGE__;
};
should_fail(
$something_else
, FooBarAndDoesQuux);
should_fail(
"Foo::Bar"
, FooBarAndDoesQuux);
should_fail(
"Foo::Baz"
, FooBarAndDoesQuux);
my
$reftype_array
= Types::Standard::Ref[
"ARRAY"
];
{
my
$x
;
sub
NotherSect () {
$x
||= intersection(
NotherUnion
=> [FooBarAndDoesQuux,
$reftype_array
]) } }
is(
scalar
@{+NotherSect},
3,
"intersections don't get unnecessarily deep"
,
);
note NotherSect->inline_check(
'$X'
);
should_pass(
bless
([],
"Foo::Baz"
), NotherSect);
should_fail(
bless
({},
"Foo::Baz"
), NotherSect);
my
$SmallEven
= SmallInteger &
sub
{
$_
% 2 == 0 };
isa_ok(
$SmallEven
,
"Type::Tiny::Intersection"
);
ok(!
$SmallEven
->can_be_inlined,
"not ($SmallEven)->can_be_inlined"
);
should_pass(2,
$SmallEven
);
should_fail(20,
$SmallEven
);
should_fail(3,
$SmallEven
);
isnt(
exception {
push
@{
$SmallEven
},
'quux'
},
undef
,
'cannot push to overloaded arrayref'
);
done_testing;