Corvus/Collecting.pm

filter: Statementstmt 41.0% 184 / 448 Branchbran 24.8% 84 / 338 Conditioncond 11.6% 36 / 309 MC/DCmcdc 2.8% 5 / 178 Subroutinesub 57.1% 28 / 49 Podpod 0.0% 0 / 2 totaltotal 25.4% 337 / 1324 CC 290 SCAR 61.5
CC
290
Cov
28%
_eval_in_place
1579.5
_eval_string
930.0
_eval_array
524.2
CRAP 467.6
« Corvus/Regex/Vm.pm ↑ Summary Corvus/Regex/Linear.pm »
1 package JSON::Schema::Corvus::Collecting;
2  
3 # Collecting-mode evaluation: evaluates an instance exhaustively against the compiled node graph and reports every
4 # keyword to a results collector, reproducing the C# evaluator's Eval<CollectingMode> (keyword order, evaluation,
5 # schema and instance paths, messages, which subschema results are committed or discarded). A port of the Python
6 # package's collecting.py.
7 #
8 # Validation without a collector never comes here: it runs the generated code. Results collection is exhaustive by
9 # nature (every keyword is evaluated and reported), so it interprets the graph rather than generating a second program.
10  
11 4 ▶use 5.026;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use B ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use JSON::Schema::Corvus::Dialect qw(DRAFT6);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use JSON::Schema::Corvus::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use JSON::Schema::Corvus::Formats ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use JSON::Schema::Corvus::Json ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use JSON::Schema::Corvus::Node qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use JSON::Schema::Corvus::Pattern ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use JSON::Schema::Corvus::Runtime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # Messages (Corvus.Text.Json Strings.resx).
24 4 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 EVALUATED_SUBSCHEMA => 'The value was expected to match the subschema.',
26 MATCHED_ALL => 'The value matched all subschema.',
27 DID_NOT_MATCH_ALL => 'The value did not match all subschema.',
28 MATCHED_AT_LEAST_ONE => 'The value matched at least one subschema.',
29 DID_NOT_MATCH_AT_LEAST_ONE => 'The value did not match at least one subschema.',
30 MATCHED_NO_SCHEMA => 'The instance matched no schema.',
31 MATCHED_EXACTLY_ONE => 'The value matched exactly one subschema.',
32 MATCHED_MORE_THAN_ONE => 'The instance matched more than one schema.',
33 MATCHED_NOT => 'The value matched the subschema in a not composition, which means the evaluation was not a match.',
34 DID_NOT_MATCH_NOT =>
35 'The value did not match the subschema in a not composition, which means the evaluation was a match.',
36 MATCHED_IF_FOR_THEN => 'The value matched the subschema in a binary or ternay if, which means the evaluation will go '
37 . 'on to match the then subschema.',
38 MATCHED_IF_FOR_ELSE => 'The value did not match the subschema in a ternary if, which means the evaluation will go on '
39 . 'to match the else subschema.',
40 MATCHED_THEN => 'The value matched the then subschema corresponding to a binary or ternary if.',
41 DID_NOT_MATCH_THEN => 'The value did not match the then subschema corresponding to a binary or ternary if.',
42 MATCHED_ELSE => 'The value matched the else subschema corresponding to a ternary if.',
43 DID_NOT_MATCH_ELSE => 'The value did not match the else subschema corresponding to a ternary if.',
44 UNIQUE_ITEMS => 'The array was expected to contain unique items.',
45 PROPERTY_NAME_FAILED => 'The property name did not match the schema.',
46 4 };
47  
48 4 our %STRING_FORMAT_MESSAGES = (
49 'date' => 'Expected an ISO8601 Date string.',
50 'date-time' => 'Expected an ISO8601 Offset DateTime string.',
51 'time' => 'Expected an ISO8601 Offset Time string.',
52 'duration' => 'Expected an ISO8601 Duration string.',
53 'email' => 'Expected an RFC5321 Section-4.1.2 Email string.',
54 'idn-email' => 'Expected an RFC6531 IDN Email string.',
55 'hostname' => 'Expected an RFC1035 hostname.',
56 'idn-hostname' => 'Expected an RFC5890 Section-2.3.2.3 IDN hostname.',
57 'ipv4' => 'Expected an RFC2673 IP V4 address.',
58 'ipv6' => 'Expected an RFC2373 IP V6 address.',
59 'uri' => 'Expected an absolute URI.',
60 'uri-reference' => 'Expected a URI reference.',
61 'iri' => 'Expected an absolute IRI.',
62 'iri-reference' => 'Expected an IRI reference.',
63 'uuid' => 'Expected an RFC4122 UUID.',
64 'uri-template' => 'Expected an RFC6570 URI Template.',
65 'json-pointer' => 'Expected an RFC6901 JSON Pointer.',
66 'relative-json-pointer' =>
67 'Expected a Relative JSON Pointer. (https://json-schema.org/draft/2020-12/relative-json-pointer).',
68 'regex' => 'Expected a regular expression specification.',
69 );
70  
71 4 my $Json = 'JSON::Schema::Corvus::Json';
72 4 *_is_number = \&JSON::Schema::Corvus::Json::is_number;
73 4 *_is_string = \&JSON::Schema::Corvus::Json::is_string;
74 4 *_equal = \&JSON::Schema::Corvus::Runtime::equal;
75  
76 # " 'v'", or nothing for an empty value (JsonSchemaEvaluation.AppendSingleQuotedValue).
77 0 ▶sub _q { length $_[0] ? " '$_[0]'" : '' }
Subroutine _q: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
length $_[0] ? : 0 0 0
78  
79 # A number as the Rust evaluator writes it (serde_json): an integer exactly, and a floating point number in its
80 # shortest form that reads back, with .0 kept on whole values and no leading zeros in the exponent (2.0, 1e+21,
81 # 1.5e-7).
82 0 ▶sub number_text {
Subroutine number_text: not called CC=11 SCAR=48.8
Pod undocumented
83 0 my ($n) = @_;
84 0 ▶ return "$n" if ref $n;
Branch: 1 branch
BranchTrueFalseTotal
if ref $n 0 0 0
85 0 my $copy = $n;
86 0 ▶ return "$copy" if JSON::Schema::Corvus::Json::is_integer($n) && B::svref_2object(\$n)->FLAGS & B::SVf_IOK;
Branch: 1 branch
BranchTrueFalseTotal
if JSON::Schema::Corvus::Json::is_integer($n) and B::svref_2object(\$n)->FLAGS & 256 0 0 0
Condition0%0/3
JSON::Schema::Corvus::Json::is_integer($n) and B::svref_2object(\$n)->FLAGS & 256
!ll&&!rl&&r
000
MC/DC0%0/2
JSON::Schema::Corvus::Json::is_integer($n) and B::svref_2object(\$n)->FLAGS & 256
JSON::Schema::Corvus::Json::is_integer($n) B::svref_2object(\$n)->FLAGS & 256
Truth table0%0/3
A and B
A= JSON::Schema::Corvus::Json::is_integer($n)B= B::svref_2object(\$n)->FLAGS & 256
ABresult
0X0
100
111
87 0 ▶ return 'NaN' if $n != $n;
Branch: 1 branch
BranchTrueFalseTotal
if $n != $n 0 0 0
88 0 ▶ return $n > 0 ? 'Infinity' : '-Infinity' if $n == $n * 2 && $n != 0;
Branch: 2 branches
BranchTrueFalseTotal
if $n == $n * 2 and $n != 0 0 0 0
$n > 0 ? : 0 0 0
Condition0%0/3
$n == $n * 2 and $n != 0
!ll&&!rl&&r
000
MC/DC0%0/2
$n == $n * 2 and $n != 0
$n == $n * 2 $n != 0
Truth table0%0/3
A and B
A= $n == $n * 2B= $n != 0
ABresult
0X0
100
111
89 0 my $text = JSON::Schema::Corvus::Json::number_text($n);
90 0 ▶ if ($text =~ /\A(-?[0-9.]+)e([+-]?)0*([0-9]+)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /\A(-?[0-9.]+)e([+-]?)0*([0-9]+)\z/u) 0 0 0
91 0 (my $mantissa = $1) =~ s/\.0\z//;
92 0 ▶ return "${mantissa}e" . ($2 eq '-' ? '-' : '+') . $3;
Branch: 1 branch
BranchTrueFalseTotal
$2 eq '-' ? : 0 0 0
93 }
94 0 ▶ $text .= '.0' unless $text =~ /[.e]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /[.e]/u 0 0 0
95 0 return $text;
96 }
97  
98 4 my @TYPE_ORDER = ([T_ARRAY, 'array'], [T_OBJECT, 'object'], [T_NULL, 'null'], [T_BOOLEAN, 'boolean'],
99 [T_NUMBER, 'number'], [T_INTEGER, 'integer'], [T_STRING, 'string']);
100  
101 10 ▶sub _type_message {
Subroutine _type_message: called CC=4 SCAR=15.0
102 10 my ($mask) = @_;
103 10 ▶ my @names = map { $mask & $_->[0] ? $_->[1] : () } @TYPE_ORDER;
Branch: 1 branch
BranchTrueFalseTotal
$mask & $_->[0] ? : 10 60 70
104 10 ▶ return undef unless @names;
Branch: 1 branch
BranchTrueFalseTotal
unless @names 0 10 10
105 10 ▶ return "The value was expected to be of type '$names[0]'" if @names == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @names == 1 10 0 10
106 0 return q{The value was expected to be of type '[} . join(', ', map { qq{"$_"} } @names) . q{]'};
107 }
108  
109 10 ▶sub _matches_type {
Subroutine _matches_type: called CC=14 SCAR=30.3
110 10 my ($mask, $x, $dialect) = @_;
111 10 my $type = JSON::Schema::Corvus::Json::type_of($x);
112 10 ▶ return ($mask & T_STRING) ? 1 : 0 if $type eq 'string';
Branch: 2 branches
BranchTrueFalseTotal
if $type eq "string" 2 8 10
$mask & 32 ? : 0 2 2
113 8 ▶ if ($type eq 'number') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "number") 4 4 8
114 4 ▶ return 1 if $mask & T_NUMBER;
Branch: 1 branch
BranchTrueFalseTotal
if $mask & 16 0 4 4
115 4 ▶ return 0 unless $mask & T_INTEGER;
Branch: 1 branch
BranchTrueFalseTotal
unless $mask & 64 0 4 4
116 4 ▶ return JSON::Schema::Corvus::Json::is_integer($x) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
JSON::Schema::Corvus::Json::is_integer($x) ? : 4 0 4
117 }
118 4 ▶ return ($mask & T_BOOLEAN) ? 1 : 0 if $type eq 'boolean';
Branch: 2 branches
BranchTrueFalseTotal
if $type eq "boolean" 0 4 4
$mask & 2 ? : 0 0 0
119 4 ▶ return ($mask & T_NULL) ? 1 : 0 if $type eq 'null';
Branch: 2 branches
BranchTrueFalseTotal
if $type eq "null" 0 4 4
$mask & 1 ? : 0 0 0
120 4 ▶ return ($mask & T_ARRAY) ? 1 : 0 if $type eq 'array';
Branch: 2 branches
BranchTrueFalseTotal
if $type eq "array" 1 3 4
$mask & 8 ? : 1 0 1
121 3 ▶ return ($mask & T_OBJECT) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$mask & 4 ? : 3 0 3
122 }
123  
124 0 ▶sub _const_message {
Subroutine _const_message: not called CC=6 SCAR=37.4
125 0 my ($value) = @_;
126 0 my $type = JSON::Schema::Corvus::Json::type_of($value);
127 0 ▶ return 'Expected the value to be the string' . _q($value) if $type eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "string" 0 0 0
128 0 ▶ return "Expected the value to be '" . ($value ? 'true' : 'false') . "'" if $type eq 'boolean';
Branch: 2 branches
BranchTrueFalseTotal
if $type eq "boolean" 0 0 0
$value ? : 0 0 0
129 0 ▶ return 'The value was expected to be equal to' . _q(number_text($value)) if $type eq 'number';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "number" 0 0 0
130 0 ▶ return "Expected the value to be 'null'" if $type eq 'null';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "null" 0 0 0
131 0 return undef;
132 }
133  
134 1 ▶sub _json_text { JSON::Schema::Corvus::Json::encode($_[0]) }
Subroutine _json_text: called CC=1 SCAR=0.0
135  
136 9 ▶sub _segment { JSON::Schema::Corvus::Uri::escape_pointer_token($_[0]) }
Subroutine _segment: called CC=1 SCAR=0.0
137  
138 # Evaluates an instance (a JSON value, in ordered mode for the order of results) against the program's entry,
139 # reporting to the collector; returns whether it is valid.
140 5 ▶sub evaluate_with_collector {
Subroutine evaluate_with_collector: called CC=1 SCAR=0.0
Pod undocumented
141 5 my ($program, $instance, $collector) = @_;
142 5 my $self = bless { program => $program, c => $collector, nodes => $program->{nodes}, scope => [], depth => 0 },
143 __PACKAGE__;
144 # A root that is nothing but a $ref reports against its target, with no $ref in the evaluation path.
145 5 my ($root) = $self->_resolve($program->{root});
146 5 $collector->begin_child_context(undef, $self->{nodes}[$root]{pointer}, undef);
147 5 my $ok = $self->_eval_node($root, $instance, undef);
148 5 $collector->commit_child_context(0, $ok, EVALUATED_SUBSCHEMA);
149 5 return $ok;
150 }
151  
152 # The single reference of a pure-$ref node (SchemaCompiler.IsPureRef), or -1.
153 12 ▶sub _pure_ref_target {
Subroutine _pure_ref_target: called CC=21 SCAR=56.8
154 12 my ($self, $n) = @_;
155 12 ▶ my $refs = ($n->{ref} >= 0 ? 1 : 0) + ($n->{static_dynamic_ref} >= 0 ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
$n->{'ref'} >= 0 ? : 0 12 12
$n->{'static_dynamic_ref'} >= 0 ? : 0 12 12
156 12 ▶ return -1 if $refs != 1 || $n->{always_true} || $n->{always_false} || defined $n->{annotations};
Branch: 1 branch
BranchTrueFalseTotal
if $refs != 1 or $n->{"always_true"} or $n->{"always_false"} or defined $n->{"annotations"} 12 0 12
Condition33%3/9
$refs != 1 or $n->{"always_true"} or $n->{"always_false"} or defined $n->{"annotations"}
l!l&&r!l&&!r
1200
$refs != 1 or $n->{"always_true"} or $n->{"always_false"}
l!l&&r!l&&!r
1200
$refs != 1 or $n->{"always_true"}
l!l&&r!l&&!r
1200
MC/DC0%0/4
$refs != 1 or $n->{"always_true"} or $n->{"always_false"} or defined $n->{"annotations"}
$refs != 1 $n->{"always_true"} $n->{"always_false"} defined $n->{"annotations"}
Truth table20%1/5
A or B or C or D
A= $refs != 1B= $n->{"always_true"}C= $n->{"always_false"}D= defined $n->{"annotations"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
157 return -1 if $n->{has_type} || $n->{has_const} || defined $n->{enum_values} || $n->has_number_keywords
158 || $n->has_string_keywords || $n->has_object_keywords || $n->has_array_keywords || defined $n->{dynamic_ref}
159 0 ▶ || defined $n->{all_of} || defined $n->{any_of} || defined $n->{one_of} || $n->{not_} >= 0 || $n->{if_} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_number_keywords or $n->has_string_keywords or $n->has_object_keywords or $n->has_array_keywords or defined $n->{"dynamic_ref"} or defined $n->{"all_of"} or defined $n->{"any_of"} or defined $n->{"one_of"} or $n->{"not_"} >= 0 or $n->{"if_"} >= 0 0 0 0
Condition0%0/36
$n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_number_keywords or $n->has_string_keywords or $n->has_object_keywords or $n->has_array_keywords or defined $n->{"dynamic_ref"} or defined $n->{"all_of"} or defined $n->{"any_of"} or defined $n->{"one_of"} or $n->{"not_"} >= 0 or $n->{"if_"} >= 0
l!l&&r!l&&!r
000
$n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_number_keywords or $n->has_string_keywords or $n->has_object_keywords or $n->has_array_keywords or defined $n->{"dynamic_ref"} or defined $n->{"all_of"} or defined $n->{"any_of"} or defined $n->{"one_of"} or $n->{"not_"} >= 0
l!l&&r!l&&!r
000
$n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_number_keywords or $n->has_string_keywords or $n->has_object_keywords or $n->has_array_keywords or defined $n->{"dynamic_ref"} or defined $n->{"all_of"} or defined $n->{"any_of"} or defined $n->{"one_of"}
l!l&&r!l&&!r
000
$n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_number_keywords or $n->has_string_keywords or $n->has_object_keywords or $n->has_array_keywords or defined $n->{"dynamic_ref"} or defined $n->{"all_of"} or defined $n->{"any_of"}
l!l&&r!l&&!r
000
$n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_number_keywords or $n->has_string_keywords or $n->has_object_keywords or $n->has_array_keywords or defined $n->{"dynamic_ref"} or defined $n->{"all_of"}
l!l&&r!l&&!r
000
$n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_number_keywords or $n->has_string_keywords or $n->has_object_keywords or $n->has_array_keywords or defined $n->{"dynamic_ref"}
l!l&&r!l&&!r
000
$n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_number_keywords or $n->has_string_keywords or $n->has_object_keywords or $n->has_array_keywords
l!l&&r!l&&!r
000
$n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_number_keywords or $n->has_string_keywords or $n->has_object_keywords
l!l&&r!l&&!r
000
$n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_number_keywords or $n->has_string_keywords
l!l&&r!l&&!r
000
$n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_number_keywords
l!l&&r!l&&!r
000
$n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"}
l!l&&r!l&&!r
000
$n->{"has_type"} or $n->{"has_const"}
l!l&&r!l&&!r
000
MC/DC0%0/13
$n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_number_keywords or $n->has_string_keywords or $n->has_object_keywords or $n->has_array_keywords or defined $n->{"dynamic_ref"} or defined $n->{"all_of"} or defined $n->{"any_of"} or defined $n->{"one_of"} or $n->{"not_"} >= 0 or $n->{"if_"} >= 0
$n->{"has_type"} $n->{"has_const"} defined $n->{"enum_values"} $n->has_number_keywords $n->has_string_keywords $n->has_object_keywords $n->has_array_keywords defined $n->{"dynamic_ref"} defined $n->{"all_of"} defined $n->{"any_of"} defined $n->{"one_of"} $n->{"not_"} >= 0 $n->{"if_"} >= 0
Truth table0%0/14
A or B or C or D or E or F or G or H or I or J or K or L or M
A= $n->{"has_type"}B= $n->{"has_const"}C= defined $n->{"enum_values"}D= $n->has_number_keywordsE= $n->has_string_keywordsF= $n->has_object_keywordsG= $n->has_array_keywordsH= defined $n->{"dynamic_ref"}I= defined $n->{"all_of"}J= defined $n->{"any_of"}K= defined $n->{"one_of"}L= $n->{"not_"} >= 0M= $n->{"if_"} >= 0
ABCDEFGHIJKLMresult
1XXXXXXXXXXXX1
01XXXXXXXXXXX1
001XXXXXXXXXX1
0001XXXXXXXXX1
00001XXXXXXXX1
000001XXXXXXX1
0000001XXXXXX1
00000001XXXXX1
000000001XXXX1
0000000001XXX1
00000000001XX1
000000000001X1
00000000000011
00000000000000
160 0 ▶ return $n->{ref} >= 0 ? $n->{ref} : $n->{static_dynamic_ref};
Branch: 1 branch
BranchTrueFalseTotal
$n->{'ref'} >= 0 ? : 0 0 0
161 }
162  
163 # Follows pure-reference hops (at most 16; not across resources when a dynamic scope is kept). The suffix extends the
164 # evaluation path by the keyword of each hop: /$ref, or /$dynamicRef or /$recursiveRef for a statically resolved
165 # dynamic reference.
166 12 ▶sub _resolve {
Subroutine _resolve: called CC=7 SCAR=28.4
167 12 my ($self, $node_id) = @_;
168 12 my $current = $node_id;
169 12 my $suffix = '';
170 12 for (1 .. 16) {
171 12 my $n = $self->{nodes}[$current];
172 12 my $next = $self->_pure_ref_target($n);
173 12 ▶ last if $next < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $next < 0 12 0 12
174 0 ▶ last if $self->{program}{uses_dynamic_scope} && $self->{nodes}[$next]{resource_id} != $n->{resource_id};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"program"}{"uses_dynamic_scope"} and $self->{"nodes"}[$next]{"resource_id"} != $n->{"resource_id"} 0 0 0
Condition0%0/3
$self->{"program"}{"uses_dynamic_scope"} and $self->{"nodes"}[$next]{"resource_id"} != $n->{"resource_id"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"program"}{"uses_dynamic_scope"} and $self->{"nodes"}[$next]{"resource_id"} != $n->{"resource_id"}
$self->{"program"}{"uses_dynamic_scope"} $self->{"nodes"}[$next]{"resource_id"} != $n->{"resource_id"}
Truth table0%0/3
A and B
A= $self->{"program"}{"uses_dynamic_scope"}B= $self->{"nodes"}[$next]{"resource_id"} != $n->{"resource_id"}
ABresult
0X0
100
111
175 0 ▶ $suffix .= $n->{ref} >= 0 ? '/$ref' : '/' . ($n->{static_dynamic_keyword} // '');
Branch: 1 branch
BranchTrueFalseTotal
$n->{'ref'} >= 0 ? : 0 0 0
Condition0%0/2
$n->{"static_dynamic_keyword"} // ""
l!l
00
MC/DC0%0/1
$n->{"static_dynamic_keyword"} // ""
$n->{"static_dynamic_keyword"}
Truth table0%0/2
A
A= $n->{"static_dynamic_keyword"}
Aresult
11
00
176 0 $current = $next;
177 }
178 12 return ($current, $suffix);
179 }
180  
181 12 ▶sub _eval_node {
Subroutine _eval_node: called CC=14 SCAR=37.6
182 12 my ($self, $node_id, $x, $bits) = @_;
183 12 my $n = $self->{nodes}[$node_id];
184 12 ▶ if ($n->{always_true} || $n->{always_false}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"always_true"} or $n->{"always_false"}) 0 12 12
Condition33%1/3
$n->{"always_true"} or $n->{"always_false"}
l!l&&r!l&&!r
0012
MC/DC0%0/2
$n->{"always_true"} or $n->{"always_false"}
$n->{"always_true"} $n->{"always_false"}
Truth table33%1/3
A or B
A= $n->{"always_true"}B= $n->{"always_false"}
ABresult
1X1
011
000
185 0 $self->{c}->evaluated_boolean_schema($n->{always_true}, undef);
186 0 ▶ return $n->{always_true} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$n->{'always_true'} ? : 0 0 0
187 }
188 12 my $pushed = 0;
189 12 my $scope = $self->{scope};
190 12 ▶ if ($self->{program}{uses_dynamic_scope} && (!@$scope || $scope->[-1] != $n->{resource_id})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"program"}{"uses_dynamic_scope"} and !@$scope || $scope->[-1] != $n->{"resource_id"}) 0 12 12
Condition16%1/6
$self->{"program"}{"uses_dynamic_scope"} and !@$scope || $scope->[-1] != $n->{"resource_id"}
!ll&&!rl&&r
1200
not @$scope or $scope->[-1] != $n->{"resource_id"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"program"}{"uses_dynamic_scope"} and !@$scope || $scope->[-1] != $n->{"resource_id"}
$self->{"program"}{"uses_dynamic_scope"} not @$scope $scope->[-1] != $n->{"resource_id"}
Truth table25%1/4
A and not(B) or C
A= $self->{"program"}{"uses_dynamic_scope"}B= not @$scopeC= $scope->[-1] != $n->{"resource_id"}
ABCresult
0XX0
1000
11X1
1011
191 0 push @$scope, $n->{resource_id};
192 0 $pushed = 1;
193 }
194 12 ▶ if (!$bits && (($n->{unevaluated_properties} >= 0 && ref $x eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (not $bits and $n->{"unevaluated_properties"} >= 0 && ref $x eq "HASH" || $n->{"unevaluated_items"} >= 0 && ref $x eq "ARRAY") 0 12 12
Condition33%4/12
not $bits and $n->{"unevaluated_properties"} >= 0 && ref $x eq "HASH" || $n->{"unevaluated_items"} >= 0 && ref $x eq "ARRAY"
!ll&&!rl&&r
0120
$n->{"unevaluated_properties"} >= 0 and ref $x eq "HASH" or $n->{"unevaluated_items"} >= 0 and ref $x eq "ARRAY"
l!l&&r!l&&!r
0012
$n->{"unevaluated_properties"} >= 0 and ref $x eq "HASH"
!ll&&!rl&&r
1200
$n->{"unevaluated_items"} >= 0 and ref $x eq "ARRAY"
!ll&&!rl&&r
1200
MC/DC0%0/5
not $bits and $n->{"unevaluated_properties"} >= 0 && ref $x eq "HASH" || $n->{"unevaluated_items"} >= 0 && ref $x eq "ARRAY"
not $bits $n->{"unevaluated_properties"} >= 0 ref $x eq "HASH" $n->{"unevaluated_items"} >= 0 ref $x eq "ARRAY"
Truth table12%1/8
not(A) and B and C or D and E
A= not $bitsB= $n->{"unevaluated_properties"} >= 0C= ref $x eq "HASH"D= $n->{"unevaluated_items"} >= 0E= ref $x eq "ARRAY"
ABCDEresult
0XXXX0
10X0X0
10X100
1100X0
110100
111XX1
10X111
110111
195 || ($n->{unevaluated_items} >= 0 && ref $x eq 'ARRAY'))) {
196 0 $bits = {};
197 }
198 12 my $ok = eval { $self->_eval_core($n, $x, $bits) };
199 12 my $error = $@;
200 12 ▶ pop @$scope if $pushed;
Branch: 1 branch
BranchTrueFalseTotal
if $pushed 0 12 12
201 12 ▶ die $error unless defined $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ok 0 12 12
202 12 return $ok;
203 }
204  
205 12 ▶sub _eval_core {
Subroutine _eval_core: called CC=34 SCAR=50.1
206 12 my ($self, $n, $x, $bits) = @_;
207 12 my $c = $self->{c};
208 12 my $ok = 1;
209 12 ▶ if ($n->{has_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"has_type"}) 10 2 12
210 10 my $m = _matches_type($n->{type}, $x, $n->{dialect});
211 10 $c->evaluated_keyword($m, _type_message($n->{type}), 'type');
212 10 ▶ $ok &&= $m;
Condition66%2/3
$ok &&= $m
!ll&&!rl&&r
028
MC/DC50%1/2
$ok &&= $m
$ok $m
Truth table66%2/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
213 }
214 12 ▶ if ($n->{has_const}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"has_const"}) 0 12 12
215 0 ▶ my $m = _equal($x, $n->{const_value}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
_equal($x, $n->{'const_value'}) ? : 0 0 0
216 0 $c->evaluated_keyword($m, _const_message($n->{const_value}), 'const');
217 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
218 }
219 12 ▶ if (defined $n->{enum_values}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n->{"enum_values"}) 0 12 12
220 0 ▶ my $m = JSON::Schema::Corvus::Runtime::includes($n->{enum_values}, $x) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
JSON::Schema::Corvus::Runtime::includes($n->{'enum_values'}, $x) ? : 0 0 0
221 0 ▶ $c->evaluated_keyword($m, $m ? MATCHED_AT_LEAST_ONE : DID_NOT_MATCH_AT_LEAST_ONE, 'enum');
Branch: 1 branch
BranchTrueFalseTotal
$m ? : 0 0 0
222 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
223 }
224 12 my $type = JSON::Schema::Corvus::Json::type_of($x);
225 12 ▶ if ($type eq 'number') {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'number') { } 4 8 12
elsif ($type eq 'string') { } 3 5 8
elsif ($type eq 'object') { } 4 1 5
elsif ($type eq 'array') { } 1 0 1
226 4 ▶ $ok = $self->_eval_number($n, $x) && $ok if $n->has_number_keywords;
Branch: 1 branch
BranchTrueFalseTotal
if $n->has_number_keywords 0 4 4
Condition0%0/3
$self->_eval_number($n, $x) && $ok
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_eval_number($n, $x) && $ok
$self->_eval_number($n, $x) $ok
Truth table0%0/3
A && B
A= $self->_eval_number($n, $x)B= $ok
ABresult
0X0
100
111
227 }
228 elsif ($type eq 'string') {
229 3 ▶ $ok = $self->_eval_string($n, $x) && $ok if $n->has_string_keywords;
Branch: 1 branch
BranchTrueFalseTotal
if $n->has_string_keywords 0 3 3
Condition0%0/3
$self->_eval_string($n, $x) && $ok
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_eval_string($n, $x) && $ok
$self->_eval_string($n, $x) $ok
Truth table0%0/3
A && B
A= $self->_eval_string($n, $x)B= $ok
ABresult
0X0
100
111
230 }
231 elsif ($type eq 'object') {
232 4 ▶ $ok = $self->_eval_object($n, $x, $bits) && $ok if $n->has_object_keywords;
Branch: 1 branch
BranchTrueFalseTotal
if $n->has_object_keywords 4 0 4
Condition66%2/3
$self->_eval_object($n, $x, $bits) && $ok
!ll&&!rl&&r
202
MC/DC50%1/2
$self->_eval_object($n, $x, $bits) && $ok
$self->_eval_object($n, $x, $bits) $ok
Truth table66%2/3
A && B
A= $self->_eval_object($n, $x, $bits)B= $ok
ABresult
0X0
100
111
233 }
234 elsif ($type eq 'array') {
235 1 ▶ $ok = $self->_eval_array($n, $x, $bits) && $ok if $n->has_array_keywords;
Branch: 1 branch
BranchTrueFalseTotal
if $n->has_array_keywords 1 0 1
Condition33%1/3
$self->_eval_array($n, $x, $bits) && $ok
!ll&&!rl&&r
001
MC/DC0%0/2
$self->_eval_array($n, $x, $bits) && $ok
$self->_eval_array($n, $x, $bits) $ok
Truth table33%1/3
A && B
A= $self->_eval_array($n, $x, $bits)B= $ok
ABresult
0X0
100
111
236 }
237 12 ▶ $ok = $self->_eval_in_place($n, $x, $bits) && $ok;
Condition66%2/3
$self->_eval_in_place($n, $x, $bits) && $ok
!ll&&!rl&&r
048
MC/DC50%1/2
$self->_eval_in_place($n, $x, $bits) && $ok
$self->_eval_in_place($n, $x, $bits) $ok
Truth table66%2/3
A && B
A= $self->_eval_in_place($n, $x, $bits)B= $ok
ABresult
0X0
100
111
238 12 ▶ if ($type eq 'object' && $n->{unevaluated_properties} >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'object' and $n->{'unevaluated_properties'} >= 0) { } 0 12 12
elsif ($type eq 'array' and $n->{'unevaluated_items'} >= 0) { } 0 23 23
Condition66%2/3
$type eq "object" and $n->{"unevaluated_properties"} >= 0
!ll&&!rl&&r
840
MC/DC0%0/2
$type eq "object" and $n->{"unevaluated_properties"} >= 0
$type eq "object" $n->{"unevaluated_properties"} >= 0
Truth table66%2/3
A and B
A= $type eq "object"B= $n->{"unevaluated_properties"} >= 0
ABresult
0X0
100
111
239 0 ▶ $ok = $self->_eval_unevaluated_properties($n, $x, $bits) && $ok;
Condition0%0/3
$self->_eval_unevaluated_properties($n, $x, $bits) && $ok
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_eval_unevaluated_properties($n, $x, $bits) && $ok
$self->_eval_unevaluated_properties($n, $x, $bits) $ok
Truth table0%0/3
A && B
A= $self->_eval_unevaluated_properties($n, $x, $bits)B= $ok
ABresult
0X0
100
111
240 }
241 ▶ elsif ($type eq 'array' && $n->{unevaluated_items} >= 0) {
Condition66%2/3
$type eq "array" and $n->{"unevaluated_items"} >= 0
!ll&&!rl&&r
1110
MC/DC0%0/2
$type eq "array" and $n->{"unevaluated_items"} >= 0
$type eq "array" $n->{"unevaluated_items"} >= 0
Truth table66%2/3
A and B
A= $type eq "array"B= $n->{"unevaluated_items"} >= 0
ABresult
0X0
100
111
242 0 ▶ $ok = $self->_eval_unevaluated_items($n, $x, $bits) && $ok;
Condition0%0/3
$self->_eval_unevaluated_items($n, $x, $bits) && $ok
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_eval_unevaluated_items($n, $x, $bits) && $ok
$self->_eval_unevaluated_items($n, $x, $bits) $ok
Truth table0%0/3
A && B
A= $self->_eval_unevaluated_items($n, $x, $bits)B= $ok
ABresult
0X0
100
111
243 }
244 12 ▶ if ($n->{annotations}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"annotations"}) 1 11 12
245 1 for my $a (@{ $n->{annotations} }) {
246 1 ▶ next if $a->{strings_only} && $type ne 'string';
Branch: 1 branch
BranchTrueFalseTotal
if $a->{"strings_only"} and $type ne "string" 0 1 1
Condition33%1/3
$a->{"strings_only"} and $type ne "string"
!ll&&!rl&&r
100
MC/DC0%0/2
$a->{"strings_only"} and $type ne "string"
$a->{"strings_only"} $type ne "string"
Truth table33%1/3
A and B
A= $a->{"strings_only"}B= $type ne "string"
ABresult
0X0
100
111
247 1 my $value = $a->{value};
248 1 ▶ $c->ignored_keyword(sub { _json_text($value) }, $a->{keyword});
Subroutine __ANON__: called CC=1 SCAR=0.0
249 }
250 }
251 12 ▶ return $ok ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 8 4 12
252 }
253  
254 # --- Numbers and strings ---
255  
256 0 ▶sub _eval_number {
Subroutine _eval_number: not called CC=8 SCAR=42.8
257 0 my ($self, $n, $x) = @_;
258 0 my $c = $self->{c};
259 0 my $ok = 1;
260 0 ▶ if ($n->{assert_format} && defined $n->{format} && JSON::Schema::Corvus::Formats::is_numeric_format($n->{format_kind})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"assert_format"} and defined $n->{"format"} and JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})) 0 0 0
Condition0%0/6
$n->{"assert_format"} and defined $n->{"format"} and JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
!ll&&!rl&&r
000
$n->{"assert_format"} and defined $n->{"format"}
!ll&&!rl&&r
000
MC/DC0%0/3
$n->{"assert_format"} and defined $n->{"format"} and JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
$n->{"assert_format"} defined $n->{"format"} JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
Truth table0%0/4
A and B and C
A= $n->{"assert_format"}B= defined $n->{"format"}C= JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
ABCresult
0XX0
10X0
1100
1111
261 0 ▶ my $custom = ($self->{program}{formats} // {})->{ $n->{format} };
Condition0%0/2
$self->{"program"}{"formats"} // {}
l!l
00
MC/DC0%0/1
$self->{"program"}{"formats"} // {}
$self->{"program"}{"formats"}
Truth table0%0/2
A
A= $self->{"program"}{"formats"}
Aresult
11
00
262 my $m = ($custom ? $custom->(number_text($x))
263 0 ▶ : $JSON::Schema::Corvus::Formats::NUMERIC_FORMAT_VALIDATORS{ $n->{format_kind} }->($x)) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
($custom ? &$custom(number_text($x)) : $JSON::Schema::Corvus::Formats::NUMERIC_FORMAT_VALIDATORS{$n->{'format_kind'}}($x)) ? : 0 0 0
$custom ? : 0 0 0
264 0 $c->evaluated_keyword($m,
265 "The value was expected to be in a supported format, and within bounds for '$n->{format_kind}'", 'format');
266 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
267 }
268 0 ▶ my $bound = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
269 0 my ($value, $test, $text, $keyword) = @_;
270 0 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
271 0 ▶ my $m = $test->($value) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&$test($value) ? : 0 0 0
272 0 ▶ $c->evaluated_keyword($m, sub { $text . _q(number_text($value)) }, $keyword);
Subroutine __ANON__: not called CC=1 SCAR=6.9
273 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
274 0 };
275 0 ▶ $bound->($n->{minimum}, sub { $x >= $_[0] }, 'The value was expected to be greater than or equal to', 'minimum');
Subroutine __ANON__: not called CC=1 SCAR=6.9
276 0 ▶ $bound->($n->{maximum}, sub { $x <= $_[0] }, 'The value was expected to be less than or equal to', 'maximum');
Subroutine __ANON__: not called CC=1 SCAR=6.9
277 0 ▶ $bound->($n->{exclusive_minimum}, sub { $x > $_[0] }, 'The value was expected to be greater than',
Subroutine __ANON__: not called CC=1 SCAR=6.9
278 'exclusiveMinimum');
279 0 ▶ $bound->($n->{exclusive_maximum}, sub { $x < $_[0] }, 'The value was expected to be less than', 'exclusiveMaximum');
Subroutine __ANON__: not called CC=1 SCAR=6.9
280 0 ▶ $bound->($n->{multiple_of}, sub { JSON::Schema::Corvus::Runtime::multiple_of($x, $_[0]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
281 0 'The value was expected to be a multiple of', 'multipleOf');
282 0 return $ok;
283 }
284  
285 0 ▶sub _search {
Subroutine _search: not called CC=3 SCAR=24.8
286 0 my ($self, $pattern, $s) = @_;
287 0 my $m = JSON::Schema::Corvus::Pattern::compile_pattern($pattern, $self->{program}{pattern_match_limit});
288 0 ▶ return $m && $m->($s) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$m && &$m($s) ? : 0 0 0
Condition0%0/3
$m and &$m($s)
!ll&&!rl&&r
000
MC/DC0%0/2
$m and &$m($s)
$m &$m($s)
Truth table0%0/3
A and B
A= $mB= &$m($s)
ABresult
0X0
100
111
289 }
290  
291 0 ▶sub _eval_string {
Subroutine _eval_string: not called CC=30 SCAR=68.4
292 0 my ($self, $n, $x) = @_;
293 0 my $c = $self->{c};
294 0 my $ok = 1;
295 0 my $length;
296 0 ▶ if ($n->{min_length} >= 0 || $n->{max_length} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"min_length"} >= 0 or $n->{"max_length"} >= 0) 0 0 0
Condition0%0/3
$n->{"min_length"} >= 0 or $n->{"max_length"} >= 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$n->{"min_length"} >= 0 or $n->{"max_length"} >= 0
$n->{"min_length"} >= 0 $n->{"max_length"} >= 0
Truth table0%0/3
A or B
A= $n->{"min_length"} >= 0B= $n->{"max_length"} >= 0
ABresult
1X1
011
000
297 # The length in code points (a JSON string is UTF-16, but its length here is in characters, as the other ports
298 # count it).
299 0 $length = length $x;
300 }
301 0 ▶ if ($n->{min_length} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"min_length"} >= 0) 0 0 0
302 0 ▶ my $m = $length >= $n->{min_length} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$length >= $n->{'min_length'} ? : 0 0 0
303 0 $c->evaluated_keyword($m, "Expected the length of the value to be greater than or equal to '$n->{min_length}'",
304 'minLength');
305 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
306 }
307 0 ▶ if ($n->{max_length} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"max_length"} >= 0) 0 0 0
308 0 ▶ my $m = $length <= $n->{max_length} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$length <= $n->{'max_length'} ? : 0 0 0
309 0 $c->evaluated_keyword($m, "Expected the length of the value to be less than or equal to '$n->{max_length}'",
310 'maxLength');
311 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
312 }
313 0 ▶ if (defined $n->{pattern}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n->{"pattern"}) 0 0 0
314 0 my $pattern = $n->{pattern};
315 0 my $m = $self->_search($pattern, $x);
316 0 ▶ $c->evaluated_keyword($m, sub { 'Expected the value to match the regular expression' . _q($pattern) }, 'pattern');
Subroutine __ANON__: not called CC=1 SCAR=6.9
317 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
318 }
319 0 ▶ if ($n->{assert_format} && defined $n->{format} && !JSON::Schema::Corvus::Formats::is_numeric_format($n->{format_kind})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"assert_format"} and defined $n->{"format"} and not JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})) 0 0 0
Condition0%0/6
$n->{"assert_format"} and defined $n->{"format"} and not JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
!ll&&!rl&&r
000
$n->{"assert_format"} and defined $n->{"format"}
!ll&&!rl&&r
000
MC/DC0%0/3
$n->{"assert_format"} and defined $n->{"format"} and not JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
$n->{"assert_format"} defined $n->{"format"} not JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
Truth table0%0/4
A and B and not(C)
A= $n->{"assert_format"}B= defined $n->{"format"}C= not JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
ABCresult
0XX0
10X0
1100
1111
320 0 ▶ my $custom = ($self->{program}{formats} // {})->{ $n->{format} };
Condition0%0/2
$self->{"program"}{"formats"} // {}
l!l
00
MC/DC0%0/1
$self->{"program"}{"formats"} // {}
$self->{"program"}{"formats"}
Truth table0%0/2
A
A= $self->{"program"}{"formats"}
Aresult
11
00
321 0 my ($m, $message);
322 0 ▶ if ($custom) {
Branch: 2 branches
BranchTrueFalseTotal
if ($custom) { } 0 0 0
elsif ($n->{'format_kind'} eq 'unknown') { } 0 0 0
323 0 ▶ $m = $custom->($x) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&$custom($x) ? : 0 0 0
324 0 $message = "Expected a string in the '$n->{format}' format.";
325 }
326 elsif ($n->{format_kind} eq 'unknown') {
327 0 $m = 1;
328 }
329 else {
330 my $validate = $n->{format_kind} eq 'hostname' && $n->{dialect} <= DRAFT6
331 ? \&JSON::Schema::Corvus::Formats::legacy_hostname
332 0 ▶ : $JSON::Schema::Corvus::Formats::FORMAT_VALIDATORS{ $n->{format_kind} };
Branch: 1 branch
BranchTrueFalseTotal
$n->{'format_kind'} eq 'hostname' && $n->{'dialect'} <= 1 ? : 0 0 0
Condition0%0/3
$n->{"format_kind"} eq "hostname" and $n->{"dialect"} <= 1
!ll&&!rl&&r
000
MC/DC0%0/2
$n->{"format_kind"} eq "hostname" and $n->{"dialect"} <= 1
$n->{"format_kind"} eq "hostname" $n->{"dialect"} <= 1
Truth table0%0/3
A and B
A= $n->{"format_kind"} eq "hostname"B= $n->{"dialect"} <= 1
ABresult
0X0
100
111
333 0 ▶ $m = $validate->($x) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&$validate($x) ? : 0 0 0
334 0 $message = $STRING_FORMAT_MESSAGES{ $n->{format_kind} };
335 }
336 0 $c->evaluated_keyword($m, $message, 'format');
337 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
338 }
339 0 ▶ if ($n->{assert_content}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"assert_content"}) 0 0 0
340 0 ▶ my $kind = $n->{content} == CONTENT_BASE64 ? 1 : $n->{content} == CONTENT_JSON ? 2 : 3;
Branch: 2 branches
BranchTrueFalseTotal
$n->{'content'} == 1 ? : 0 0 0
$n->{'content'} == 2 ? : 0 0 0
341 0 ▶ my $m = JSON::Schema::Corvus::Runtime::content($x, $kind) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
JSON::Schema::Corvus::Runtime::content($x, $kind) ? : 0 0 0
342 0 ▶ my $text = $kind == 1 ? 'Expected a valid Base64-encoded string.' : $kind == 2 ? 'Expected valid JSON content.'
Branch: 2 branches
BranchTrueFalseTotal
$kind == 1 ? : 0 0 0
$kind == 2 ? : 0 0 0
343 : 'Expected valid Base64-encoded JSON content.';
344 0 ▶ $c->evaluated_keyword($m, $text, $kind == 1 ? 'contentEncoding' : 'contentMediaType');
Branch: 1 branch
BranchTrueFalseTotal
$kind == 1 ? : 0 0 0
345 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
346 }
347 0 return $ok;
348 }
349  
350 # --- Objects ---
351  
352 # A child application at a new instance location (a property value or an array item).
353 7 ▶sub _eval_at {
Subroutine _eval_at: called CC=1 SCAR=0.0
354 7 my ($self, $child_id, $path, $value, $doc_segment) = @_;
355 7 my ($target, $suffix) = $self->_resolve($child_id);
356 7 $self->{c}->begin_child_context($path . $suffix, $self->{nodes}[$target]{pointer}, $doc_segment);
357 7 my $ok = $self->_eval_node($target, $value, undef);
358 7 $self->{c}->commit_child_context($ok, $ok, EVALUATED_SUBSCHEMA);
359 7 return $ok;
360 }
361  
362 4 ▶sub _eval_object {
Subroutine _eval_object: called CC=40 SCAR=60.9
363 4 my ($self, $n, $x, $bits) = @_;
364 4 my $c = $self->{c};
365 4 my $ok = 1;
366 4 my $count = keys %$x;
367 4 ▶ if ($n->{min_properties} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"min_properties"} >= 0) 0 4 4
368 0 ▶ my $m = $count >= $n->{min_properties} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$count >= $n->{'min_properties'} ? : 0 0 0
369 0 $c->evaluated_keyword($m, "Expected the property count to be greater than or equal to '$n->{min_properties}'",
370 'minProperties');
371 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
372 }
373 4 ▶ if ($n->{max_properties} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"max_properties"} >= 0) 0 4 4
374 0 ▶ my $m = $count <= $n->{max_properties} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$count <= $n->{'max_properties'} ? : 0 0 0
375 0 $c->evaluated_keyword($m, "Expected the property count to be less than or equal to '$n->{max_properties}'",
376 'maxProperties');
377 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
378 }
379 4 ▶ if (defined $n->{properties} || defined $n->{pattern_properties} || $n->{additional_properties} >= 0
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n->{"properties"} or defined $n->{"pattern_properties"} or $n->{"additional_properties"} >= 0 or $n->{"property_names"} >= 0) 4 0 4
Condition33%3/9
defined $n->{"properties"} or defined $n->{"pattern_properties"} or $n->{"additional_properties"} >= 0 or $n->{"property_names"} >= 0
l!l&&r!l&&!r
400
defined $n->{"properties"} or defined $n->{"pattern_properties"} or $n->{"additional_properties"} >= 0
l!l&&r!l&&!r
400
defined $n->{"properties"} or defined $n->{"pattern_properties"}
l!l&&r!l&&!r
400
MC/DC0%0/4
defined $n->{"properties"} or defined $n->{"pattern_properties"} or $n->{"additional_properties"} >= 0 or $n->{"property_names"} >= 0
defined $n->{"properties"} defined $n->{"pattern_properties"} $n->{"additional_properties"} >= 0 $n->{"property_names"} >= 0
Truth table20%1/5
A or B or C or D
A= defined $n->{"properties"}B= defined $n->{"pattern_properties"}C= $n->{"additional_properties"} >= 0D= $n->{"property_names"} >= 0
ABCDresult
1XXX1
01XX1
001X1
00011
00000
380 || $n->{property_names} >= 0) {
381 4 for my $k (JSON::Schema::Corvus::Json::names($x)) {
382 5 my $v = $x->{$k};
383 5 my $doc = _segment($k);
384 5 my $matched = 0;
385 5 ▶ my $p = $n->{properties} ? $n->{properties}{$k} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$n->{'properties'} ? : 5 0 5
386 5 ▶ if (defined $p) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p) 4 1 5
387 4 $matched = 1;
388 4 ▶ $bits->{$k} = 1 if $bits;
Branch: 1 branch
BranchTrueFalseTotal
if $bits 0 4 4
389 4 ▶ $ok = $self->_eval_at($p, 'properties/' . _segment($k), $v, $doc) && $ok;
Condition66%2/3
$self->_eval_at($p, 'properties/' . _segment($k), $v, $doc) && $ok
!ll&&!rl&&r
202
MC/DC50%1/2
$self->_eval_at($p, 'properties/' . _segment($k), $v, $doc) && $ok
$self->_eval_at($p, 'properties/' . _segment($k), $v, $doc) $ok
Truth table66%2/3
A && B
A= $self->_eval_at($p, 'properties/' . _segment($k), $v, $doc)B= $ok
ABresult
0X0
100
111
390 }
391 5 ▶ for my $pp (@{ $n->{pattern_properties} // [] }) {
Condition50%1/2
$n->{"pattern_properties"} // []
l!l
05
MC/DC0%0/1
$n->{"pattern_properties"} // []
$n->{"pattern_properties"}
Truth table50%1/2
A
A= $n->{"pattern_properties"}
Aresult
11
00
392 0 ▶ next unless $self->_search($pp->{pattern}, $k);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_search($pp->{"pattern"}, $k) 0 0 0
393 0 $matched = 1;
394 0 ▶ $bits->{$k} = 1 if $bits;
Branch: 1 branch
BranchTrueFalseTotal
if $bits 0 0 0
395 0 ▶ $ok = $self->_eval_at($pp->{node}, 'patternProperties/' . _segment($pp->{pattern}), $v, $doc) && $ok;
Condition0%0/3
$self->_eval_at($pp->{'node'}, 'patternProperties/' . _segment($pp->{'pattern'}), $v, $doc) && $ok
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_eval_at($pp->{'node'}, 'patternProperties/' . _segment($pp->{'pattern'}), $v, $doc) && $ok
$self->_eval_at($pp->{'node'}, 'patternProperties/' . _segment($pp->{'pattern'}), $v, $doc) $ok
Truth table0%0/3
A && B
A= $self->_eval_at($pp->{'node'}, 'patternProperties/' . _segment($pp->{'pattern'}), $v, $doc)B= $ok
ABresult
0X0
100
111
396 }
397 5 ▶ if ($n->{additional_properties} >= 0 && !$matched) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"additional_properties"} >= 0 and not $matched) 0 5 5
Condition33%1/3
$n->{"additional_properties"} >= 0 and not $matched
!ll&&!rl&&r
500
MC/DC0%0/2
$n->{"additional_properties"} >= 0 and not $matched
$n->{"additional_properties"} >= 0 not $matched
Truth table33%1/3
A and not(B)
A= $n->{"additional_properties"} >= 0B= not $matched
ABresult
0X0
100
111
398 0 ▶ $bits->{$k} = 1 if $bits;
Branch: 1 branch
BranchTrueFalseTotal
if $bits 0 0 0
399 0 ▶ $ok = $self->_eval_at($n->{additional_properties}, 'additionalProperties', $v, $doc) && $ok;
Condition0%0/3
$self->_eval_at($n->{'additional_properties'}, 'additionalProperties', $v, $doc) && $ok
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_eval_at($n->{'additional_properties'}, 'additionalProperties', $v, $doc) && $ok
$self->_eval_at($n->{'additional_properties'}, 'additionalProperties', $v, $doc) $ok
Truth table0%0/3
A && B
A= $self->_eval_at($n->{'additional_properties'}, 'additionalProperties', $v, $doc)B= $ok
ABresult
0X0
100
111
400 }
401 5 ▶ if ($n->{property_names} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"property_names"} >= 0) 0 5 5
402 # Not elided; the document path stays the object's.
403 0 $c->begin_child_context('propertyNames', $self->{nodes}[ $n->{property_names} ]{pointer}, undef);
404 0 my $m = $self->_eval_node($n->{property_names}, $k, undef);
405 0 $c->commit_child_context($m, $m, EVALUATED_SUBSCHEMA);
406 0 ▶ if (!$m) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($m) 0 0 0
407 0 $c->evaluated_keyword(0, PROPERTY_NAME_FAILED, 'propertyNames');
408 0 $ok = 0;
409 }
410 }
411 }
412 }
413 4 ▶ if ($n->{required_list}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"required_list"}) 3 1 4
414 3 for my $r (@{ $n->{required_list} }) {
415 3 ▶ my $present = exists $x->{$r} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $x->{$r} ? : 1 2 3
416 3 $c->evaluated_keyword_for_property($present, _required_message($present, $r), $r, 'required');
417 3 ▶ $ok &&= $present;
Condition66%2/3
$ok &&= $present
!ll&&!rl&&r
201
MC/DC50%1/2
$ok &&= $present
$ok $present
Truth table66%2/3
A &&= B
A= $okB= $present
ABresult
0X0
100
111
418 }
419 }
420 4 ▶ if ($n->{dependencies}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"dependencies"}) 0 4 4
421 # Rows are reported under the keyword the schema used (dependencies, dependentRequired or dependentSchemas).
422 0 for my $d (@{ $n->{dependencies} }) {
423 0 ▶ next unless exists $x->{ $d->{name} };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$x{$d->{"name"}} 0 0 0
424 0 ▶ for my $r (@{ $d->{required} // [] }) {
Condition0%0/2
$d->{"required"} // []
l!l
00
MC/DC0%0/1
$d->{"required"} // []
$d->{"required"}
Truth table0%0/2
A
A= $d->{"required"}
Aresult
11
00
425 0 ▶ my $present = exists $x->{$r} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $x->{$r} ? : 0 0 0
426 0 $c->evaluated_keyword_for_property($present, _required_message($present, $r), $r, $d->{keyword});
427 0 ▶ $ok &&= $present;
Condition0%0/3
$ok &&= $present
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $present
$ok $present
Truth table0%0/3
A &&= B
A= $okB= $present
ABresult
0X0
100
111
428 }
429 0 ▶ if (defined $d->{schema}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $d->{"schema"}) 0 0 0
430 0 my ($m) = $self->_eval_in_place_child($d->{schema}, "$d->{keyword}/" . _segment($d->{name}), $x, $bits, 1);
431 0 $c->evaluated_keyword_for_property($m, _dependency_message($d->{name}), $d->{name}, $d->{keyword});
432 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
433 }
434 }
435 }
436 4 return $ok;
437 }
438  
439 0 ▶sub _eval_unevaluated_properties {
Subroutine _eval_unevaluated_properties: not called CC=4 SCAR=30.0
440 0 my ($self, $n, $x, $bits) = @_;
441 0 my $ok = 1;
442 0 for my $k (JSON::Schema::Corvus::Json::names($x)) {
443 0 ▶ next if $bits->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if $bits->{$k} 0 0 0
444 0 $bits->{$k} = 1;
445 0 ▶ $ok = $self->_eval_at($n->{unevaluated_properties}, 'unevaluatedProperties', $x->{$k}, _segment($k)) && $ok;
Condition0%0/3
$self->_eval_at($n->{'unevaluated_properties'}, 'unevaluatedProperties', $x->{$k}, _segment($k)) && $ok
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_eval_at($n->{'unevaluated_properties'}, 'unevaluatedProperties', $x->{$k}, _segment($k)) && $ok
$self->_eval_at($n->{'unevaluated_properties'}, 'unevaluatedProperties', $x->{$k}, _segment($k)) $ok
Truth table0%0/3
A && B
A= $self->_eval_at($n->{'unevaluated_properties'}, 'unevaluatedProperties', $x->{$k}, _segment($k))B= $ok
ABresult
0X0
100
111
446 }
447 0 $self->{c}->evaluated_keyword($ok, undef, 'unevaluatedProperties');
448 0 return $ok;
449 }
450  
451 # --- Arrays ---
452  
453 1 ▶sub _eval_array {
Subroutine _eval_array: called CC=36 SCAR=62.6
454 1 my ($self, $n, $x, $bits) = @_;
455 1 my $c = $self->{c};
456 1 my $ok = 1;
457 1 my $length = @$x;
458 1 ▶ if ($n->{min_items} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"min_items"} >= 0) 0 1 1
459 0 ▶ my $m = $length >= $n->{min_items} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$length >= $n->{'min_items'} ? : 0 0 0
460 0 $c->evaluated_keyword($m, "Expected the item count to be greater than or equal to '$n->{min_items}'", 'minItems');
461 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
462 }
463 1 ▶ if ($n->{max_items} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"max_items"} >= 0) 0 1 1
464 0 ▶ my $m = $length <= $n->{max_items} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$length <= $n->{'max_items'} ? : 0 0 0
465 0 $c->evaluated_keyword($m, "Expected the item count to be less than or equal to '$n->{max_items}'", 'maxItems');
466 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
467 }
468 1 ▶ return $ok if !defined $n->{prefix_items} && $n->{items} < 0 && $n->{contains} < 0 && !$n->{unique_items};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $n->{"prefix_items"} and $n->{"items"} < 0 and $n->{"contains"} < 0 and not $n->{"unique_items"} 0 1 1
Condition33%3/9
not defined $n->{"prefix_items"} and $n->{"items"} < 0 and $n->{"contains"} < 0 and not $n->{"unique_items"}
!ll&&!rl&&r
100
not defined $n->{"prefix_items"} and $n->{"items"} < 0 and $n->{"contains"} < 0
!ll&&!rl&&r
100
not defined $n->{"prefix_items"} and $n->{"items"} < 0
!ll&&!rl&&r
010
MC/DC0%0/4
not defined $n->{"prefix_items"} and $n->{"items"} < 0 and $n->{"contains"} < 0 and not $n->{"unique_items"}
not defined $n->{"prefix_items"} $n->{"items"} < 0 $n->{"contains"} < 0 not $n->{"unique_items"}
Truth table20%1/5
not(A) and B and C and not(D)
A= not defined $n->{"prefix_items"}B= $n->{"items"} < 0C= $n->{"contains"} < 0D= not $n->{"unique_items"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
469 1 my $count = 0;
470 1 my $unique = 1;
471 1 my $prefix = $n->{prefix_items};
472 1 for my $i (0 .. $length - 1) {
473 3 ▶ if ($prefix && $i < @$prefix) {
Branch: 2 branches
BranchTrueFalseTotal
if ($prefix and $i < @$prefix) { } 0 3 3
elsif ($n->{'items'} >= 0) { } 3 0 3
Condition33%1/3
$prefix and $i < @$prefix
!ll&&!rl&&r
300
MC/DC0%0/2
$prefix and $i < @$prefix
$prefix $i < @$prefix
Truth table33%1/3
A and B
A= $prefixB= $i < @$prefix
ABresult
0X0
100
111
474 0 ▶ $bits->{"#$i"} = 1 if $bits;
Branch: 1 branch
BranchTrueFalseTotal
if $bits 0 0 0
475 0 ▶ $ok = $self->_eval_at($prefix->[$i], "$n->{prefix_keyword}/$i", $x->[$i], "$i") && $ok;
Condition0%0/3
$self->_eval_at($prefix->[$i], "$n->{'prefix_keyword'}/$i", $x->[$i], "$i") && $ok
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_eval_at($prefix->[$i], "$n->{'prefix_keyword'}/$i", $x->[$i], "$i") && $ok
$self->_eval_at($prefix->[$i], "$n->{'prefix_keyword'}/$i", $x->[$i], "$i") $ok
Truth table0%0/3
A && B
A= $self->_eval_at($prefix->[$i], "$n->{'prefix_keyword'}/$i", $x->[$i], "$i")B= $ok
ABresult
0X0
100
111
476 }
477 elsif ($n->{items} >= 0) {
478 3 ▶ $bits->{"#$i"} = 1 if $bits;
Branch: 1 branch
BranchTrueFalseTotal
if $bits 0 3 3
479 3 ▶ $ok = $self->_eval_at($n->{items}, $n->{items_keyword}, $x->[$i], "$i") && $ok;
Condition33%1/3
$self->_eval_at($n->{'items'}, $n->{'items_keyword'}, $x->[$i], "$i") && $ok
!ll&&!rl&&r
003
MC/DC0%0/2
$self->_eval_at($n->{'items'}, $n->{'items_keyword'}, $x->[$i], "$i") && $ok
$self->_eval_at($n->{'items'}, $n->{'items_keyword'}, $x->[$i], "$i") $ok
Truth table33%1/3
A && B
A= $self->_eval_at($n->{'items'}, $n->{'items_keyword'}, $x->[$i], "$i")B= $ok
ABresult
0X0
100
111
480 }
481 3 ▶ if ($n->{contains} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"contains"} >= 0) 0 3 3
482 0 my ($target, $suffix) = $self->_resolve($n->{contains});
483 0 $c->begin_child_context("contains$suffix", $self->{nodes}[$target]{pointer}, "$i");
484 0 ▶ if ($self->_eval_node($target, $x->[$i], undef)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eval_node($target, $x->[$i], undef)) { } 0 0 0
485 0 $c->commit_child_context(1, 1, EVALUATED_SUBSCHEMA);
486 0 $count++;
487 0 ▶ $bits->{"#$i"} = 1 if $n->{contains_marks_evaluated} && $bits;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"contains_marks_evaluated"} and $bits 0 0 0
Condition0%0/3
$n->{"contains_marks_evaluated"} and $bits
!ll&&!rl&&r
000
MC/DC0%0/2
$n->{"contains_marks_evaluated"} and $bits
$n->{"contains_marks_evaluated"} $bits
Truth table0%0/3
A and B
A= $n->{"contains_marks_evaluated"}B= $bits
ABresult
0X0
100
111
488 }
489 else {
490 0 $c->pop_child_context;
491 }
492 }
493 3 ▶ if ($n->{unique_items} && $unique) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"unique_items"} and $unique) 0 3 3
Condition33%1/3
$n->{"unique_items"} and $unique
!ll&&!rl&&r
300
MC/DC0%0/2
$n->{"unique_items"} and $unique
$n->{"unique_items"} $unique
Truth table33%1/3
A and B
A= $n->{"unique_items"}B= $unique
ABresult
0X0
100
111
494 0 for my $j (0 .. $i - 1) {
495 0 ▶ if (_equal($x->[$i], $x->[$j])) {
Branch: 1 branch
BranchTrueFalseTotal
if (_equal($x->[$i], $x->[$j])) 0 0 0
496 0 $unique = 0;
497 0 last;
498 }
499 }
500 }
501 }
502 1 ▶ if ($n->{unique_items}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"unique_items"}) 0 1 1
503 0 $c->evaluated_keyword($unique, UNIQUE_ITEMS, 'uniqueItems');
504 0 ▶ $ok &&= $unique;
Condition0%0/3
$ok &&= $unique
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $unique
$ok $unique
Truth table0%0/3
A &&= B
A= $okB= $unique
ABresult
0X0
100
111
505 }
506 1 ▶ if ($n->{contains} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"contains"} >= 0) 0 1 1
507 0 my $hi = $n->{max_contains};
508 0 ▶ my $m = ($count >= $n->{min_contains} && ($hi < 0 || $count <= $hi)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$count >= $n->{'min_contains'} && ($hi < 0 || $count <= $hi) ? : 0 0 0
Condition0%0/6
$count >= $n->{"min_contains"} and $hi < 0 || $count <= $hi
!ll&&!rl&&r
000
$hi < 0 or $count <= $hi
l!l&&r!l&&!r
000
MC/DC0%0/3
$count >= $n->{"min_contains"} and $hi < 0 || $count <= $hi
$count >= $n->{"min_contains"} $hi < 0 $count <= $hi
Truth table0%0/4
A and B or C
A= $count >= $n->{"min_contains"}B= $hi < 0C= $count <= $hi
ABCresult
0XX0
1000
11X1
1011
509 0 ▶ my $message = $hi >= 0 && $count > $hi ? "Expected the contains count to be less than or equal to '$hi'"
Branch: 1 branch
BranchTrueFalseTotal
$hi >= 0 && $count > $hi ? : 0 0 0
Condition0%0/3
$hi >= 0 and $count > $hi
!ll&&!rl&&r
000
MC/DC0%0/2
$hi >= 0 and $count > $hi
$hi >= 0 $count > $hi
Truth table0%0/3
A and B
A= $hi >= 0B= $count > $hi
ABresult
0X0
100
111
510 : "Expected the contains count to be greater than or equal to '$n->{min_contains}'";
511 0 $c->evaluated_keyword($m, $message, 'contains');
512 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
513 }
514 1 return $ok;
515 }
516  
517 0 ▶sub _eval_unevaluated_items {
Subroutine _eval_unevaluated_items: not called CC=4 SCAR=30.0
518 0 my ($self, $n, $x, $bits) = @_;
519 0 my $ok = 1;
520 0 for my $i (0 .. $#$x) {
521 0 ▶ next if $bits->{"#$i"};
Branch: 1 branch
BranchTrueFalseTotal
if $$bits{"#$i"} 0 0 0
522 0 $bits->{"#$i"} = 1;
523 0 ▶ $ok = $self->_eval_at($n->{unevaluated_items}, 'unevaluatedItems', $x->[$i], "$i") && $ok;
Condition0%0/3
$self->_eval_at($n->{'unevaluated_items'}, 'unevaluatedItems', $x->[$i], "$i") && $ok
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_eval_at($n->{'unevaluated_items'}, 'unevaluatedItems', $x->[$i], "$i") && $ok
$self->_eval_at($n->{'unevaluated_items'}, 'unevaluatedItems', $x->[$i], "$i") $ok
Truth table0%0/3
A && B
A= $self->_eval_at($n->{'unevaluated_items'}, 'unevaluatedItems', $x->[$i], "$i")B= $ok
ABresult
0X0
100
111
524 }
525 0 $self->{c}->evaluated_keyword($ok, undef, 'unevaluatedItems');
526 0 return $ok;
527 }
528  
529 # --- In-place applicators ---
530  
531 0 ▶sub _can_mark {
Subroutine _can_mark: not called CC=2 SCAR=17.9
532 0 my ($self, $node_id, $x) = @_;
533 0 my $n = $self->{nodes}[$node_id];
534 0 ▶ return ref $x eq 'HASH' ? $n->{marks_properties} : $n->{marks_items};
Branch: 1 branch
BranchTrueFalseTotal
ref $x eq 'HASH' ? : 0 0 0
535 }
536  
537 # Evaluates an in-place child (EvalInPlaceCore): a new context at the same instance location, on a fresh scratch set of
538 # evaluated properties or items merged into the parent's on success. A failing child is committed or popped.
539 0 ▶sub _eval_in_place_child {
Subroutine _eval_in_place_child: not called CC=14 SCAR=53.5
540 0 my ($self, $child_id, $path, $x, $bits, $commit_on_failure, $no_elide) = @_;
541 0 ▶ my ($target, $suffix) = $no_elide ? ($child_id, '') : $self->_resolve($child_id);
Branch: 1 branch
BranchTrueFalseTotal
$no_elide ? : 0 0 0
542 0 ▶ my $scratch = $bits && $self->_can_mark($child_id, $x) ? {} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$bits && $self->_can_mark($child_id, $x) ? : 0 0 0
Condition0%0/3
$bits and $self->_can_mark($child_id, $x)
!ll&&!rl&&r
000
MC/DC0%0/2
$bits and $self->_can_mark($child_id, $x)
$bits $self->_can_mark($child_id, $x)
Truth table0%0/3
A and B
A= $bitsB= $self->_can_mark($child_id, $x)
ABresult
0X0
100
111
543 0 my $guarded = $self->{nodes}[$target]{in_place_cycle};
544 0 ▶ if ($guarded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guarded) 0 0 0
545 0 ▶ if (++$self->{depth} > $self->{program}{max_depth}) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->{"depth"} > $self->{"program"}{"max_depth"}) 0 0 0
546 0 $self->{depth} = 0;
547 0 JSON::Schema::Corvus::Runtime::depth_exceeded();
548 }
549 }
550 0 my $ok = eval {
551 0 $self->{c}->begin_child_context($path . $suffix, $self->{nodes}[$target]{pointer}, undef);
552 0 my $r = $self->_eval_node($target, $x, $scratch);
553 0 ▶ if ($r || $commit_on_failure) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r or $commit_on_failure) { } 0 0 0
Condition0%0/3
$r or $commit_on_failure
l!l&&r!l&&!r
000
MC/DC0%0/2
$r or $commit_on_failure
$r $commit_on_failure
Truth table0%0/3
A or B
A= $rB= $commit_on_failure
ABresult
1X1
011
000
554 0 $self->{c}->commit_child_context($r, $r, EVALUATED_SUBSCHEMA);
555 }
556 else {
557 0 $self->{c}->pop_child_context;
558 }
559 0 ▶ @$bits{ keys %$scratch } = values %$scratch if $r && $scratch && $bits;
Branch: 1 branch
BranchTrueFalseTotal
if $r and $scratch and $bits 0 0 0
Condition0%0/6
$r and $scratch and $bits
!ll&&!rl&&r
000
$r and $scratch
!ll&&!rl&&r
000
MC/DC0%0/3
$r and $scratch and $bits
$r $scratch $bits
Truth table0%0/4
A and B and C
A= $rB= $scratchC= $bits
ABCresult
0XX0
10X0
1100
1111
560 0 $r;
561 };
562 0 my $error = $@;
563 0 ▶ $self->{depth}-- if $guarded && $self->{depth} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $guarded and $self->{"depth"} > 0 0 0 0
Condition0%0/3
$guarded and $self->{"depth"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$guarded and $self->{"depth"} > 0
$guarded $self->{"depth"} > 0
Truth table0%0/3
A and B
A= $guardedB= $self->{"depth"} > 0
ABresult
0X0
100
111
564 0 ▶ die $error unless defined $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ok 0 0 0
565 0 return ($ok, $scratch);
566 }
567  
568 0 ▶sub _resolve_dynamic {
Subroutine _resolve_dynamic: not called CC=3 SCAR=24.8
569 0 my ($self, $d) = @_;
570 0 for my $resource (@{ $self->{scope} }) {
571 0 my $target = $d->{by_resource}{$resource};
572 0 ▶ return $target if defined $target;
Branch: 1 branch
BranchTrueFalseTotal
if defined $target 0 0 0
573 }
574 0 return $d->{fallback};
575 }
576  
577 12 ▶sub _eval_in_place {
Subroutine _eval_in_place: called CC=48 SCAR=73.6
578 12 my ($self, $n, $x, $bits) = @_;
579 12 my $c = $self->{c};
580 12 my $ok = 1;
581 12 ▶ if ($n->{ref} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"ref"} >= 0) 0 12 12
582 0 my ($m) = $self->_eval_in_place_child($n->{ref}, '$ref', $x, $bits, 1);
583 0 ▶ $c->evaluated_keyword($m, $m ? MATCHED_ALL : DID_NOT_MATCH_ALL, '$ref');
Branch: 1 branch
BranchTrueFalseTotal
$m ? : 0 0 0
584 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
585 }
586 12 ▶ if ($n->{static_dynamic_ref} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"static_dynamic_ref"} >= 0) 0 12 12
587 0 ▶ my $keyword = $n->{static_dynamic_keyword} // '$dynamicRef';
Condition0%0/2
$n->{"static_dynamic_keyword"} // "\$dynamicRef"
l!l
00
MC/DC0%0/1
$n->{"static_dynamic_keyword"} // "\$dynamicRef"
$n->{"static_dynamic_keyword"}
Truth table0%0/2
A
A= $n->{"static_dynamic_keyword"}
Aresult
11
00
588 0 my ($m) = $self->_eval_in_place_child($n->{static_dynamic_ref}, $keyword, $x, $bits, 1);
589 0 ▶ $c->evaluated_keyword($m, $m ? MATCHED_ALL : DID_NOT_MATCH_ALL, $keyword);
Branch: 1 branch
BranchTrueFalseTotal
$m ? : 0 0 0
590 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
591 }
592 12 ▶ if (my $d = $n->{dynamic_ref}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $n->{"dynamic_ref"}) 0 12 12
593 0 ▶ my $keyword = $d->{is_recursive} ? '$recursiveRef' : '$dynamicRef';
Branch: 1 branch
BranchTrueFalseTotal
$d->{'is_recursive'} ? : 0 0 0
594 # The resolved target is elided, with no hops in the path.
595 0 my ($target) = $self->_resolve($self->_resolve_dynamic($d));
596 0 my ($m) = $self->_eval_in_place_child($target, $keyword, $x, $bits, 1, 1);
597 0 ▶ $c->evaluated_keyword($m, $m ? MATCHED_ALL : DID_NOT_MATCH_ALL, $keyword);
Branch: 1 branch
BranchTrueFalseTotal
$m ? : 0 0 0
598 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
599 }
600 12 ▶ if ($n->{all_of}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"all_of"}) 0 12 12
601 0 my $all_ok = 1;
602 0 for my $i (0 .. $#{ $n->{all_of} }) {
603 0 my ($m) = $self->_eval_in_place_child($n->{all_of}[$i], "allOf/$i", $x, $bits, 1);
604 0 ▶ $all_ok = 0 unless $m;
Branch: 1 branch
BranchTrueFalseTotal
unless $m 0 0 0
605 }
606 0 ▶ $c->evaluated_keyword($all_ok, $all_ok ? MATCHED_ALL : DID_NOT_MATCH_ALL, 'allOf');
Branch: 1 branch
BranchTrueFalseTotal
$all_ok ? : 0 0 0
607 0 ▶ $ok &&= $all_ok;
Condition0%0/3
$ok &&= $all_ok
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $all_ok
$ok $all_ok
Truth table0%0/3
A &&= B
A= $okB= $all_ok
ABresult
0X0
100
111
608 }
609 12 ▶ if ($n->{any_of}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"any_of"}) 0 12 12
610 0 my $any_ok = 0;
611 0 for my $i (0 .. $#{ $n->{any_of} }) {
612 0 my ($m) = $self->_eval_in_place_child($n->{any_of}[$i], "anyOf/$i", $x, $bits, 0);
613 0 ▶ $any_ok = 1 if $m;
Branch: 1 branch
BranchTrueFalseTotal
if $m 0 0 0
614 }
615 0 ▶ $c->evaluated_keyword($any_ok, $any_ok ? MATCHED_AT_LEAST_ONE : DID_NOT_MATCH_AT_LEAST_ONE, 'anyOf');
Branch: 1 branch
BranchTrueFalseTotal
$any_ok ? : 0 0 0
616 0 ▶ $ok &&= $any_ok;
Condition0%0/3
$ok &&= $any_ok
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $any_ok
$ok $any_ok
Truth table0%0/3
A &&= B
A= $okB= $any_ok
ABresult
0X0
100
111
617 }
618 12 ▶ if ($n->{one_of}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"one_of"}) 0 12 12
619 0 my $matched = 0;
620 0 my $only;
621 0 for my $i (0 .. $#{ $n->{one_of} }) {
622 # Evaluated properties and items are merged only when exactly one branch matched, so they are collected aside.
623 0 ▶ my ($r_ok, $r_scratch) = $self->_eval_in_place_child($n->{one_of}[$i], "oneOf/$i", $x, $bits ? {} : undef, 0);
Branch: 1 branch
BranchTrueFalseTotal
$bits ? : 0 0 0
624 0 ▶ if ($r_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r_ok) 0 0 0
625 0 $matched++;
626 0 $only = $r_scratch;
627 }
628 }
629 0 ▶ @$bits{ keys %$only } = values %$only if $matched == 1 && $bits && $only;
Branch: 1 branch
BranchTrueFalseTotal
if $matched == 1 and $bits and $only 0 0 0
Condition0%0/6
$matched == 1 and $bits and $only
!ll&&!rl&&r
000
$matched == 1 and $bits
!ll&&!rl&&r
000
MC/DC0%0/3
$matched == 1 and $bits and $only
$matched == 1 $bits $only
Truth table0%0/4
A and B and C
A= $matched == 1B= $bitsC= $only
ABCresult
0XX0
10X0
1100
1111
630 0 ▶ my $message = $matched == 0 ? MATCHED_NO_SCHEMA : $matched == 1 ? MATCHED_EXACTLY_ONE : MATCHED_MORE_THAN_ONE;
Branch: 2 branches
BranchTrueFalseTotal
$matched == 0 ? : 0 0 0
$matched == 1 ? : 0 0 0
631 0 ▶ $c->evaluated_keyword($matched == 1 ? 1 : 0, $message, 'oneOf');
Branch: 1 branch
BranchTrueFalseTotal
$matched == 1 ? : 0 0 0
632 0 ▶ $ok &&= $matched == 1;
Condition0%0/3
$ok &&= $matched == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $matched == 1
$ok $matched == 1
Truth table0%0/3
A &&= B
A= $okB= $matched == 1
ABresult
0X0
100
111
633 }
634 12 ▶ if ($n->{not_} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"not_"} >= 0) 0 12 12
635 # Not elided, and never contributes results or evaluated properties or items.
636 0 $c->begin_child_context('not', $self->{nodes}[ $n->{not_} ]{pointer}, undef);
637 0 my $inner = $self->_eval_node($n->{not_}, $x, undef);
638 0 $c->pop_child_context;
639 0 ▶ $c->evaluated_keyword($inner ? 0 : 1, $inner ? MATCHED_NOT : DID_NOT_MATCH_NOT, 'not');
Branch: 2 branches
BranchTrueFalseTotal
$inner ? : 0 0 0
$inner ? : 0 0 0
640 0 ▶ $ok &&= !$inner;
Condition0%0/3
$ok &&= !$inner
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= !$inner
$ok !$inner
Truth table0%0/3
A &&= not(B)
A= $okB= !$inner
ABresult
0X0
100
111
641 }
642 12 ▶ if ($n->{if_} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"if_"} >= 0) 0 12 12
643 0 my ($cond) = $self->_eval_in_place_child($n->{if_}, 'if', $x, $bits, 0);
644 0 ▶ $c->evaluated_keyword(1, $cond ? MATCHED_IF_FOR_THEN : MATCHED_IF_FOR_ELSE, 'if');
Branch: 1 branch
BranchTrueFalseTotal
$cond ? : 0 0 0
645 0 ▶ if ($cond && $n->{then} >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cond and $n->{'then'} >= 0) { } 0 0 0
elsif (not $cond and $n->{'else_'} >= 0) { } 0 0 0
Condition0%0/3
$cond and $n->{"then"} >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$cond and $n->{"then"} >= 0
$cond $n->{"then"} >= 0
Truth table0%0/3
A and B
A= $condB= $n->{"then"} >= 0
ABresult
0X0
100
111
646 0 my ($m) = $self->_eval_in_place_child($n->{then}, 'then', $x, $bits, 1);
647 0 ▶ $c->evaluated_keyword($m, $m ? MATCHED_THEN : DID_NOT_MATCH_THEN, 'then');
Branch: 1 branch
BranchTrueFalseTotal
$m ? : 0 0 0
648 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
649 }
650 ▶ elsif (!$cond && $n->{else_} >= 0) {
Condition0%0/3
not $cond and $n->{"else_"} >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
not $cond and $n->{"else_"} >= 0
not $cond $n->{"else_"} >= 0
Truth table0%0/3
not(A) and B
A= not $condB= $n->{"else_"} >= 0
ABresult
0X0
100
111
651 0 my ($m) = $self->_eval_in_place_child($n->{else_}, 'else', $x, $bits, 1);
652 0 ▶ $c->evaluated_keyword($m, $m ? MATCHED_ELSE : DID_NOT_MATCH_ELSE, 'else');
Branch: 1 branch
BranchTrueFalseTotal
$m ? : 0 0 0
653 0 ▶ $ok &&= $m;
Condition0%0/3
$ok &&= $m
!ll&&!rl&&r
000
MC/DC0%0/2
$ok &&= $m
$ok $m
Truth table0%0/3
A &&= B
A= $okB= $m
ABresult
0X0
100
111
654 }
655 }
656 12 ▶ return $ok ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 12 0 12
657 }
658  
659 0 ▶sub _dependency_message {
Subroutine _dependency_message: not called CC=1 SCAR=6.9
660 0 my ($name) = @_;
661 0 ▶ return sub { "The value did match the schema applied because it contained the property '$name'" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
662 }
663  
664 3 ▶sub _required_message {
Subroutine _required_message: called CC=1 SCAR=0.0
665 3 my ($present, $name) = @_;
666 3 ▶ return sub { 'Required property ' . ($present ? '' : 'not ') . "present '$name'" };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$present ? : 1 1 2
667 }
668  
669 4 1;
« Corvus/Regex/Vm.pm ↑ Summary Corvus/Regex/Linear.pm »