File: predictable-errors.t

package info (click to toggle)
libjson-validator-perl 5.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,160 kB
  • sloc: perl: 3,015; makefile: 14
file content (21 lines) | stat: -rw-r--r-- 832 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use Mojo::Base -strict;

use JSON::Validator;
use Test::More;

my $jv          = JSON::Validator->new;
my $broken_data = {ant => [qw(fire soldier termite)], bat => 'cricket', cat => 'lion', dog => 'good boy'};
my $num_errors;

# The schema below gets turned into a perl hash inside JSON::Validator,
# so looping around like this will execute the test with all kinds of
# different internal ordering
for (1 .. 20) {
  my $schema_text
    = '{"type":"object","properties":{"ant":{"type":"string"},"bat":{"type":"array"},"cat":{"type":"object"},"dog":{"type":"integer"}}}';
  $jv->schema($schema_text);
  is_deeply [map { $_->path } $jv->validate($broken_data)], [qw(/ant /bat /cat /dog)], 'got errors in expected order';
  is scalar $jv->validate($broken_data), 4, 'in scalar context got the right number of errors';
}

done_testing;