File: to-json.t

package info (click to toggle)
libjson-validator-perl 3.06%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 616 kB
  • sloc: perl: 1,308; makefile: 6
file content (57 lines) | stat: -rw-r--r-- 1,298 bytes parent folder | download
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use Mojo::Base -strict;
use Test::More;
use JSON::Validator 'validate_json';

my @errors
  = validate_json(
  bless({path => '', message => 'yikes'}, 'JSON::Validator::Error'),
  'data://main/error_object.json');
ok !@errors, 'TO_JSON on objects' or diag join ', ', @errors;

my $input = {
  errors => [
    JSON::Validator::Error->new('/', 'foo'),
    JSON::Validator::Error->new('/', 'bar')
  ],
  valid => Mojo::JSON->false,
};
@errors = validate_json $input, 'data://main/error_array.json';
ok !@errors, 'TO_JSON on objects inside arrays' or diag join ', ', @errors;
is_deeply $input,
  {
  errors => [
    JSON::Validator::Error->new('/', 'foo'),
    JSON::Validator::Error->new('/', 'bar')
  ],
  valid => Mojo::JSON->false,
  },
  'input objects are not changed';

done_testing;
__DATA__
@@ error_object.json
{
  "type": "object",
  "properties": { "message": { "type": "string" } },
  "required": ["message"]
}

@@ error_array.json
{
  "type": "object",
  "required": [ "errors" ],
  "properties": {
    "valid": { "type": "boolean" },
    "errors": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [ "message" ],
        "properaties": {
          "message": { "type": "string" },
          "path": { "type": "string" }
        }
      }
    }
  }
}