Branch Coverage

blib/lib/JSON/Schema/Tiny.pm
Criterion Covered Total %
branch 511 564 90.6


line true false branch
56 0 12777 unless defined wantarray
64 12610 167 if builtin::blessed($_[0]) and builtin::blessed($_[0])->isa(__PACKAGE__)
68 12631 146 if (defined $SPECIFICATION_VERSION)
70 3 12628 if not $SPECIFICATION_VERSION =~ /^draft/u and &any(sub { 'draft' . $SPECIFICATION_VERSION eq $_; } , values %version_uris)
72 1 12630 if &none(sub { $SPECIFICATION_VERSION eq $_; } , values %version_uris)
75 0 12776 if @_ < 2
96 1674 1 if (Ref::Util::XS::is_plain_hashref($e)) { }
106 0 6506 unless $valid or @{$$state{"errors"}}
110 6266 6496 $valid ? :
6266 6496 $valid ? :
14 12762 $BOOLEAN_RESULT ? :
137 0 21636 unless defined wantarray
145 3 21633 if $$state{"depth"}++ > $MAX_TRAVERSAL_DEPTH
148 751 20882 if $schema_type eq "boolean"
149 19 20863 if $schema_type ne "object"
151 359 20504 unless keys %$schema
161 2 20502 if grep((substr($schema_location, 0, length $_) eq $_), keys %{$$state{"seen"}{$$state{"data_path"}}{$canonical_uri}})
168 15413 5089 !$spec_version || $spec_version ne 'draft7' ? :
7950 12552 !$spec_version || $spec_version eq 'draft2019-09' ? :
7795 12707 !$spec_version || $spec_version eq 'draft2020-12' ? :
7950 12552 !$spec_version || $spec_version eq 'draft2019-09' ? :
7795 12707 !$spec_version || $spec_version eq 'draft2020-12' ? :
15413 5089 !$spec_version || $spec_version ne 'draft7' ? :
5421 15081 !$spec_version || $spec_version eq 'draft7' ? :
15413 5089 !$spec_version || $spec_version ne 'draft7' ? :
15413 5089 !$spec_version || $spec_version ne 'draft7' ? :
5421 15081 !$spec_version || $spec_version eq 'draft7' ? :
7795 12707 !($spec_version && $spec_version =~ qr/^draft(?:7|2019-09)$/u) ? :
13039 7463 !$spec_version || $spec_version =~ qr/^draft(?:7|2019-09)$/u ? :
15413 5089 !$spec_version || $spec_version ne 'draft7' ? :
15413 5089 !$spec_version || $spec_version ne 'draft7' ? :
15413 5089 !$spec_version || $spec_version ne 'draft7' ? :
200 686002 34296 unless exists $$schema{$keyword}
204 15 32444 if $keyword ne "\$ref" and $keyword ne "definitions" and exists $$schema{"\$ref"} and $spec_version eq "draft7"
210 7501 24181 unless (&$sub($data, $schema, $state))
212 0 7501 if $error_count == @{$$state{"errors"}}
216 3656 28026 if not $valid and $$state{"short_circuit"}
221 62422 214 unless exists $$schema{$keyword}
224 214 0 if (my $alternates = $removed_keywords{$spec_version}{$keyword})
226 0 214 if @list > 2
227 162 52 if @list > 1
243 1 5643 if length $$state{"schema_path"}
246 29 5614 unless $spec_version
250 1 5613 if defined $SPECIFICATION_VERSION and $SPECIFICATION_VERSION ne $spec_version
255 1 5612 if exists $$schema{"\$ref"} and $spec_version eq "draft7"
266 98 1601 unless ($uri->fragment // "") =~ m[^(?:/(?:[^~]|~[01])*)?$]u
272 469 1132 if $uri->clone->fragment(undef) ne "Mojo::URL"->new($$state{"root_schema"}{"\$id"} // "")
275 5 1127 unless defined $subschema
290 0 52 unless ($uri->fragment // "") =~ m[^(?:/(?:[^~]|~[01])*)?$]u
297 44 8 if $uri->clone->fragment(undef) ne "Mojo::URL"->new($$state{"root_schema"}{"\$id"} // "")
300 0 8 unless defined $subschema
302 0 8 if (is_type("boolean", $$subschema{"\$recursiveAnchor"}) and $$subschema{"\$recursiveAnchor"})
306 0 0 unless defined $subschema
325 133 537 if (($$state{'spec_version'} // '') eq 'draft7') { }
326 3 130 if (length $uri->fragment)
327 0 3 if length $uri->clone->fragment(undef)
330 1 2 unless $uri->fragment =~ /^[A-Za-z][A-Za-z0-9_:.-]*$/u
337 2 535 if length $uri->fragment
341 24 641 unless length $uri
343 540 101 $uri->is_abs ? :
358 12 0 if !$$state{'spec_version'} || $$state{'spec_version'} eq 'draft2019-09' and ($$schema{"\$anchor"} // "") =~ /^[A-Za-z][A-Za-z0-9_:.-]*$/u or !$$state{'spec_version'} || $$state{'spec_version'} eq 'draft2020-12' and ($$schema{"\$anchor"} // "") =~ /^[A-Za-z_][A-Za-z0-9._-]*$/u
365 41 51 if not $$schema{"\$recursiveAnchor"} or exists $$state{"recursive_anchor_uri"}
370 0 51 unless exists $$schema{"\$id"}
380 0 10 unless assert_keyword_type($state, $schema, "string")
383 0 10 unless $$schema{"\$dynamicAnchor"} =~ /^[A-Za-z_][A-Za-z0-9._-]*$/u
392 0 4 unless is_type("boolean", $$schema{"\$vocabulary"}{$uri})
398 0 4 if length $$state{"schema_path"}
401 0 4 if length $$state{"traversed_schema_path"} . $$state{"schema_path"}
419 163 3543 if (Ref::Util::XS::is_plain_arrayref($$schema{'type'})) { }
420 0 163 unless @{$$schema{"type"}}
423 6 338 unless &any(sub { ($type // "") eq $_; } , "null", "boolean", "object", "array", "string", "number", "integer")
425 0 157 unless is_elements_unique($$schema{"type"})
429 229 0 unless $type eq $_ or $_ eq "number" and $type eq "integer" or $type eq "string" and $STRINGY_NUMBERS and &looks_like_number($data) and $_ eq 'number' || $_ eq 'integer' && $data == int $data
433 65 92 if &any(sub { $_ eq "boolean" and $SCALARREF_BOOLEANS and $type eq "reference to SCALAR" unless $type eq $_ or $_ eq "number" and $type eq "integer" or $type eq "string" and $STRINGY_NUMBERS and &looks_like_number($data) and $_ eq 'number' || $_ eq 'integer' && $data == int $data; } , @{$$schema{"type"}})
439 2 3535 unless &any(sub { ($$schema{"type"} // "") eq $_; } , "null", "boolean", "object", "array", "string", "number", "integer")
445 2 113 if $type eq $$schema{"type"} or $$schema{"type"} eq "number" and $type eq "integer" or $type eq "string" and $STRINGY_NUMBERS and &looks_like_number($data) and $$schema{'type'} eq 'number' || $$schema{'type'} eq 'integer' && $data == int $data or $$schema{"type"} eq "boolean" and $SCALARREF_BOOLEANS and $type eq "reference to SCALAR"
454 264 219 if &any(sub { is_equal($data, $_, $s[$idx++] = {}); } , @{$$schema{"enum"}})
457 176 43 !grep($our $_{'path'}, @s) ? :
462 576 479 if is_equal($data, $$schema{"const"}, scalar(my $s = {}))
463 55 424 $$s{'path'} ? :
468 0 830 if $$schema{"multipleOf"} <= 0
472 0 2 unless is_type("number", $data) or $STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data) and do { $data = 0 + $data; 1 }
475 52 588 if (is_bignum($data) or is_bignum($$schema{'multipleOf'}) or get_type($data) eq 'number' or get_type($$schema{'multipleOf'}) eq 'number') { }
477 30 22 is_bignum($data) ? :
478 48 4 is_bignum($$schema{'multipleOf'}) ? :
480 0 52 if $quotient->is_inf
481 30 22 if $remainder == 0
485 588 0 "$]" >= 5.022 ? :
0 588 if "$]" >= "5.022" ? isinf($quotient) : $quotient =~ /^-?Inf$/iu
487 313 275 if int $quotient == $quotient
495 0 1 unless is_type("number", $data) or $STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
497 216 172 if 0 + $data <= $$schema{"maximum"}
503 0 1 unless is_type("number", $data) or $STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
505 138 154 if 0 + $data < $$schema{"exclusiveMaximum"}
511 0 1 unless is_type("number", $data) or $STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
513 265 242 if 0 + $data >= $$schema{"minimum"}
519 0 1 unless is_type("number", $data) or $STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
521 108 124 if 0 + $data > $$schema{"exclusiveMinimum"}
528 209 352 unless is_type("string", $data)
529 190 162 if length $data <= $$schema{"maxLength"}
536 210 302 unless is_type("string", $data)
537 160 142 if length $data >= $$schema{"minLength"}
545 227 671 unless is_type("string", $data)
546 357 313 if $data =~ /(?:$$schema{"pattern"})/u
553 169 256 unless is_type("array", $data)
554 134 122 if @$data <= $$schema{"maxItems"}
555 22 100 $$schema{'maxItems'} > 1 ? :
561 167 257 unless is_type("array", $data)
562 133 124 if @$data >= $$schema{"minItems"}
563 112 12 $$schema{'minItems'} > 1 ? :
568 161 614 unless is_type("array", $data)
569 165 449 unless $$schema{"uniqueItems"}
570 242 207 if is_elements_unique($data, scalar(my $equal_indices = []))
576 8 76 unless exists $$state{"_num_contains"}
577 0 76 unless is_type("array", $data)
580 32 44 if $$state{"_num_contains"} > $$schema{"maxContains"}
587 8 94 unless exists $$state{"_num_contains"}
588 0 94 unless is_type("array", $data)
591 34 60 if $$state{"_num_contains"} < $$schema{"minContains"}
599 138 202 unless is_type("object", $data)
600 104 98 if keys %$data <= $$schema{"maxProperties"}
602 12 86 $$schema{'maxProperties'} > 1 ? :
608 138 202 unless is_type("object", $data)
609 104 98 if keys %$data >= $$schema{"minProperties"}
611 6 92 $$schema{'minProperties'} > 1 ? :
617 0 1414 if &any(sub { not is_type("string", $_); } , @{$$schema{"required"}})
618 0 1414 unless is_elements_unique($$schema{"required"})
620 150 1264 unless is_type("object", $data)
623 698 566 unless @missing
624 36 530 @missing > 1 ? :
632 0 287 unless is_type("array", $$schema{"dependentRequired"}{$property})
636 1 300 unless is_type("string", $$schema{"dependentRequired"}{$property}[$index])
640 0 286 unless is_elements_unique($$schema{"dependentRequired"}{$property})
643 97 173 unless is_type("object", $data)
647 36 153 unless exists $$data{$property}
649 79 74 if (my(@missing) = grep((!exists($$data{$_})), @{$$schema{"dependentRequired"}{$property}}))
650 5 74 @missing > 1 ? :
655 94 79 if $valid
665 463 209 if _eval_subschema($data, $$schema{"allOf"}[$idx], {%$state, "schema_path", $$state{"schema_path"} . '/allOf/' . $idx})
668 71 138 if $$state{"short_circuit"}
671 235 169 if @invalid == 0
674 36 133 $pl ? :
36 133 $pl ? :
684 382 239 unless _eval_subschema($data, $$schema{"anyOf"}[$idx], {%$state, "errors", \@errors, "schema_path", $$state{"schema_path"} . '/anyOf/' . $idx})
686 98 141 if $$state{"short_circuit"}
689 202 92 if $valid
700 533 377 unless _eval_subschema($data, $$schema{"oneOf"}[$idx], {%$state, "errors", \@errors, "schema_path", $$state{"schema_path"} . '/oneOf/' . $idx})
702 44 333 if @valid > 1 and $$state{"short_circuit"}
705 157 201 if @valid == 1
707 123 78 if (not @valid) { }
717 112 181 if is_type("boolean", $$schema{"not"})
720 38 135 unless _eval_subschema($data, $$schema{"not"}, {%$state, "schema_path", $$state{"schema_path"} . '/not', "short_circuit", 1, "errors", []})
726 44 52 unless exists $$schema{"then"} or exists $$schema{"else"}
728 138 144 _eval_subschema($data, $$schema{'if'}, {%$state, 'schema_path', $$state{'schema_path'} . '/if', 'short_circuit', 1, 'errors', []}) ? :
731 58 224 unless exists $$schema{$keyword}
734 32 192 if is_type("boolean", $$schema{$keyword})
737 108 62 if _eval_subschema($data, $$schema{$keyword}, {%$state, "schema_path", $$state{"schema_path"} . '/' . $keyword})
744 124 213 unless is_type("object", $data)
750 166 97 if not exists $$data{$property} or _eval_subschema($data, $$schema{"dependentSchemas"}{$property}, {%$state, "schema_path", jsonp($$state{"schema_path"}, "dependentSchemas", $property)})
753 48 49 if $$state{"short_circuit"}
756 97 116 unless $valid
763 67 119 unless is_type("object", $data)
767 52 114 if (is_type('array', $$schema{'dependencies'}{$property})) { }
772 0 62 unless is_type("string", $$schema{"dependencies"}{$property}[$index])
776 0 52 unless is_elements_unique($$schema{"dependencies"}{$property})
778 28 24 unless exists $$data{$property}
780 14 10 if (my(@missing) = grep((!exists($$data{$_})), @{$$schema{"dependencies"}{$property}}))
781 3 11 @missing > 1 ? :
789 67 47 if not exists $$data{$property} or _eval_subschema($data, $$schema{"dependencies"}{$property}, {%$state, "schema_path", jsonp($$state{"schema_path"}, "dependencies", $property)})
792 23 24 if $$state{"short_circuit"}
796 60 59 if $valid
801 0 411 unless assert_array_schemas($schema, $state)
806 700 604 if (Ref::Util::XS::is_plain_arrayref($$schema{"items"}))
808 1 699 if ($$state{"spec_version"} // "") eq "draft2020-12"
818 28 191 unless exists $$state{"_last_items_index"}
824 0 1110 unless @{$$schema{$$state{"keyword"}}}
825 213 897 unless is_type("array", $data)
830 287 1294 if $idx > $$schema{$$state{"keyword"}}->$#*
833 286 1008 if (is_type('boolean', $$schema{$$state{'keyword'}}[$idx])) { }
834 178 108 if $$schema{$$state{"keyword"}}[$idx]
841 941 67 if _eval_subschema($$data[$idx], $$schema{$$state{"keyword"}}[$idx], {%$state, "data_path", $$state{"data_path"} . '/' . $idx, "schema_path", $$state{"schema_path"} . '/' . $$state{"keyword"} . '/' . $idx})
847 56 0 $$state{'keyword'} eq 'items' ? :
31 56 $$state{'keyword'} eq 'prefixItems' ? :
75 100 if $$state{"short_circuit"} and not exists $$schema{$$state{"keyword"} eq "prefixItems" ? "items" : ($$state{"keyword"} eq "items" ? "additionalItems" : die())}
851 172 725 unless $valid
857 104 691 unless is_type("array", $data)
858 244 447 if $$state{"_last_items_index"} == $data->$#*
862 32 644 if (is_type('boolean', $$schema{$$state{'keyword'}}) and $$state{'keyword'} eq 'additionalItems') { }
864 6 26 if $$schema{$$state{"keyword"}}
867 26 0 exists $$schema{'prefixItems'} || $$state{'keyword'} eq 'additionalItems' ? :
872 360 219 if _eval_subschema($$data[$idx], $$schema{$$state{"keyword"}}, {%$state, "data_path", $$state{"data_path"} . '/' . $idx, "schema_path", $$state{"schema_path"} . '/' . $$state{"keyword"}})
876 90 155 if $$state{"short_circuit"}
882 59 144 exists $$schema{'prefixItems'} || $$state{'keyword'} eq 'additionalItems' ? :
203 179 unless $valid
888 213 504 unless is_type("array", $data)
893 390 232 if (_eval_subschema($$data[$idx], $$schema{"contains"}, {%$state, "errors", \@errors, "data_path", $$state{"data_path"} . '/' . $idx, "schema_path", $$state{"schema_path"} . '/contains'}))
901 126 60 if $$state{"short_circuit"} and !exists($$schema{'maxContains'}) || $$state{'_num_contains'} > $$schema{'maxContains'} and $$state{"_num_contains"} >= ($$schema{"minContains"} // 1)
906 195 16 if (not $$state{"_num_contains"} and ($$schema{'minContains'} // 1) > 0 || $$state{'spec_version'} && $$state{'spec_version'} eq 'draft7')
917 251 2150 unless is_type("object", $data)
921 1044 1670 unless exists $$data{$property}
923 323 1347 if (is_type('boolean', $$schema{'properties'}{$property})) { }
924 217 106 if $$schema{"properties"}{$property}
932 863 329 if _eval_subschema($$data{$property}, $$schema{"properties"}{$property}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "schema_path", jsonp($$state{"schema_path"}, "properties", $property)})
936 210 225 if $$state{"short_circuit"}
939 413 1582 unless $valid
950 193 614 unless is_type("object", $data)
955 319 238 if (is_type('boolean', $$schema{'patternProperties'}{$property_pattern})) { }
956 211 108 if $$schema{"patternProperties"}{$property_pattern}
964 151 87 if _eval_subschema($$data{$property}, $$schema{"patternProperties"}{$property_pattern}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "schema_path", jsonp($$state{"schema_path"}, "patternProperties", $property_pattern)})
968 92 103 if $$state{"short_circuit"}
972 180 434 unless $valid
977 199 556 unless is_type("object", $data)
981 114 438 if exists $$schema{"properties"} and exists $$schema{"properties"}{$property}
983 88 350 if exists $$schema{"patternProperties"} and &any(sub { $property =~ /(?:$_)/u; } , keys %{$$schema{"patternProperties"}})
985 192 158 if (is_type('boolean', $$schema{'additionalProperties'})) { }
986 20 172 if $$schema{"additionalProperties"}
995 63 43 if _eval_subschema($$data{$property}, $$schema{"additionalProperties"}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "schema_path", $$state{"schema_path"} . '/additionalProperties'})
999 105 110 if $$state{"short_circuit"}
1002 214 290 unless $valid
1007 175 288 unless is_type("object", $data)
1014 86 116 if _eval_subschema($property, $$schema{"propertyNames"}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "schema_path", $$state{"schema_path"} . '/propertyNames'})
1017 60 56 if $$state{"short_circuit"}
1020 116 172 unless $valid
1040 83 52811 if ($type eq "null")
1043 6022 46789 if ($type eq "boolean")
1046 12088 34701 if ($type eq "object")
1049 8790 25911 if ($type eq "array")
1053 9036 16 if ($type eq "string" or $type eq "number" or $type eq "integer")
1054 18 25877 unless defined $value
1062 16845 9032 if ($type eq "string")
1070 6143 2889 if ($type eq "number")
1075 2889 0 if ($type eq "integer")
1084 11 5 if ($type =~ /^reference to (.+)$/u)
1095 22047 13041 if Ref::Util::XS::is_plain_hashref($value)
1096 1979 11062 if is_bool($value)
1097 298 10764 unless defined $value
1098 1283 9481 if Ref::Util::XS::is_plain_arrayref($value)
1101 455 9026 if (Ref::Util::XS::is_ref($value))
1103 195 81 $value->is_int ? :
4 70 defined builtin::blessed($value) ? :
276 74 $ref eq 'Math::BigFloat' ? :
105 350 $ref eq 'Math::BigInt' ? :
1120 4639 15 if $flags & 1024 and !($flags & 768) || do { BEGIN {${^WARNING_BITS} = "\xdd\x7f\xf7\xc3\xd7\xff\xf5\xff\xff\xff\xff\xff\xf5\xd7\xf4\xd7\x15\x50\x55\x55\x55\x55"} 0 + $value eq $value }
1124 4355 17 int $value == $value ? :
4372 15 if &created_as_number($value)
1137 19063 0 unless builtin::is_bool($value)
1162 3 4168 if grep(($types[$_] eq "ambiguous type"), (0, 1))
1165 99 4069 if ($SCALARREF_BOOLEANS)
1166 14 85 if $types[0] eq "reference to SCALAR"
1167 18 81 if $types[1] eq "reference to SCALAR"
1170 18 4150 if ($STRINGY_NUMBERS)
1171 5 3 int 0 + $x == $x ? :
8 10 if $types[0] eq "string" and &looks_like_number($x)
1174 4 1 int 0 + $y == $y ? :
5 13 if $types[1] eq "string" and &looks_like_number($y)
1178 843 3325 if $types[0] ne $types[1]
1179 14 3311 if $types[0] eq "null"
1180 1533 1778 if $types[0] eq "string"
1182 1155 623 if grep(($types[0] eq $_), ("boolean", "number", "integer"))
1186 217 406 if ($types[0] eq "object")
1187 17 200 if keys %$x != keys %$y
1190 7 193 unless (is_equal(my $arr_x = [sort(keys %$x)], my $arr_y = [sort(keys %$y)], scalar(my $s = {})))
1198 87 144 unless is_equal($$x{$property}, $$y{$property}, $state)
1204 406 0 if ($types[0] eq "array")
1205 9 397 if @$x != @$y
1208 128 313 unless is_equal($$x[$idx], $$y[$idx], $state)
1225 207 1044 if (is_equal($$array[$idx0], $$array[$idx1]))
1226 207 0 if defined $equal_indices
1245 14011 6758 unless @extra_path or length $$state{"schema_path"}
1247 9843 6758 @extra_path ? :
1248 78 16523 unless length $fragment
1258 1 9842 defined $sps && Ref::Util::XS::is_plain_arrayref($sps) ? :
1265 8516 1327 if $uri eq "" and $keyword_location eq "" or ($uri->fragment // "") eq $keyword_location and $uri->clone->fragment(undef) eq ""
1270 1327 8516 defined $uri ? :
4726 5117 @args ? :
1288 28000 18 if is_type($type, $$schema{$$state{"keyword"}})
1289 2 16 $type =~ /^[aeiou]/u ? :
1306 0 1229 if fc "Mojo::URL"->new($string)->to_unsafe_string ne fc $string or $string =~ /[^[:ascii:]]/u or $string =~ /#/u and not $string =~ /#$/u and not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u and not $string =~ m[#/(?:[^~]|~[01])*$]u
1321 0 0 if fc $uri->to_unsafe_string ne fc $string or $string =~ /[^[:ascii:]]/u or not $uri->is_abs or $string =~ /#/u and not $string =~ /#$/u and not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u and not $string =~ m[#/(?:[^~]|~[01])*$]u
1337 0 2788 if $$schema{$$state{"keyword"}} < 0
1343 0 1928 unless @{$$schema{$$state{"keyword"}}}
1350 66 923 is_bignum($value) ? :