added some code to improve the error message and added test for that
[gitmo/MooseX-Types-Structured.git] / t / 12-error.t
1 BEGIN {
2         use strict;
3         use warnings;
4         use Test::More tests=>4;
5 }
6
7 use Moose::Util::TypeConstraints;
8 use MooseX::Types::Structured qw(Dict Tuple);
9 use MooseX::Types::Moose qw(Int Str ArrayRef HashRef);
10
11 # Create some TCs from which errors will be generated
12 my $simple_tuple = subtype 'simple_tuple', as Tuple[Int,Str];
13 my $simple_dict = subtype 'simple_dict', as Dict[name=>Str,age=>Int];
14
15 # We probably need more stuff here...
16 ok $simple_tuple->check([1,'hello']), "simple_tuple validates: 1,'hello'";
17 ok !$simple_tuple->check(['hello',1]), "simple_tuple fails: 'hello',1";
18 like $simple_tuple->validate(['hello',1]), qr/"hello", 1/, 'got expected valiate message';
19 like $simple_dict->validate(['hello',1]), qr/"hello", 1/, 'got expected valiate message';
20