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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
=pod
=encoding utf-8
=head1 PURPOSE
Checks various undocumented Type::Tiny methods.
The fact that these are tested here should not be construed to mean tht
they are any any way a stable, supported part of the Type::Tiny API.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2014 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use strict;
use warnings;
use lib qw( ./lib ./t/lib ../inc ./inc );
use Test::More;
use Test::Fatal;
use Test::TypeTiny;
use Type::Tiny;
use Types::Standard -types;
is_deeply(
Int->inline_environment,
{},
'$type->inline_environment',
);
my $check = Int->_inline_check('$foo');
ok(
eval("my \$foo = 42; $check") && !eval("my \$foo = 4.2; $check"),
'$type->_inline_check',
);
ok(
Int->_compiled_type_constraint->("42") && !Int->_compiled_type_constraint->("4.2"),
'$type->_compiled_type_constraint',
);
like(
exception { Any->meta },
qr/^Not really a Moose::Meta::TypeConstraint/,
'$type->meta',
);
ok(
Int->compile_type_constraint->("42") && !Int->compile_type_constraint->("4.2"),
'$type->compile_type_constraint',
);
ok(
Int->_actually_compile_type_constraint->("42") && !Int->_actually_compile_type_constraint->("4.2"),
'$type->_actually_compile_type_constraint',
);
is(
Int->hand_optimized_type_constraint,
undef,
'$type->hand_optimized_type_constraint',
);
ok(
!Int->has_hand_optimized_type_constraint,
'$type->has_hand_optimized_type_constraint',
);
ok(
(ArrayRef[Int])->__is_parameterized && !Int->__is_parameterized,
'$type->__is_parameterized',
);
my $Int = Int->create_child_type;
$Int->_add_type_coercions(Num, q[int($_)]);
is(
$Int->coerce(42.1),
42,
'$type->_add_type_coercions',
);
is(
Int->_as_string,
'Types::Standard::Int',
'$type->_as_string',
);
is(
$Int->_compiled_type_coercion->(6.2),
6,
'$type->_compiled_type_coercion',
);
ok(
Int->_identity != $Int->_identity,
'$type->_identity',
);
my $union = Int->_unite(ArrayRef);
ok(
$union->equals( Int | ArrayRef ),
'$type->_unite',
);
done_testing;
|