test for bug with different coercions on same native type
[gitmo/Moo.git] / xt / moox-types-coercion.t
1 use strictures 1;
2 use Test::More;
3
4 {
5   package ClassWithTypes;
6   $INC{'ClassWithTypes.pm'} = __FILE__;
7   use Moo;
8   use MooX::Types::MooseLike::Base qw(ArrayRef);
9
10   has split_comma => (is => 'ro', isa => ArrayRef, coerce => sub { [ split /,/, $_[0] ] } );
11   has split_space => (is => 'ro', isa => ArrayRef, coerce => sub { [ split / /, $_[0] ] } );
12 }
13
14 my $o = ClassWithTypes->new(split_comma => 'a,b c,d', split_space => 'a,b c,d');
15 is_deeply $o->split_comma, ['a','b c','d'], 'coerce with prebuilt type works';
16 is_deeply $o->split_space, ['a,b','c,d'], ' ... and with different coercion on same type';
17
18 {
19   package MooseSubclassWithTypes;
20   use Moose;
21   extends 'ClassWithTypes';
22 }
23
24 my $o2 = MooseSubclassWithTypes->new(split_comma => 'a,b c,d', split_space => 'a,b c,d');
25 is_deeply $o2->split_comma, ['a','b c','d'], 'moose subclass has correct coercion';
26 is_deeply $o2->split_space, ['a,b','c,d'], ' ... and with different coercion on same type';
27
28 done_testing;