From: Graham Knop Date: Sat, 12 Jan 2013 21:29:12 +0000 (+0000) Subject: test for bug with different coercions on same native type X-Git-Tag: v1.001000~22 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d885d85e8e545b3ef9ac7267aadcfb128e460158;p=gitmo%2FMoo.git test for bug with different coercions on same native type --- diff --git a/xt/moox-types-coercion.t b/xt/moox-types-coercion.t new file mode 100644 index 0000000..071a595 --- /dev/null +++ b/xt/moox-types-coercion.t @@ -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;