Regenerate test files
[gitmo/Mouse.git] / t-failing / 040_type_constraints / 019_coerced_parameterized_types.t
CommitLineData
b2b106d7 1#!/usr/bin/perl
fde8e43f 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
b2b106d7 5
6use strict;
7use warnings;
8
fde8e43f 9use Test::More;
10$TODO = q{Mouse is not yet completed};
b2b106d7 11use Test::Exception;
12
13BEGIN {
14 use_ok("Mouse::Util::TypeConstraints");
fde8e43f 15 use_ok('Mouse::Meta::TypeConstraint');
b2b106d7 16}
17
18BEGIN {
19 package MyList;
20 sub new {
21 my $class = shift;
22 bless { items => \@_ }, $class;
23 }
24
25 sub items {
26 my $self = shift;
27 return @{ $self->{items} };
28 }
29}
30
31subtype 'MyList' => as 'Object' => where { $_->isa('MyList') };
32
33lives_ok {
34 coerce 'ArrayRef'
35 => from 'MyList'
36 => via { [ $_->items ] }
37} '... created the coercion okay';
38
39my $mylist = Mouse::Util::TypeConstraints::find_or_parse_type_constraint('MyList[Int]');
40
41ok($mylist->check(MyList->new(10, 20, 30)), '... validated it correctly (pass)');
42ok(!$mylist->check(MyList->new(10, "two")), '... validated it correctly (fail)');
43ok(!$mylist->check([10]), '... validated it correctly (fail)');
44
45subtype 'EvenList' => as 'MyList' => where { $_->items % 2 == 0 };
46
47# XXX: get this to work *without* the declaration. I suspect it'll be a new
48# method in Mouse::Meta::TypeCoercion that will look at the parents of the
49# coerced type as well. but will that be too "action at a distance"-ey?
50lives_ok {
51 coerce 'ArrayRef'
52 => from 'EvenList'
53 => via { [ $_->items ] }
54} '... created the coercion okay';
55
56my $evenlist = Mouse::Util::TypeConstraints::find_or_parse_type_constraint('EvenList[Int]');
57
58ok(!$evenlist->check(MyList->new(10, 20, 30)), '... validated it correctly (fail)');
59ok($evenlist->check(MyList->new(10, 20, 30, 40)), '... validated it correctly (pass)');
60ok(!$evenlist->check(MyList->new(10, "two")), '... validated it correctly (fail)');
61ok(!$evenlist->check([10, 20]), '... validated it correctly (fail)');
62
fde8e43f 63done_testing;