add failing test for coercing parameterized type
[gitmo/MooseX-Types.git] / t / 21_coerce_parameterized_types.t
CommitLineData
6cfbfdbc 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::Exception;
5
6use Test::More tests => 2;
7
8BEGIN {
9 package TypeLib;
10 use MooseX::Types -declare => [qw/MyType ArrayRefOfMyType/];
11 use MooseX::Types::Moose qw/ArrayRef Str/;
12
13 subtype MyType, as Str, where {
14 length == 1
15 };
16
17 coerce ArrayRef[MyType], from Str, via {
18 [split //]
19 };
20
21# same thing with an explicit subtype
22 subtype ArrayRefOfMyType, as ArrayRef[MyType];
23
24 coerce ArrayRefOfMyType, from Str, via {
25 [split //]
26 };
27}
28{
29 package AClass;
30 use Moose;
31 BEGIN { TypeLib->import(qw/MyType ArrayRefOfMyType/) };
32 use MooseX::Types::Moose 'ArrayRef';
33
34 has parameterized => (is => 'rw', isa => ArrayRef[MyType], coerce => 1);
35 has subtype => (is => 'rw', isa => ArrayRefOfMyType, coerce => 1);
36}
37
38my $instance = AClass->new;
39
40lives_ok { $instance->parameterized('foo') }
41 'coercion applied to parameterized type';
42
43lives_ok { $instance->subtype('foo') } 'coercion applied to subtype';