test for bug with different coercions on same native type
Graham Knop [Sat, 12 Jan 2013 21:29:12 +0000 (21:29 +0000)]
xt/moox-types-coercion.t [new file with mode: 0644]

diff --git a/xt/moox-types-coercion.t b/xt/moox-types-coercion.t
new file mode 100644 (file)
index 0000000..071a595
--- /dev/null
@@ -0,0 +1,28 @@
+use strictures 1;
+use Test::More;
+
+{
+  package ClassWithTypes;
+  $INC{'ClassWithTypes.pm'} = __FILE__;
+  use Moo;
+  use MooX::Types::MooseLike::Base qw(ArrayRef);
+
+  has split_comma => (is => 'ro', isa => ArrayRef, coerce => sub { [ split /,/, $_[0] ] } );
+  has split_space => (is => 'ro', isa => ArrayRef, coerce => sub { [ split / /, $_[0] ] } );
+}
+
+my $o = ClassWithTypes->new(split_comma => 'a,b c,d', split_space => 'a,b c,d');
+is_deeply $o->split_comma, ['a','b c','d'], 'coerce with prebuilt type works';
+is_deeply $o->split_space, ['a,b','c,d'], ' ... and with different coercion on same type';
+
+{
+  package MooseSubclassWithTypes;
+  use Moose;
+  extends 'ClassWithTypes';
+}
+
+my $o2 = MooseSubclassWithTypes->new(split_comma => 'a,b c,d', split_space => 'a,b c,d');
+is_deeply $o2->split_comma, ['a','b c','d'], 'moose subclass has correct coercion';
+is_deeply $o2->split_space, ['a,b','c,d'], ' ... and with different coercion on same type';
+
+done_testing;