blob: a2abf9323d4f4d1873ebd7cbd01b4994d0449722 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Requires 'JSON';
use Moose::Util::TypeConstraints 'find_type_constraint';
use MooseX::Validation::Doctypes;
doctype 'Person' => {
id => 'Str',
name => 'Str',
title => 'Str',
};
my $JSON = JSON->new->utf8->convert_blessed;
{
my $person = find_type_constraint('Person');
my $errors = $person->validate({ foo => "bar" });
is_deeply(
$JSON->decode($JSON->encode($errors)),
{
errors => {
id => "invalid value undef for 'id'",
name => "invalid value undef for 'name'",
title => "invalid value undef for 'title'",
},
extra_data => {
foo => "bar",
},
},
"error objects can be encoded as json"
);
}
done_testing;
|