Branch Coverage

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


line true false branch
57 0 12777 unless defined wantarray
65 12610 167 if builtin::blessed($_[0]) and builtin::blessed($_[0])->isa(__PACKAGE__)
69 12631 146 if (defined $SPECIFICATION_VERSION)
71 3 12628 if not $SPECIFICATION_VERSION =~ /^draft/u and CORE::any {'draft' . $SPECIFICATION_VERSION eq $_;} values %version_uris
73 1 12630 unless CORE::any {$SPECIFICATION_VERSION eq $_;} values %version_uris
76 0 12776 if @_ < 2
97 1674 1 if (ref $e eq 'HASH') { }
107 0 6506 unless $valid or @{$$state{"errors"}}
111 6266 6496 $valid ? :
6266 6496 $valid ? :
14 12762 $BOOLEAN_RESULT ? :
138 0 21636 unless defined wantarray
146 3 21633 if $$state{"depth"}++ > $MAX_TRAVERSAL_DEPTH
149 751 20882 if $schema_type eq "boolean"
150 19 20863 if $schema_type ne "object"
152 359 20504 unless keys %$schema
162 2 20502 if grep((substr($schema_location, 0, length $_) eq $_), keys %{$$state{"seen"}{$$state{"data_path"}}{$canonical_uri}})
169 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' ? :
201 686002 34296 unless exists $$schema{$keyword}
205 15 32444 if $keyword ne "\$ref" and $keyword ne "definitions" and exists $$schema{"\$ref"} and $spec_version eq "draft7"
211 7501 24181 unless (&$sub($data, $schema, $state))
213 0 7501 if $error_count == @{$$state{"errors"}}
217 3656 28026 if not $valid and $$state{"short_circuit"}
222 62422 214 unless exists $$schema{$keyword}
225 214 0 if (my $alternates = $removed_keywords{$spec_version}{$keyword})
227 0 214 if @list > 2
228 162 52 if @list > 1
244 1 5643 if length $$state{"schema_path"}
247 29 5614 unless $spec_version
251 1 5613 if defined $SPECIFICATION_VERSION and $SPECIFICATION_VERSION ne $spec_version
256 1 5612 if exists $$schema{"\$ref"} and $spec_version eq "draft7"
267 98 1601 unless ($uri->fragment // "") =~ m[^(?:/(?:[^~]|~[01])*)?$]u
273 469 1132 if $uri->clone->fragment(undef) ne "Mojo::URL"->new($$state{"root_schema"}{"\$id"} // "")
276 5 1127 unless defined $subschema
291 0 52 unless ($uri->fragment // "") =~ m[^(?:/(?:[^~]|~[01])*)?$]u
298 44 8 if $uri->clone->fragment(undef) ne "Mojo::URL"->new($$state{"root_schema"}{"\$id"} // "")
301 0 8 unless defined $subschema
303 0 8 if (is_type("boolean", $$subschema{"\$recursiveAnchor"}) and $$subschema{"\$recursiveAnchor"})
307 0 0 unless defined $subschema
326 133 537 if (($$state{'spec_version'} // '') eq 'draft7') { }
327 3 130 if (length $uri->fragment)
328 0 3 if length $uri->clone->fragment(undef)
331 1 2 unless $uri->fragment =~ /^[A-Za-z][A-Za-z0-9_:.-]*$/u
338 2 535 if length $uri->fragment
342 24 641 unless length $uri
344 540 101 $uri->is_abs ? :
359 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
366 41 51 if not $$schema{"\$recursiveAnchor"} or exists $$state{"recursive_anchor_uri"}
371 0 51 unless exists $$schema{"\$id"}
381 0 10 unless assert_keyword_type($state, $schema, "string")
384 0 10 unless $$schema{"\$dynamicAnchor"} =~ /^[A-Za-z_][A-Za-z0-9._-]*$/u
393 0 4 unless is_type("boolean", $$schema{"\$vocabulary"}{$uri})
399 0 4 if length $$state{"schema_path"}
402 0 4 if length $$state{"traversed_schema_path"} . $$state{"schema_path"}
420 163 3543 if (ref $$schema{'type'} eq 'ARRAY') { }
421 0 163 unless @{$$schema{"type"}}
424 6 338 unless CORE::any {($type // "") eq $_;} "null", "boolean", "object", "array", "string", "number", "integer"
426 0 157 unless is_elements_unique($$schema{"type"})
430 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
434 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"}}
440 2 3535 unless CORE::any {($$schema{"type"} // "") eq $_;} "null", "boolean", "object", "array", "string", "number", "integer"
446 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"
455 264 219 if CORE::any {is_equal($data, $_, $s[$idx++] = {});} @{$$schema{"enum"}}
458 176 43 !grep($$_{'path'}, @s) ? :
463 576 479 if is_equal($data, $$schema{"const"}, scalar(my $s = {}))
464 55 424 $$s{'path'} ? :
469 0 830 if $$schema{"multipleOf"} <= 0
473 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 }
476 52 588 if (is_bignum($data) or is_bignum($$schema{'multipleOf'}) or get_type($data) eq 'number' or get_type($$schema{'multipleOf'}) eq 'number') { }
478 30 22 is_bignum($data) ? :
479 48 4 is_bignum($$schema{'multipleOf'}) ? :
481 0 52 if $quotient->is_inf
482 30 22 if $remainder == 0
486 588 0 "$]" >= 5.022 ? :
0 588 if "$]" >= "5.022" ? isinf($quotient) : $quotient =~ /^-?Inf$/iu
488 313 275 if int $quotient == $quotient
496 0 1 unless is_type("number", $data) or $STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
498 216 172 if 0 + $data <= $$schema{"maximum"}
504 0 1 unless is_type("number", $data) or $STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
506 138 154 if 0 + $data < $$schema{"exclusiveMaximum"}
512 0 1 unless is_type("number", $data) or $STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
514 265 242 if 0 + $data >= $$schema{"minimum"}
520 0 1 unless is_type("number", $data) or $STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
522 108 124 if 0 + $data > $$schema{"exclusiveMinimum"}
529 209 352 unless is_type("string", $data)
530 190 162 if length $data <= $$schema{"maxLength"}
537 210 302 unless is_type("string", $data)
538 160 142 if length $data >= $$schema{"minLength"}
546 227 671 unless is_type("string", $data)
547 357 313 if $data =~ /(?:$$schema{"pattern"})/u
554 169 256 unless is_type("array", $data)
555 134 122 if @$data <= $$schema{"maxItems"}
556 22 100 $$schema{'maxItems'} > 1 ? :
562 167 257 unless is_type("array", $data)
563 133 124 if @$data >= $$schema{"minItems"}
564 112 12 $$schema{'minItems'} > 1 ? :
569 161 614 unless is_type("array", $data)
570 165 449 unless $$schema{"uniqueItems"}
571 242 207 if is_elements_unique($data, scalar(my $equal_indices = []))
577 8 76 unless exists $$state{"_num_contains"}
578 0 76 unless is_type("array", $data)
581 32 44 if $$state{"_num_contains"} > $$schema{"maxContains"}
588 8 94 unless exists $$state{"_num_contains"}
589 0 94 unless is_type("array", $data)
592 34 60 if $$state{"_num_contains"} < $$schema{"minContains"}
600 138 202 unless is_type("object", $data)
601 104 98 if keys %$data <= $$schema{"maxProperties"}
603 12 86 $$schema{'maxProperties'} > 1 ? :
609 138 202 unless is_type("object", $data)
610 104 98 if keys %$data >= $$schema{"minProperties"}
612 6 92 $$schema{'minProperties'} > 1 ? :
618 0 1414 if CORE::any {not is_type("string", $_);} @{$$schema{"required"}}
619 0 1414 unless is_elements_unique($$schema{"required"})
621 150 1264 unless is_type("object", $data)
624 698 566 unless @missing
625 36 530 @missing > 1 ? :
633 0 287 unless is_type("array", $$schema{"dependentRequired"}{$property})
637 1 300 unless is_type("string", $$schema{"dependentRequired"}{$property}[$index])
641 0 286 unless is_elements_unique($$schema{"dependentRequired"}{$property})
644 97 173 unless is_type("object", $data)
648 36 153 unless exists $$data{$property}
650 79 74 if (my(@missing) = grep((!exists($$data{$_})), @{$$schema{"dependentRequired"}{$property}}))
651 5 74 @missing > 1 ? :
656 94 79 if $valid
666 463 209 if _eval_subschema($data, $$schema{"allOf"}[$idx], {%$state, "schema_path", $$state{"schema_path"} . '/allOf/' . $idx})
669 71 138 if $$state{"short_circuit"}
672 235 169 if @invalid == 0
675 36 133 $pl ? :
36 133 $pl ? :
685 382 239 unless _eval_subschema($data, $$schema{"anyOf"}[$idx], {%$state, "errors", \@errors, "schema_path", $$state{"schema_path"} . '/anyOf/' . $idx})
687 98 141 if $$state{"short_circuit"}
690 202 92 if $valid
701 533 377 unless _eval_subschema($data, $$schema{"oneOf"}[$idx], {%$state, "errors", \@errors, "schema_path", $$state{"schema_path"} . '/oneOf/' . $idx})
703 44 333 if @valid > 1 and $$state{"short_circuit"}
706 157 201 if @valid == 1
708 123 78 if (not @valid) { }
718 112 181 if is_type("boolean", $$schema{"not"})
721 38 135 unless _eval_subschema($data, $$schema{"not"}, {%$state, "schema_path", $$state{"schema_path"} . '/not', "short_circuit", 1, "errors", []})
727 44 52 unless exists $$schema{"then"} or exists $$schema{"else"}
729 138 144 _eval_subschema($data, $$schema{'if'}, {%$state, 'schema_path', $$state{'schema_path'} . '/if', 'short_circuit', 1, 'errors', []}) ? :
732 58 224 unless exists $$schema{$keyword}
735 32 192 if is_type("boolean", $$schema{$keyword})
738 108 62 if _eval_subschema($data, $$schema{$keyword}, {%$state, "schema_path", $$state{"schema_path"} . '/' . $keyword})
745 124 213 unless is_type("object", $data)
751 166 97 if not exists $$data{$property} or _eval_subschema($data, $$schema{"dependentSchemas"}{$property}, {%$state, "schema_path", jsonp($$state{"schema_path"}, "dependentSchemas", $property)})
754 48 49 if $$state{"short_circuit"}
757 97 116 unless $valid
764 67 119 unless is_type("object", $data)
768 52 114 if (is_type('array', $$schema{'dependencies'}{$property})) { }
773 0 62 unless is_type("string", $$schema{"dependencies"}{$property}[$index])
777 0 52 unless is_elements_unique($$schema{"dependencies"}{$property})
779 28 24 unless exists $$data{$property}
781 14 10 if (my(@missing) = grep((!exists($$data{$_})), @{$$schema{"dependencies"}{$property}}))
782 3 11 @missing > 1 ? :
790 67 47 if not exists $$data{$property} or _eval_subschema($data, $$schema{"dependencies"}{$property}, {%$state, "schema_path", jsonp($$state{"schema_path"}, "dependencies", $property)})
793 23 24 if $$state{"short_circuit"}
797 60 59 if $valid
802 0 411 unless assert_array_schemas($schema, $state)
807 700 604 if (ref $$schema{"items"} eq "ARRAY")
809 1 699 if ($$state{"spec_version"} // "") eq "draft2020-12"
819 28 191 unless exists $$state{"_last_items_index"}
825 0 1110 unless @{$$schema{$$state{"keyword"}}}
826 213 897 unless is_type("array", $data)
831 287 1294 if $idx > $$schema{$$state{"keyword"}}->$#*
834 286 1008 if (is_type('boolean', $$schema{$$state{'keyword'}}[$idx])) { }
835 178 108 if $$schema{$$state{"keyword"}}[$idx]
842 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})
848 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())}
852 172 725 unless $valid
858 104 691 unless is_type("array", $data)
859 244 447 if $$state{"_last_items_index"} == $data->$#*
863 32 644 if (is_type('boolean', $$schema{$$state{'keyword'}}) and $$state{'keyword'} eq 'additionalItems') { }
865 6 26 if $$schema{$$state{"keyword"}}
868 26 0 exists $$schema{'prefixItems'} || $$state{'keyword'} eq 'additionalItems' ? :
873 360 219 if _eval_subschema($$data[$idx], $$schema{$$state{"keyword"}}, {%$state, "data_path", $$state{"data_path"} . '/' . $idx, "schema_path", $$state{"schema_path"} . '/' . $$state{"keyword"}})
877 90 155 if $$state{"short_circuit"}
883 59 144 exists $$schema{'prefixItems'} || $$state{'keyword'} eq 'additionalItems' ? :
203 179 unless $valid
889 213 504 unless is_type("array", $data)
894 390 232 if (_eval_subschema($$data[$idx], $$schema{"contains"}, {%$state, "errors", \@errors, "data_path", $$state{"data_path"} . '/' . $idx, "schema_path", $$state{"schema_path"} . '/contains'}))
902 126 60 if $$state{"short_circuit"} and !exists($$schema{'maxContains'}) || $$state{'_num_contains'} > $$schema{'maxContains'} and $$state{"_num_contains"} >= ($$schema{"minContains"} // 1)
907 195 16 if (not $$state{"_num_contains"} and ($$schema{'minContains'} // 1) > 0 || $$state{'spec_version'} && $$state{'spec_version'} eq 'draft7')
918 251 2150 unless is_type("object", $data)
922 1044 1670 unless exists $$data{$property}
924 323 1347 if (is_type('boolean', $$schema{'properties'}{$property})) { }
925 217 106 if $$schema{"properties"}{$property}
933 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)})
937 210 225 if $$state{"short_circuit"}
940 413 1582 unless $valid
951 193 614 unless is_type("object", $data)
956 319 238 if (is_type('boolean', $$schema{'patternProperties'}{$property_pattern})) { }
957 211 108 if $$schema{"patternProperties"}{$property_pattern}
965 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)})
969 92 103 if $$state{"short_circuit"}
973 180 434 unless $valid
978 199 556 unless is_type("object", $data)
982 114 438 if exists $$schema{"properties"} and exists $$schema{"properties"}{$property}
984 88 350 if exists $$schema{"patternProperties"} and CORE::any {$property =~ /(?:$_)/u;} keys %{$$schema{"patternProperties"}}
986 192 158 if (is_type('boolean', $$schema{'additionalProperties'})) { }
987 20 172 if $$schema{"additionalProperties"}
996 63 43 if _eval_subschema($$data{$property}, $$schema{"additionalProperties"}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "schema_path", $$state{"schema_path"} . '/additionalProperties'})
1000 105 110 if $$state{"short_circuit"}
1003 214 290 unless $valid
1008 175 288 unless is_type("object", $data)
1015 86 116 if _eval_subschema($property, $$schema{"propertyNames"}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "schema_path", $$state{"schema_path"} . '/propertyNames'})
1018 60 56 if $$state{"short_circuit"}
1021 116 172 unless $valid
1041 83 52811 if ($type eq "null")
1044 6022 46789 if ($type eq "boolean")
1047 12088 34701 if ($type eq "object")
1050 8790 25911 if ($type eq "array")
1054 9036 16 if ($type eq "string" or $type eq "number" or $type eq "integer")
1055 18 25877 unless defined $value
1063 16845 9032 if ($type eq "string")
1071 6143 2889 if ($type eq "number")
1076 2889 0 if ($type eq "integer")
1085 11 5 if ($type =~ /^reference to (.+)$/u)
1096 22047 13041 if ref $value eq "HASH"
1097 1979 11062 if is_bool($value)
1098 298 10764 unless defined $value
1099 1283 9481 if ref $value eq "ARRAY"
1102 455 9026 if (length(my $ref = 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} = "\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x15\x50\x55\x15\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 $sps eq 'ARRAY' ? :
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) ? :