HashRef doesn't have a coercion");
ok(HashRef->is_parameterizable, "HashRef is parameterizable");
isnt(HashRef->type_default, undef, "HashRef has a type_default");
is_deeply(HashRef->type_default->(),
t have a coercion");
ok(!$HashOfInts->is_parameterizable, "\$HashOfInts is not parameterizable");
isnt($HashOfInts->type_default, undef, "\$HashOfInts has a type_default");
is_deeply($HashOfInts->type
ged" );
};
do {
my $orig = { foo => 42.1 };
my $coerced = $HashOfRounded->coerce($orig);
isnt( refaddr($orig), refaddr($coerced), "coercion happened" );
is($coerced->{foo}, 42, "... and data
hat should pass their type constraint",
);
isnt(
exception { "Local::Class"->new(small => 100) },
undef,
"direct violation of type constraint",
);
isnt(
exception { "Local::Class"->new(small =>
on of parent type constraint",
);
isnt(
exception { "Local::Class"->new(small => "five point five") },
undef,
"violation of grandparent type constraint",
);
isnt(
exception { "Local::Class"->new
);
};
isnt($e, undef, "'big' attribute throws when it cannot coerce in constructor - $suffix");
$e = exception {
$o = "Local::Class"->new(
small => {},
big => [],
);
};
isnt($e, und
$e = exception { $o->big({}) };
isnt($e, undef, "'big' attribute throws when it cannot coerce in accessor - $suffix");
$e = exception { $o->small({}) };
isnt($e, undef, "'small' attribute throw
hat should pass their type constraint",
);
isnt(
exception { "Local::Class"->new(small => 100) },
undef,
"direct violation of type constraint",
);
isnt(
exception { "Local::Class"->new(small =>
on of parent type constraint",
);
isnt(
exception { "Local::Class"->new(small => "five point five") },
undef,
"violation of grandparent type constraint",
);
isnt(
exception { "Local::Class"->new
);
isnt(
exception { scalar(foo(4.2)) },
undef,
);
done_testing;
};
subtest "list context" => sub
{
is_deeply(
[ foo(4, 2) ],
[ 4, 2 ],
);
isnt(
except
),
4,
);
TODO: {
local $TODO = 'this seems to fail: error in Return::Type??';
isnt(
exception { scalar(bar(xxx => 1, 2)) },
undef,
);
}
done_testing;
};
subte
=> sub
{
is_deeply(
{ bar(xxx => 1, yyy => 2) },
{ xxx => 1, yyy => 2 },
);
isnt(
exception { [ bar(xxx => 1, 2) ] },
undef,
);
done_testing;
};
done_testing;
};
ayRef doesn't have a coercion");
ok(ArrayRef->is_parameterizable, "ArrayRef is parameterizable");
isnt(ArrayRef->type_default, undef, "ArrayRef has a type_default");
is_deeply(ArrayRef->type_default->
have a coercion");
ok(!$ArrayOfInts->is_parameterizable, "\$ArrayOfInts is not parameterizable");
isnt($ArrayOfInts->type_default, undef, "\$ArrayOfInts has a type_default");
is_deeply($ArrayOfInts->t
unchanged" );
};
do {
my $orig = [ 42.1 ];
my $coerced = $ArrayOfRounded->coerce($orig);
isnt( refaddr($orig), refaddr($coerced), "coercion happened" );
is($coerced->[0], 42, "... and data l
_coercion, "Map doesn't have a coercion");
ok(Map->is_parameterizable, "Map is parameterizable");
isnt(Map->type_default, undef, "Map has a type_default");
is_deeply(Map->type_default->(), {}, "Map ty
coercion");
ok(!$MapWithIntKeys->is_parameterizable, "\$MapWithIntKeys is not parameterizable");
isnt($MapWithIntKeys->type_default, undef, "\$MapWithIntKeys has a type_default");
is_deeply($MapWithI
};
do {
my $orig = { 3.1 => 4.2 };
my $coerced = $HashOfRounded->coerce($orig); # {3=>4}
isnt( refaddr($orig), refaddr($coerced), "coercion happened" );
is($coerced->{3}, 4, "... and data lo
);
is($foo->add(2), 42);
is($foo->num, 42);
isnt(
exception { $foo->num("Hello") },
undef,
);
isnt(
exception { $foo->add("Hello") },
undef,
);
isnt(
exception { 'Foo'->new(num => "Hello") },
test "tied scalar" => sub
{
tie my($int), Int;
is(
exception { $int = 42 },
undef,
);
isnt(
exception { $int = 4.2 },
undef,
);
is($int, 42);
done_testing;
};
subtest "tied arr
is(
exception {
$ints[0] = 1;
push @ints, 2;
unshift @ints, 0;
},
undef,
);
isnt(
exception { $ints[3] = 3.5 },
undef,
);
is_deeply(
\@ints,
[ 0..2 ],
);
done_tes
e my(%ints), Int;
is(
exception {
$ints{one} = 1;
$ints{two} = 2;
},
undef,
);
isnt(
exception { $ints{three} = 3.5 },
undef,
);
is_deeply(
\%ints,
{ one => 1, two => 2
ion, "Maybe doesn't have a coercion");
ok(Maybe->is_parameterizable, "Maybe is parameterizable");
isnt(Maybe->type_default, undef, "Maybe has a type_default");
is(Maybe->type_default->(), undef, "Mayb
e);
isnt($type->type_default, undef, "$type has a type_default, because Int does");
is($type->type_default->(), 0, "$type type_default is 0");
my $type2 = Maybe[ Types::Standard::Defined ];
isnt($ty
=> 0' );
}
{
my $check = compile( ArrayRef, { clone => 1 } );
my ( $got ) = $check->( $arr );
isnt( refaddr( $got ), refaddr( $arr ), 'compile with clone => 1' );
}
{
my $check = compile_named(
$check = compile_named( xxx => ArrayRef, { clone => 1 } );
my ( $got ) = $check->( xxx => $arr );
isnt( refaddr( $got->{xxx} ), refaddr( $arr ), 'compile_named with clone => 1' );
}
done_testing;
, "Slurpy doesn't have a coercion");
ok(Slurpy->is_parameterizable, "Slurpy is parameterizable");
isnt(Slurpy->type_default, undef, "Slurpy has a type_default");
is(Slurpy->type_default->(), undef, "S
, ucfirst("$label should fail $SlurpyCodeRef"));
}
else {
fail("expected '$expect'?!");
}
}
isnt(Slurpy->of( Types::Standard::HashRef )->type_default, undef, "Slurpy[HashRef] has a type_default"
n},
);
can_ok(main => "Any");
isnt(
exception { "Types::Standard"->import("kghffubbtfui") },
undef,
q {Attempt to export a function which does not exist},
);
isnt(
exception { "Types::Standard"
ional doesn't have a coercion");
ok(Optional->is_parameterizable, "Optional is parameterizable");
isnt(Optional->type_default, undef, "Optional has a type_default");
is(Optional->type_default->(), und
hould_pass(0, $type);
should_pass(1, $type);
should_fail(1.1, $type);
should_fail(undef, $type);
isnt($type->type_default, undef, "$type has a type_default");
is($type->type_default->(), 0, "$type ty
on, "Item doesn't have a coercion");
ok(!Item->is_parameterizable, "Item isn't parameterizable");
isnt(Item->type_default, undef, "Item has a type_default");
is(Item->type_default->(), undef, "Item ty
e doesn't have a coercion");
ok(CycleTuple->is_parameterizable, "CycleTuple is parameterizable");
isnt(CycleTuple->type_default, undef, "CycleTuple has a type_default");
is_deeply(CycleTuple->type_def
ion, "Tuple doesn't have a coercion");
ok(Tuple->is_parameterizable, "Tuple is parameterizable");
isnt(Tuple->type_default, undef, "Tuple has a type_default");
is_deeply(Tuple->type_default->(), [], "
e doesn't have a coercion");
ok(!CodeLike->is_parameterizable, "CodeLike isn't parameterizable");
isnt(CodeLike->type_default, undef, "CodeLike has a type_default");
is(scalar CodeLike->type_default->
ercion, "Dict doesn't have a coercion");
ok(Dict->is_parameterizable, "Dict is parameterizable");
isnt(Dict->type_default, undef, "Dict has a type_default");
is_deeply(Dict->type_default->(), {}, "Dic
"TypeTiny has a coercion");
ok(!TypeTiny->is_parameterizable, "TypeTiny isn't parameterizable");
isnt(TypeTiny->type_default, undef, "TypeTiny has a type_default");
is(TypeTiny->type_default->(), do