File: 02-api.t

package info (click to toggle)
libtype-tiny-perl 2.002001-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,948 kB
  • sloc: perl: 14,610; makefile: 2; sh: 1
file content (157 lines) | stat: -rw-r--r-- 2,819 bytes parent folder | download | duplicates (2)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
=pod

=encoding utf-8

=head1 PURPOSE

Test that Type::Tiny and Type::Coercion provide a Moose/Mouse-compatible API.

=head1 AUTHOR

Toby Inkster E<lt>tobyink@cpan.orgE<gt>.

=head1 COPYRIGHT AND LICENCE

This software is copyright (c) 2013-2014, 2017-2023 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 Test::More;

my $HAVE_MOOSE = eval {
	require Moose;
	Moose->VERSION('2.000');
	1; # return true
};

my @MOOSE_WANTS = qw(
	_actually_compile_type_constraint
	_collect_all_parents
	_compile_subtype
	_compile_type
	_compiled_type_constraint
	_default_message
	_has_compiled_type_constraint
	_inline_check
	_new
	_package_defined_in
	_set_constraint
	assert_coerce
	assert_valid
	can_be_inlined
	check
	coerce
	coercion
	compile_type_constraint
	constraint
	create_child_type
	equals
	get_message
	has_coercion
	has_message
	has_parent
	inline_environment
	inlined
	is_a_type_of
	is_subtype_of
	message
	meta
	name
	new
	parent
	parents
	validate
);

my $HAVE_MOUSE = eval { require Mouse };

my @MOUSE_WANTS = qw(
	__is_parameterized
	_add_type_coercions
	_as_string
	_compiled_type_coercion
	_compiled_type_constraint
	_identity
	_unite
	assert_valid
	check
	coerce
	compile_type_constraint
	create_child_type
	get_message
	has_coercion
	is_a_type_of
	message
	name
	new
	parameterize
	parent
	type_parameter
);

require Type::Tiny;

my $type = "Type::Tiny"->new(name => "TestType");

if ( $HAVE_MOOSE ) {
	no warnings 'once';
	*Moose::Meta::TypeConstraint::bleh_this_does_not_exist = sub { 42 };
	push @MOOSE_WANTS, 'bleh_this_does_not_exist';
}

for (@MOOSE_WANTS)
{
	SKIP: {
		skip "Moose::Meta::TypeConstraint PRIVATE API: '$_'", 1 if /^_/ && !$HAVE_MOOSE;
		ok($type->can($_), "Moose::Meta::TypeConstraint API: $type->can('$_')");
	}
}

if ( $HAVE_MOOSE ) {
	is( $type->can('bleh_this_does_not_exist')->( $type ), 42 );
	is( $type->bleh_this_does_not_exist(), 42 );
}

for (@MOUSE_WANTS)
{
	SKIP: {
		skip "Mouse::Meta::TypeConstraint PRIVATE API: '$_'", 1 if /^_/ && !$HAVE_MOUSE;
		ok($type->can($_), "Mouse::Meta::TypeConstraint API: $type->can('$_')");
	}
}

my @MOOSE_WANTS_COERCE = qw(
	_compiled_type_coercion
	_new
	add_type_coercions
	coerce
	compile_type_coercion
	has_coercion_for_type
	meta
	new
	type_coercion_map
	type_constraint
);

require Type::Coercion;

my $coerce = "Type::Coercion"->new(name => "TestCoercion");

for (@MOOSE_WANTS_COERCE)
{
	SKIP: {
		skip "Moose::Meta::TypeCoercion PRIVATE API: '$_'", 1 if /^_/ && !$HAVE_MOOSE;
		ok($coerce->can($_), "Moose::Meta::TypeCoercion API: $coerce->can('$_')");
	}
}

BAIL_OUT("Further tests rely on the Type::Tiny and Type::Coercion APIs.")
	unless "Test::Builder"->new->is_passing;

done_testing;