]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - t/02-autocoerce.t
Preserve __PACKAGE__ from stringification by =>
[perl/modules/LaTeX-TikZ.git] / t / 02-autocoerce.t
index 02ab12b35e4fe25676657df6cf60f2eed9114f16..39ab616c394f4dddbda2ec202982867cca192627 100644 (file)
@@ -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;