File: jv-allof-and-not.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 (31 lines) | stat: -rw-r--r-- 952 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
22
23
24
25
26
27
28
29
30
31
use lib '.';
use t::Helper;

my $missing = E '/required', '/allOf/0 Missing property.';
my $schema  = {type => 'object', allOf => [{required => ['required']}]};
my @tests   = (
  [{foo => 1, required  => 2}, $schema],
  [{foo => 2, forbidden => 3}, $schema, $missing],
  [{foo => 3, forbidden => 3, required => 2}, $schema],
  [{foo => 4}, $schema, $missing]
);

subtest 'property "required" must be present' => sub {
  validate_ok @$_ for @tests;
};

subtest 'Property "forbidden" must not be present' => sub {
  $schema->{not} = {required => ['forbidden']};
  splice @{$tests[1]}, 2, 0, E '/', 'Should not match.';
  $tests[2][2] = E '/', 'Should not match.';
  validate_ok @$_ for @tests;
};

subtest 'Move "not" constraint to "allOf"' => sub {
  push @{$schema->{allOf}}, {not => delete $schema->{not}};
  $tests[1][2] = $tests[2][2] = E '/', '/allOf/1 Should not match.';
  $tests[1][3] = $missing;
  validate_ok @$_ for @tests;
};

done_testing;