X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F02-autocoerce.t;h=b171715eda6d219de7714b1d731d00a0ce01a7d8;hb=58dbdba6c44235e491e03288cb9a4ad4223b2cdd;hp=02ab12b35e4fe25676657df6cf60f2eed9114f16;hpb=04443c7fdf4aadc37d87c495aa57f70852b05b83;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/t/02-autocoerce.t b/t/02-autocoerce.t index 02ab12b..b171715 100644 --- a/t/02-autocoerce.t +++ b/t/02-autocoerce.t @@ -3,23 +3,49 @@ 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/ - coerce - from - via + use Mouse; + use Mouse::Util::TypeConstraints qw< + coerce from via find_type_constraint register_type_constraint - / ]; + >; has 'id' => ( is => 'ro', @@ -30,7 +56,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] =~ /::([^:]+)$/; @@ -55,7 +81,7 @@ use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce; { package LaTeX::TikZ::TestY; - use Any::Moose; + use Mouse; has 'num' => ( is => 'ro', @@ -71,7 +97,7 @@ use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce; { package LaTeX::TikZ::TestZ; - use Any::Moose; + use Mouse; has 'x' => ( is => 'ro', @@ -88,8 +114,8 @@ use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce; { package LaTeX::TikZ::TestW; - use Any::Moose; - use Any::Moose 'Util::TypeConstraints'; + use Mouse; + use Mouse::Util::TypeConstraints; has 'x' => ( is => 'ro', @@ -98,7 +124,7 @@ use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce; ); coerce 'LaTeX::TikZ::TestX::Autocoerce' - => from __PACKAGE__ + => from +(__PACKAGE__) => via { $_->x }; __PACKAGE__->meta->make_immutable;