X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F02-autocoerce.t;h=39ab616c394f4dddbda2ec202982867cca192627;hb=5320bfbf612fadc6acc5363436814b185a220909;hp=02ab12b35e4fe25676657df6cf60f2eed9114f16;hpb=04443c7fdf4aadc37d87c495aa57f70852b05b83;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/t/02-autocoerce.t b/t/02-autocoerce.t index 02ab12b..39ab616 100644 --- a/t/02-autocoerce.t +++ b/t/02-autocoerce.t @@ -3,23 +3,51 @@ use strict; use warnings; -use Test::More tests => 7 * 4; +use Test::More tests => 3 + 7 * 4; use lib 't/lib'; use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce; +{ + my $tc = eval { + LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new( + target => undef, + ); + }; + like $@, qr/^No meta object for undefined target/, 'Undef target'; +} + +{ + my $target = 'LaTeX::TikZ::A::Class::Likely::Not::To::Exist'; + my $tc = eval { + LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new( + target => $target, + ); + }; + like $@, qr/^No meta object for target \Q$target\E/, 'Nonexistent target'; +} + +{ + my $tc = eval { + LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new( + target => 'LaTeX::TikZ::Meta::TypeConstraint::Autocoerce', + ); + }; + is $@, '', 'Valid target'; +} + { package LaTeX::TikZ::TestX; use Any::Moose; - use Any::Moose 'Util::TypeConstraints' => [ qw/ + use Any::Moose 'Util::TypeConstraints' => [ qw< coerce from via find_type_constraint register_type_constraint - / ]; + > ]; has 'id' => ( is => 'ro', @@ -30,7 +58,7 @@ use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce; register_type_constraint( LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new( name => 'LaTeX::TikZ::TestX::Autocoerce', - parent => find_type_constraint(__PACKAGE__), + target => find_type_constraint(__PACKAGE__), mapper => sub { shift; my ($last) = $_[0] =~ /::([^:]+)$/; @@ -80,7 +108,7 @@ use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce; coerce => 1, ); - __PACKAGE__->meta->make_immutable; + __PACKAGE__->meta->make_immutable if any_moose() ne 'Moose'; sub main::Z () { __PACKAGE__ } } @@ -98,7 +126,7 @@ use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce; ); coerce 'LaTeX::TikZ::TestX::Autocoerce' - => from __PACKAGE__ + => from +(__PACKAGE__) => via { $_->x }; __PACKAGE__->meta->make_immutable;