Branch Coverage

blib/lib/JSON/Schema/Tiny.pm
Criterion Covered Total %
branch 494 546 90.4


line true false branch
49 0 12121 unless defined wantarray
56 11974 147 if &blessed($_[0]) and &blessed($_[0])->isa("JSON::Schema::Tiny")
60 11995 126 if (defined $SPECIFICATION_VERSION)
62 3 11992 if not $SPECIFICATION_VERSION =~ /^draft/u and &any(sub {
64 1 11994 if &none(sub {
67 0 12120 if @_ < 2
98 0 6092 unless $valid or @{$state->{'errors'}}
102 6024 6082 $valid ? :
6024 6082 $valid ? :
14 12106 $BOOLEAN_RESULT ? :
129 0 20542 unless defined wantarray
137 3 20539 if $state->{'depth'}++ > $MAX_TRAVERSAL_DEPTH
145 2 20537 if grep((substr($schema_location, 0, length $_) eq $_), keys %{$state->{'seen'}{$state->{'data_path'}}{$canonical_uri}})
149 780 19757 if $schema_type eq "boolean"
150 19 19738 if $schema_type ne "object"
152 251 19487 unless keys %$schema
157 14635 4852 !$spec_version || $spec_version ne 'draft7' ? :
7599 11888 !$spec_version || $spec_version eq 'draft2019-09' ? :
7330 12157 !$spec_version || $spec_version eq 'draft2020-12' ? :
7599 11888 !$spec_version || $spec_version eq 'draft2019-09' ? :
7330 12157 !$spec_version || $spec_version eq 'draft2020-12' ? :
14635 4852 !$spec_version || $spec_version ne 'draft7' ? :
5146 14341 !$spec_version || $spec_version eq 'draft7' ? :
14635 4852 !$spec_version || $spec_version ne 'draft7' ? :
14635 4852 !$spec_version || $spec_version ne 'draft7' ? :
5146 14341 !$spec_version || $spec_version eq 'draft7' ? :
7330 12157 !($spec_version && $spec_version =~ qr/^draft(7|2019-09)$/u) ? :
12451 7036 !$spec_version || $spec_version =~ qr/^draft(?:7|2019-09)$/u ? :
14635 4852 !$spec_version || $spec_version ne 'draft7' ? :
14635 4852 !$spec_version || $spec_version ne 'draft7' ? :
14635 4852 !$spec_version || $spec_version ne 'draft7' ? :
188 650201 32350 unless exists $schema->{$keyword}
192 15 30640 if $keyword ne "\$ref" and $keyword ne "definitions" and exists $schema->{'$ref'} and $spec_version eq "draft7"
198 7129 22809 unless (&$sub($data, $schema, $state))
200 0 7129 if $error_count == @{$state->{'errors'}}
204 3481 4409 if not $valid and $state->{'short_circuit'}
209 59448 214 unless exists $schema->{$keyword}
212 214 0 if (my $alternates = $removed_keywords{$spec_version}{$keyword})
214 0 214 if @list > 2
215 162 52 if @list > 1
231 1 5155 if length $state->{'schema_path'}
234 21 5134 unless $spec_version
238 1 5133 if defined $SPECIFICATION_VERSION and $SPECIFICATION_VERSION ne $spec_version
243 1 5132 if exists $schema->{'$ref'} and $spec_version eq "draft7"
254 86 1487 unless ($uri->fragment // "") =~ m[^(/(?:[^~]|~[01])*|)$]u
260 427 1060 if $uri->clone->fragment(undef) ne "Mojo::URL"->new($state->{'root_schema'}{'$id'} // "")
263 5 1055 unless defined $subschema
278 0 52 unless ($uri->fragment // "") =~ m[^(/(?:[^~]|~[01])*|)$]u
285 44 8 if $uri->clone->fragment(undef) ne "Mojo::URL"->new($state->{'root_schema'}{'$id'} // "")
288 0 8 unless defined $subschema
290 0 0 if (is_type("boolean", $subschema->{'$recursiveAnchor'}) and $subschema->{'$recursiveAnchor'})
294 0 0 unless defined $subschema
313 117 461 if (($state->{'spec_version'} // '') eq 'draft7') { }
314 3 114 if (length $uri->fragment)
315 0 3 if length $uri->clone->fragment(undef)
318 1 2 unless $uri->fragment =~ /^[A-Za-z][A-Za-z0-9_:.-]*$/u
325 2 459 if length $uri->fragment
329 24 549 unless length $uri
331 428 121 $uri->is_abs ? :
346 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
353 41 39 if not $schema->{'$recursiveAnchor'} or exists $state->{'recursive_anchor_uri'}
358 0 39 unless exists $schema->{'$id'}
368 0 14 unless assert_keyword_type($state, $schema, "string")
371 0 14 unless $schema->{'$dynamicAnchor'} =~ /^[A-Za-z_][A-Za-z0-9._-]*$/u
384 0 4 if length $state->{'schema_path'}
387 0 4 if length $state->{'traversed_schema_path'} . $state->{'schema_path'}
405 159 3380 if (XXX) { }
406 0 159 unless @{$schema->{'type'}}
409 6 330 unless &any(sub {
411 0 153 unless is_elements_unique($schema->{'type'})
415 222 0 unless $type eq $_ or $_ eq "number" and $type eq "integer"
417 64 89 if &any(sub {
423 2 3372 unless &any(sub {
427 182 113 if $type eq $schema->{'type'} or $schema->{'type'} eq "number" and $type eq "integer" or $schema->{'type'} eq "boolean" and $SCALARREF_BOOLEANS and $type eq "reference to SCALAR"
434 0 385 unless is_elements_unique($schema->{'enum'})
437 209 176 if &any(sub {
441 169 7 !grep($_->{'path'}, @s) ? :
445 549 460 if is_equal($data, $schema->{'const'}, my $s = {})
447 55 405 $s->{'path'} ? :
452 0 816 if $schema->{'multipleOf'} <= 0
454 188 628 unless is_type("number", $data)
457 42 586 if (ref($data) =~ /^Math::Big(?:Int|Float)$/u or ref($schema->{'multipleOf'}) =~ /^Math::Big(?:Int|Float)$/u) { }
458 30 12 ref($data) =~ /^Math::Big(?:Int|Float)$/u ? :
459 42 0 ref($schema->{'multipleOf'}) =~ /^Math::Big(?:Int|Float)$/u ? :
461 0 42 if $quotient->is_inf
462 24 18 if $remainder == 0
466 586 0 "$]" >= 5.022 ? :
0 586 if "$]" >= "5.022" ? isinf($quotient) : $quotient =~ /^-?Inf$/iu
468 313 273 if int $quotient == $quotient
476 194 385 unless is_type("number", $data)
477 216 169 if $data <= $schema->{'maximum'}
483 188 289 unless is_type("number", $data)
484 138 151 if $data < $schema->{'exclusiveMaximum'}
490 203 504 unless is_type("number", $data)
491 265 239 if $data >= $schema->{'minimum'}
497 188 229 unless is_type("number", $data)
498 108 121 if $data > $schema->{'exclusiveMinimum'}
505 209 336 unless is_type("string", $data)
506 174 162 if length $data <= $schema->{'maxLength'}
513 210 302 unless is_type("string", $data)
514 160 142 if length $data >= $schema->{'minLength'}
522 227 666 unless is_type("string", $data)
523 352 313 if $data =~ /$schema->{'pattern'}/u
530 169 256 unless is_type("array", $data)
531 134 122 if @$data <= $schema->{'maxItems'}
532 22 100 $schema->{'maxItems'} > 1 ? :
538 167 257 unless is_type("array", $data)
539 133 124 if @$data >= $schema->{'minItems'}
540 112 12 $schema->{'minItems'} > 1 ? :
545 161 608 unless is_type("array", $data)
546 165 443 unless $schema->{'uniqueItems'}
547 242 201 if is_elements_unique($data, my $equal_indices = [])
553 8 76 unless exists $state->{'_num_contains'}
554 0 76 unless is_type("array", $data)
557 32 44 if $state->{'_num_contains'} > $schema->{'maxContains'}
564 8 94 unless exists $state->{'_num_contains'}
565 0 94 unless is_type("array", $data)
568 34 60 if $state->{'_num_contains'} < $schema->{'minContains'}
576 138 202 unless is_type("object", $data)
577 104 98 if keys %$data <= $schema->{'maxProperties'}
579 12 86 $schema->{'maxProperties'} > 1 ? :
585 138 202 unless is_type("object", $data)
586 104 98 if keys %$data >= $schema->{'minProperties'}
588 6 92 $schema->{'minProperties'} > 1 ? :
594 0 1410 if &any(sub {
595 0 1410 unless is_elements_unique($schema->{'required'})
597 150 1260 unless is_type("object", $data)
600 694 566 unless @missing
601 36 530 @missing > 1 ? :
609 0 287 unless is_type("array", $schema->{'dependentRequired'}{$property})
613 1 300 unless is_type("string", $schema->{'dependentRequired'}{$property}[$index])
617 0 286 unless is_elements_unique($schema->{'dependentRequired'}{$property})
620 97 173 unless is_type("object", $data)
624 36 153 unless exists $data->{$property}
626 79 74 if (my(@missing) = grep((!exists $data->{$_}), @{$$schema{"dependentRequired"}{$property}}))
627 5 74 @missing > 1 ? :
632 94 79 if $valid
642 447 187 if _eval_subschema($data, $schema->{'allOf'}[$idx], {%$state, "schema_path", $state->{'schema_path'} . "/allOf/" . $idx})
645 66 121 if $state->{'short_circuit'}
648 224 154 if @invalid == 0
651 31 123 $pl ? :
31 123 $pl ? :
661 382 231 unless _eval_subschema($data, $schema->{'anyOf'}[$idx], {%$state, "errors", \@errors, "schema_path", $state->{'schema_path'} . "/anyOf/" . $idx})
663 90 141 if $state->{'short_circuit'}
666 194 92 if $valid
677 533 377 unless _eval_subschema($data, $schema->{'oneOf'}[$idx], {%$state, "errors", \@errors, "schema_path", $state->{'schema_path'} . "/oneOf/" . $idx})
679 44 47 if @valid > 1 and $state->{'short_circuit'}
682 157 201 if @valid == 1
684 123 78 if (not @valid) { }
695 39 84 unless _eval_subschema($data, $schema->{'not'}, {%$state, "schema_path", $state->{'schema_path'} . "/not", "short_circuit", 1, "errors", []})
701 28 40 unless exists $schema->{'then'} or exists $schema->{'else'}
703 132 138 _eval_subschema($data, $schema->{'if'}, {%$state, 'schema_path', $state->{'schema_path'} . '/if', 'short_circuit', 1, 'errors', []}) ? :
706 46 224 unless exists $schema->{$keyword}
708 136 70 if _eval_subschema($data, $schema->{$keyword}, {%$state, "schema_path", $state->{'schema_path'} . "/" . $keyword})
715 124 173 unless is_type("object", $data)
721 110 89 if not exists $data->{$property} or _eval_subschema($data, $schema->{'dependentSchemas'}{$property}, {%$state, "schema_path", jsonp($state->{'schema_path'}, "dependentSchemas", $property)})
724 44 45 if $state->{'short_circuit'}
727 89 84 unless $valid
734 67 111 unless is_type("object", $data)
738 52 106 if (is_type('array', $schema->{'dependencies'}{$property})) { }
743 0 62 unless is_type("string", $schema->{'dependencies'}{$property}[$index])
747 0 52 unless is_elements_unique($schema->{'dependencies'}{$property})
749 28 24 unless exists $data->{$property}
751 14 10 if (my(@missing) = grep((!exists $data->{$_}), @{$$schema{"dependencies"}{$property}}))
752 3 11 @missing > 1 ? :
760 63 43 if not exists $data->{$property} or _eval_subschema($data, $schema->{'dependencies'}{$property}, {%$state, "schema_path", jsonp($state->{'schema_path'}, "dependencies", $property)})
763 21 22 if $state->{'short_circuit'}
767 56 55 if $valid
800 0 395 unless assert_array_schemas($schema, $state)
805 684 588 if (XXX)
807 1 683 if ($state->{'spec_version'} // "") eq "draft2020-12"
817 24 177 unless exists $state->{'_last_items_index'}
823 0 1078 unless @{$$schema{$state->{'keyword'}}}
824 213 865 unless is_type("array", $data)
829 269 1250 if $idx > $#{$$schema{$state->{'keyword'}}}
832 274 976 if (is_type('boolean', $$schema{$state->{'keyword'}}[$idx])) { }
833 166 108 if $$schema{$state->{'keyword'}}[$idx]
840 909 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 693 unless $valid
856 104 661 unless is_type("array", $data)
857 232 429 if $state->{'_last_items_index'} == $#$data
861 26 607 if (is_type('boolean', $$schema{$state->{'keyword'}}) and $state->{'keyword'} eq 'additionalItems') { }
863 6 20 if $$schema{$state->{'keyword'}}
866 20 0 exists $schema->{'prefixItems'} || $state->{'keyword'} eq 'additionalItems' ? :
871 336 206 if _eval_subschema($data->[$idx], $$schema{$state->{'keyword'}}, {%$state, "data_path", $state->{'data_path'} . "/" . $idx, "schema_path", $state->{'schema_path'} . "/" . $state->{'keyword'}})
875 84 142 if $state->{'short_circuit'}
881 53 138 exists $schema->{'prefixItems'} || $state->{'keyword'} eq 'additionalItems' ? :
191 173 unless $valid
887 213 496 unless is_type("array", $data)
892 385 229 if (_eval_subschema($data->[$idx], $schema->{'contains'}, {%$state, "errors", \@errors, "data_path", $state->{'data_path'} . "/" . $idx, "schema_path", $state->{'schema_path'} . "/contains"}))
900 124 60 if $state->{'short_circuit'} and !exists $schema->{'maxContains'} || $state->{'_num_contains'} > $schema->{'maxContains'} and $state->{'_num_contains'} >= ($schema->{'minContains'} // 1)
905 195 12 if (not $state->{'_num_contains'} and ($schema->{'minContains'} // 1) > 0 || $state->{'spec_version'} && $state->{'spec_version'} eq 'draft7')
916 251 2032 unless is_type("object", $data)
920 1001 1586 unless exists $data->{$property}
922 323 1263 if (is_type('boolean', $schema->{'properties'}{$property})) { }
923 217 106 if $schema->{'properties'}{$property}
931 801 315 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 201 220 if $state->{'short_circuit'}
938 399 1486 unless $valid
949 193 613 unless is_type("object", $data)
954 318 238 if (is_type('boolean', $schema->{'patternProperties'}{$property_pattern})) { }
955 210 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 433 unless $valid
976 199 519 unless is_type("object", $data)
980 110 67 if exists $schema->{'properties'} and exists $schema->{'properties'}{$property}
982 87 305 if exists $schema->{'patternProperties'} and &any(sub {
984 164 141 if (is_type('boolean', $schema->{'additionalProperties'})) { }
985 16 148 if $schema->{'additionalProperties'}
994 52 37 if _eval_subschema($data->{$property}, $schema->{'additionalProperties'}, {%$state, "data_path", jsonp($state->{'data_path'}, $property), "schema_path", $state->{'schema_path'} . "/additionalProperties"})
998 90 95 if $state->{'short_circuit'}
1001 184 283 unless $valid
1006 175 230 unless is_type("object", $data)
1013 42 104 if _eval_subschema($property, $schema->{'propertyNames'}, {%$state, "data_path", jsonp($state->{'data_path'}, $property), "schema_path", $state->{'schema_path'} . "/propertyNames"})
1016 55 49 if $state->{'short_circuit'}
1019 104 126 unless $valid
1034 71 50114 if ($type eq "null")
1037 5260 44854 if ($type eq "boolean")
1040 11590 33264 if ($type eq "object")
1043 8523 24741 if ($type eq "array")
1047 8918 18 if ($type eq "string" or $type eq "number" or $type eq "integer")
1048 18 24705 unless defined $value
1051 15791 8914 if ($type eq "string")
1055 6055 2859 if ($type eq "number")
1060 2859 0 if ($type eq "integer")
1066 14 4 if ($type =~ /^reference to (.+)$/u)
1074 306 36794 unless defined $value
1075 21050 15744 if XXX
1076 1249 14495 if XXX
1077 2094 12401 if is_bool($value)
1079 750 81 $value->is_int ? :
3 76 &blessed($value) ? :
831 79 ref($value) =~ /^Math::Big(?:Int|Float)$/u ? :
910 11491 if XXX
1084 4454 7037 if $flags & 1024 and not $flags & 768
1085 7034 2 int $value == $value ? :
7036 1 if not $flags & 1024 and $flags & 768
1100 104 6347 if ($SCALARREF_BOOLEANS)
1101 10 94 if $types[0] eq "reference to SCALAR"
1102 17 87 if $types[1] eq "reference to SCALAR"
1105 1138 5313 if $types[0] ne $types[1]
1106 14 5299 if $types[0] eq "null"
1107 1456 3843 if $types[0] eq "string"
1108 3295 548 if grep(($types[0] eq $_), ("boolean", "number", "integer"))
1111 217 331 if ($types[0] eq "object")
1112 16 201 if keys %$x != keys %$y
1113 15 186 unless is_equal([sort(keys %$x)], [sort(keys %$y)])
1116 86 132 unless is_equal($x->{$property}, $y->{$property}, $state)
1121 331 0 if ($types[0] eq "array")
1122 8 323 if @$x != @$y
1125 97 264 unless is_equal($x->[$idx], $y->[$idx], $state)
1138 201 3604 if (is_equal($array->[$idx0], $array->[$idx1]))
1139 201 0 if defined $equal_indices
1149 1 24254 XXX ? :
1154 1 30096 if @extra_path and XXX
1157 12552 17545 unless length $uri->fragment
1169 8074 1231 if $uri eq "" and $keyword_location eq "" or ($uri->fragment // "") eq $keyword_location and $uri->clone->fragment(undef) eq ""
1174 1231 8074 defined $uri ? :
4542 4763 @args ? :
1196 0 0 XXX ? :
4 0 XXX ? :
4 26563 if exists $state->{'_schema_path_suffix'}
1197 26559 8 if is_type($type, $value)
1198 2 6 $type =~ /^[aeiou]/u ? :
1215 0 1121 if fc "Mojo::URL"->new($ref)->to_unsafe_string ne fc $ref or $ref =~ /[^[:ascii:]]/u or $ref =~ /#/u and not $ref =~ /#$/u and not $ref =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u and not $ref =~ m[#/(?:[^~]|~[01])*$]u
1229 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
1245 0 2772 if $$schema{$state->{'keyword'}} < 0
1251 0 1858 unless @{$$schema{$state->{'keyword'}}}
1257 66 905 ref($value) =~ /^Math::Big(?:Int|Float)$/u ? :