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
|
=pod
=encoding utf-8
=head1 PURPOSE
Tests for deep coercion.
=head1 SEE ALSO
L<https://rt.cpan.org/Ticket/Display.html?id=104154>.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2019-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 Type::Tiny;
use Test::More;
my $type_without = "Type::Tiny"->new(
name => "HasParam_without",
message => sub { "$_ ain't got a number" },
constraint_generator => sub { sub { 0 } }, # Reject everything
deep_explanation => sub { ["love to contradict"] },
);
my $type_with = "Type::Tiny"->new(
constraint => sub { 1 }, # Un-parameterized accepts al
name => "HasParam_with",
message => sub { "$_ ain't got a number" },
constraint_generator => sub { sub { 0 } }, # Reject everything
deep_explanation => sub { ["love to contradict"] },
);
my $type_parent = "Type::Tiny"->new(
parent => $type_without,
name => "HasParam_parent",
message => sub { "$_ ain't got a number" },
constraint_generator => sub { sub { 0 } }, # Reject everything
deep_explanation => sub { ["love to contradict"] },
);
my $s = 'a string';
my $param_with = $type_with->parameterize('an ignored parameter');
my $param_parent = $type_parent->parameterize('an ignored parameter');
my $param_without = $type_without->parameterize('an ignored parameter');
my $explain_with=join("\n ",@{$param_with->validate_explain($s,'$s')});
my $explain_parent=join("\n ",@{$param_parent->validate_explain($s,'$s')});
my $explain_without=join("\n ",@{$param_without->validate_explain($s,'$s')});
#diag "With a plain constraint:\n $explain_with\n";
#diag "With a parent constraint:\n $explain_parent\n";
#diag "Without a plain constraint:\n $explain_without\n";
$explain_with =~ s/(HasParam)_\w+/$1/g;
$explain_parent =~ s/(HasParam)_\w+/$1/g;
$explain_without =~ s/(HasParam)_\w+/$1/g;
ok $explain_with eq $explain_without;
ok $explain_parent eq $explain_without;
done_testing;
|