Branch Coverage

blib/lib/JSON/Schema/Tiny.pm
Criterion Covered Total %
branch 512 564 90.7


line true false branch
55 0 12777 unless defined wantarray
63 12610 167 if builtin::blessed($_[0]) and builtin::blessed($_[0])->isa(__PACKAGE__)
67 12631 146 if (defined $SPECIFICATION_VERSION)
69 3 12628 if not $SPECIFICATION_VERSION =~ /^draft/u and CORE::any {'draft' . $SPECIFICATION_VERSION eq $_;} values %version_uris
71 1 12630 unless CORE::any {$SPECIFICATION_VERSION eq $_;} values %version_uris
74 0 12776 if @_ < 2
95 1674 1 if (ref $e eq 'HASH') { }
105 0 6506 unless $valid or @{$$state{"errors"}}
109 6266 6496 $valid ? :
6266 6496 $valid ? :
14 12762 $BOOLEAN_RESULT ? :
136 0 21636 unless defined wantarray
144 3 21633 if $$state{"depth"}++ > $MAX_TRAVERSAL_DEPTH
147 751 20882 if $schema_type eq "boolean"
148 19 20863 if $schema_type ne "object"
150 359 20504 unless keys %$schema
160 2 20502 if grep((substr($schema_location, 0, length $_) eq $_), keys %{$$state{"seen"}{$$state{"data_path"}}{$canonical_uri}})
167 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' ? :
199 686002 34296 unless exists $$schema{$keyword}
203 15 32444 if $keyword ne "\$ref" and $keyword ne "definitions" and exists $$schema{"\$ref"} and $spec_version eq "draft7"
209 7501 24181 unless (&$sub($data, $schema, $state))
211 0 7501 if $error_count == @{$$state{"errors"}}
215 3656 28026 if not $valid and $$state{"short_circuit"}
220 62422 214 unless exists $$schema{$keyword}
223 214 0 if (my $alternates = $removed_keywords{$spec_version}{$keyword})
225 0 214 if @list > 2
226 162 52 if @list > 1
242 1 5643 if length $$state{"schema_path"}
245 29 5614 unless $spec_version
249 1 5613 if defined $SPECIFICATION_VERSION and $SPECIFICATION_VERSION ne $spec_version
254 1 5612 if exists $$schema{"\$ref"} and $spec_version eq "draft7"
265 98 1601 unless ($uri->fragment // "") =~ m[^(?:/(?:[^~]|~[01])*)?$]u
271 469 1132 if $uri->clone->fragment(undef) ne "Mojo::URL"->new($$state{"root_schema"}{"\$id"} // "")
274 5 1127 unless defined $subschema
289 0 52 unless ($uri->fragment // "") =~ m[^(?:/(?:[^~]|~[01])*)?$]u
296 44 8 if $uri->clone->fragment(undef) ne "Mojo::URL"->new($$state{"root_schema"}{"\$id"} // "")
299 0 8 unless defined $subschema
301 0 8 if (is_type("boolean", $$subschema{"\$recursiveAnchor"}) and $$subschema{"\$recursiveAnchor"})
305 0 0 unless defined $subschema
324 133 537 if (($$state{'spec_version'} // '') eq 'draft7') { }
325 3 130 if (length $uri->fragment)
326 0 3 if length $uri->clone->fragment(undef)
329 1 2 unless $uri->fragment =~ /^[A-Za-z][A-Za-z0-9_:.-]*$/u
336 2 535 if length $uri->fragment
340 24 641 unless length $uri
342 540 101 $uri->is_abs ? :
357 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
364 41 51 if not $$schema{"\$recursiveAnchor"} or exists $$state{"recursive_anchor_uri"}
369 0 51 unless exists $$schema{"\$id"}
379 0 10 unless assert_keyword_type($state, $schema, "string")
382 0 10 unless $$schema{"\$dynamicAnchor"} =~ /^[A-Za-z_][A-Za-z0-9._-]*$/u
391 0 4 unless is_type("boolean", $$schema{"\$vocabulary"}{$uri})
397 0 4 if length $$state{"schema_path"}
400 0 4 if length $$state{"traversed_schema_path"} . $$state{"schema_path"}
418 163 3543 if (ref $$schema{'type'} eq 'ARRAY') { }
419 0 163 unless @{$$schema{"type"}}
422 6 338 unless CORE::any {($type // "") eq $_;} "null", "boolean", "object", "array", "string", "number", "integer"
424 0 157 unless is_elements_unique($$schema{"type"})
428 229 63 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
432 65 92 if CORE::any {$_ 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"}}
438 2 3535 unless CORE::any {($$schema{"type"} // "") eq $_;} "null", "boolean", "object", "array", "string", "number", "integer"
444 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"
453 264 219 if CORE::any {is_equal($data, $_, $s[$idx++] = {});} @{$$schema{"enum"}}
456 176 43 !grep($our $_{'path'}, @s) ? :
461 576 479 if is_equal($data, $$schema{"const"}, scalar(my $s = {}))
462 55 424 $$s{'path'} ? :
467 0 830 if $$schema{"multipleOf"} <= 0
471 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 }
474 52 588 if (is_bignum($data) or is_bignum($$schema{'multipleOf'}) or get_type($data) eq 'number' or get_type($$schema{'multipleOf'}) eq 'number') { }
476 30 22 is_bignum($data) ? :
477 48 4 is_bignum($$schema{'multipleOf'}) ? :
479 0 52 if $quotient->is_inf
480 30 22 if $remainder == 0
484 588 0 "$]" >= 5.022 ? :
0 588 if "$]" >= "5.022" ? isinf($quotient) : $quotient =~ /^-?Inf$/iu
486 313 275 if int $quotient == $quotient
494 0 1 unless is_type("number", $data) or $STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
496 216 172 if 0 + $data <= $$schema{"maximum"}
502 0 1 unless is_type("number", $data) or $STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
504 138 154 if 0 + $data < $$schema{"exclusiveMaximum"}
510 0 1 unless is_type("number", $data) or $STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
512 265 242 if 0 + $data >= $$schema{"minimum"}
518 0 1 unless is_type("number", $data) or $STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
520 108 124 if 0 + $data > $$schema{"exclusiveMinimum"}
527 209 352 unless is_type("string", $data)
528 190 162 if length $data <= $$schema{"maxLength"}
535 210 302 unless is_type("string", $data)
536 160 142 if length $data >= $$schema{"minLength"}
544 227 671 unless is_type("string", $data)
545 357 313 if $data =~ /(?:$$schema{"pattern"})/u
552 169 256 unless is_type("array", $data)
553 134 122 if @$data <= $$schema{"maxItems"}
554 22 100 $$schema{'maxItems'} > 1 ? :
560 167 257 unless is_type("array", $data)
561 133 124 if @$data >= $$schema{"minItems"}
562 112 12 $$schema{'minItems'} > 1 ? :
567 161 614 unless is_type("array", $data)
568 165 449 unless $$schema{"uniqueItems"}
569 242 207 if is_elements_unique($data, scalar(my $equal_indices = []))
575 8 76 unless exists $$state{"_num_contains"}
576 0 76 unless is_type("array", $data)
579 32 44 if $$state{"_num_contains"} > $$schema{"maxContains"}
586 8 94 unless exists $$state{"_num_contains"}
587 0 94 unless is_type("array", $data)
590 34 60 if $$state{"_num_contains"} < $$schema{"minContains"}
598 138 202 unless is_type("object", $data)
599 104 98 if keys %$data <= $$schema{"maxProperties"}
601 12 86 $$schema{'maxProperties'} > 1 ? :
607 138 202 unless is_type("object", $data)
608 104 98 if keys %$data >= $$schema{"minProperties"}
610 6 92 $$schema{'minProperties'} > 1 ? :
616 0 1414 if CORE::any {not is_type("string", $_);} @{$$schema{"required"}}
617 0 1414 unless is_elements_unique($$schema{"required"})
619 150 1264 unless is_type("object", $data)
622 698 566 unless @missing
623 36 530 @missing > 1 ? :
631 0 287 unless is_type("array", $$schema{"dependentRequired"}{$property})
635 1 300 unless is_type("string", $$schema{"dependentRequired"}{$property}[$index])
639 0 286 unless is_elements_unique($$schema{"dependentRequired"}{$property})
642 97 173 unless is_type("object", $data)
646 36 153 unless exists $$data{$property}
648 79 74 if (my(@missing) = grep((!exists($$data{$_})), @{$$schema{"dependentRequired"}{$property}}))
649 5 74 @missing > 1 ? :
654 94 79 if $valid
664 463 209 if _eval_subschema($data, $$schema{"allOf"}[$idx], {%$state, "schema_path", $$state{"schema_path"} . '/allOf/' . $idx})
667 71 138 if $$state{"short_circuit"}
670 235 169 if @invalid == 0
673 36 133 $pl ? :
36 133 $pl ? :
683 382 239 unless _eval_subschema($data, $$schema{"anyOf"}[$idx], {%$state, "errors", \@errors, "schema_path", $$state{"schema_path"} . '/anyOf/' . $idx})
685 98 141 if $$state{"short_circuit"}
688 202 92 if $valid
699 533 377 unless _eval_subschema($data, $$schema{"oneOf"}[$idx], {%$state, "errors", \@errors, "schema_path", $$state{"schema_path"} . '/oneOf/' . $idx})
701 44 333 if @valid > 1 and $$state{"short_circuit"}
704 157 201 if @valid == 1
706 123 78 if (not @valid) { }
716 112 181 if is_type("boolean", $$schema{"not"})
719 38 135 unless _eval_subschema($data, $$schema{"not"}, {%$state, "schema_path", $$state{"schema_path"} . '/not', "short_circuit", 1, "errors", []})
725 44 52 unless exists $$schema{"then"} or exists $$schema{"else"}
727 138 144 _eval_subschema($data, $$schema{'if'}, {%$state, 'schema_path', $$state{'schema_path'} . '/if', 'short_circuit', 1, 'errors', []}) ? :
730 58 224 unless exists $$schema{$keyword}
733 32 192 if is_type("boolean", $$schema{$keyword})
736 108 62 if _eval_subschema($data, $$schema{$keyword}, {%$state, "schema_path", $$state{"schema_path"} . '/' . $keyword})
743 124 213 unless is_type("object", $data)
749 166 97 if not exists $$data{$property} or _eval_subschema($data, $$schema{"dependentSchemas"}{$property}, {%$state, "schema_path", jsonp($$state{"schema_path"}, "dependentSchemas", $property)})
752 48 49 if $$state{"short_circuit"}
755 97 116 unless $valid
762 67 119 unless is_type("object", $data)
766 52 114 if (is_type('array', $$schema{'dependencies'}{$property})) { }
771 0 62 unless is_type("string", $$schema{"dependencies"}{$property}[$index])
775 0 52 unless is_elements_unique($$schema{"dependencies"}{$property})
777 28 24 unless exists $$data{$property}
779 14 10 if (my(@missing) = grep((!exists($$data{$_})), @{$$schema{"dependencies"}{$property}}))
780 3 11 @missing > 1 ? :
788 67 47 if not exists $$data{$property} or _eval_subschema($data, $$schema{"dependencies"}{$property}, {%$state, "schema_path", jsonp($$state{"schema_path"}, "dependencies", $property)})
791 23 24 if $$state{"short_circuit"}
795 60 59 if $valid
800 0 411 unless assert_array_schemas($schema, $state)
805 700 604 if (ref $$schema{"items"} eq "ARRAY")
807 1 699 if ($$state{"spec_version"} // "") eq "draft2020-12"
817 28 191 unless exists $$state{"_last_items_index"}
823 0 1110 unless @{$$schema{$$state{"keyword"}}}
824 213 897 unless is_type("array", $data)
829 287 1294 if $idx > $$schema{$$state{"keyword"}}->$#*
832 286 1008 if (is_type('boolean', $$schema{$$state{'keyword'}}[$idx])) { }
833 178 108 if $$schema{$$state{"keyword"}}[$idx]
840 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})
846 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())}
850 172 725 unless $valid
856 104 691 unless is_type("array", $data)
857 244 447 if $$state{"_last_items_index"} == $data->$#*
861 32 644 if (is_type('boolean', $$schema{$$state{'keyword'}}) and $$state{'keyword'} eq 'additionalItems') { }
863 6 26 if $$schema{$$state{"keyword"}}
866 26 0 exists $$schema{'prefixItems'} || $$state{'keyword'} eq 'additionalItems' ? :
871 360 219 if _eval_subschema($$data[$idx], $$schema{$$state{"keyword"}}, {%$state, "data_path", $$state{"data_path"} . '/' . $idx, "schema_path", $$state{"schema_path"} . '/' . $$state{"keyword"}})
875 90 155 if $$state{"short_circuit"}
881 59 144 exists $$schema{'prefixItems'} || $$state{'keyword'} eq 'additionalItems' ? :
203 179 unless $valid
887 213 504 unless is_type("array", $data)
892 390 232 if (_eval_subschema($$data[$idx], $$schema{"contains"}, {%$state, "errors", \@errors, "data_path", $$state{"data_path"} . '/' . $idx, "schema_path", $$state{"schema_path"} . '/contains'}))
900 126 60 if $$state{"short_circuit"} and !exists($$schema{'maxContains'}) || $$state{'_num_contains'} > $$schema{'maxContains'} and $$state{"_num_contains"} >= ($$schema{"minContains"} // 1)
905 195 16 if (not $$state{"_num_contains"} and ($$schema{'minContains'} // 1) > 0 || $$state{'spec_version'} && $$state{'spec_version'} eq 'draft7')
916 251 2150 unless is_type("object", $data)
920 1044 1670 unless exists $$data{$property}
922 323 1347 if (is_type('boolean', $$schema{'properties'}{$property})) { }
923 217 106 if $$schema{"properties"}{$property}
931 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)})
935 210 225 if $$state{"short_circuit"}
938 413 1582 unless $valid
949 193 614 unless is_type("object", $data)
954 319 238 if (is_type('boolean', $$schema{'patternProperties'}{$property_pattern})) { }
955 211 108 if $$schema{"patternProperties"}{$property_pattern}
963 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)})
967 92 103 if $$state{"short_circuit"}
971 180 434 unless $valid
976 199 556 unless is_type("object", $data)
980 114 438 if exists $$schema{"properties"} and exists $$schema{"properties"}{$property}
982 88 350 if exists $$schema{"patternProperties"} and CORE::any {$property =~ /(?:$_)/u;} keys %{$$schema{"patternProperties"}}
984 192 158 if (is_type('boolean', $$schema{'additionalProperties'})) { }
985 20 172 if $$schema{"additionalProperties"}
994 63 43 if _eval_subschema($$data{$property}, $$schema{"additionalProperties"}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "schema_path", $$state{"schema_path"} . '/additionalProperties'})
998 105 110 if $$state{"short_circuit"}
1001 214 290 unless $valid
1006 175 288 unless is_type("object", $data)
1013 86 116 if _eval_subschema($property, $$schema{"propertyNames"}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "schema_path", $$state{"schema_path"} . '/propertyNames'})
1016 60 56 if $$state{"short_circuit"}
1019 116 172 unless $valid
1039 83 52811 if ($type eq "null")
1042 6022 46789 if ($type eq "boolean")
1045 12088 34701 if ($type eq "object")
1048 8790 25911 if ($type eq "array")
1052 9036 16 if ($type eq "string" or $type eq "number" or $type eq "integer")
1053 18 25877 unless defined $value
1061 16845 9032 if ($type eq "string")
1069 6143 2889 if ($type eq "number")
1074 2889 0 if ($type eq "integer")
1083 11 5 if ($type =~ /^reference to (.+)$/u)
1094 22047 13041 if ref $value eq "HASH"
1095 1979 11062 if is_bool($value)
1096 298 10764 unless defined $value
1097 1283 9481 if ref $value eq "ARRAY"
1100 455 9026 if (length(my $ref = ref $value))
1101 195 81 $value->is_int ? :
4 70 defined builtin::blessed($value) ? :
276 74 $ref eq 'Math::BigFloat' ? :
105 350 $ref eq 'Math::BigInt' ? :
1118 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\x15\x55\x55\x55"} 0 + $value eq $value }
1122 4355 17 int $value == $value ? :
4372 15 if &created_as_number($value)
1135 19063 0 unless builtin::is_bool($value)
1160 3 4168 if grep(($types[$_] eq "ambiguous type"), (0, 1))
1163 99 4069 if ($SCALARREF_BOOLEANS)
1164 14 85 if $types[0] eq "reference to SCALAR"
1165 18 81 if $types[1] eq "reference to SCALAR"
1168 18 4150 if ($STRINGY_NUMBERS)
1169 5 3 int 0 + $x == $x ? :
8 10 if $types[0] eq "string" and &looks_like_number($x)
1172 4 1 int 0 + $y == $y ? :
5 13 if $types[1] eq "string" and &looks_like_number($y)
1176 843 3325 if $types[0] ne $types[1]
1177 14 3311 if $types[0] eq "null"
1178 1533 1778 if $types[0] eq "string"
1180 1155 623 if grep(($types[0] eq $_), ("boolean", "number", "integer"))
1184 217 406 if ($types[0] eq "object")
1185 17 200 if keys %$x != keys %$y
1188 7 193 unless (is_equal(my $arr_x = [sort(keys %$x)], my $arr_y = [sort(keys %$y)], scalar(my $s = {})))
1196 87 144 unless is_equal($$x{$property}, $$y{$property}, $state)
1202 406 0 if ($types[0] eq "array")
1203 9 397 if @$x != @$y
1206 128 313 unless is_equal($$x[$idx], $$y[$idx], $state)
1223 207 1044 if (is_equal($$array[$idx0], $$array[$idx1]))
1224 207 0 if defined $equal_indices
1243 14011 6758 unless @extra_path or length $$state{"schema_path"}
1245 9843 6758 @extra_path ? :
1246 78 16523 unless length $fragment
1256 1 9842 defined $sps && ref $sps eq 'ARRAY' ? :
1263 8516 1327 if $uri eq "" and $keyword_location eq "" or ($uri->fragment // "") eq $keyword_location and $uri->clone->fragment(undef) eq ""
1268 1327 8516 defined $uri ? :
4726 5117 @args ? :
1286 28000 18 if is_type($type, $$schema{$$state{"keyword"}})
1287 2 16 $type =~ /^[aeiou]/u ? :
1304 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
1319 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
1335 0 2788 if $$schema{$$state{"keyword"}} < 0
1341 0 1928 unless @{$$schema{$$state{"keyword"}}}
1348 66 923 is_bignum($value) ? :