Branch Coverage

blib/lib/JSON/Schema/Tiny.pm
Criterion Covered Total %
branch 494 544 90.8


line true false branch
50 0 12233 unless defined wantarray
57 12084 149 if &blessed($_[0]) and &blessed($_[0])->isa("JSON::Schema::Tiny")
61 12105 128 if (defined $SPECIFICATION_VERSION)
63 3 12102 if not $SPECIFICATION_VERSION =~ /^draft/u and &any(sub {
65 1 12104 if &none(sub {
68 0 12232 if @_ < 2
99 0 6192 unless $valid or @{$state->{'errors'}}
103 6036 6182 $valid ? :
6036 6182 $valid ? :
14 12218 $BOOLEAN_RESULT ? :
130 0 20732 unless defined wantarray
138 3 20729 if $state->{'depth'}++ > $MAX_TRAVERSAL_DEPTH
146 2 20727 if grep((substr($schema_location, 0, length $_) eq $_), keys %{$state->{'seen'}{$state->{'data_path'}}{$canonical_uri}})
150 788 19939 if $schema_type eq "boolean"
151 19 19920 if $schema_type ne "object"
153 251 19669 unless keys %$schema
158 14768 4901 !$spec_version || $spec_version ne 'draft7' ? :
7670 11999 !$spec_version || $spec_version eq 'draft2019-09' ? :
7394 12275 !$spec_version || $spec_version eq 'draft2020-12' ? :
7670 11999 !$spec_version || $spec_version eq 'draft2019-09' ? :
7394 12275 !$spec_version || $spec_version eq 'draft2020-12' ? :
14768 4901 !$spec_version || $spec_version ne 'draft7' ? :
5197 14472 !$spec_version || $spec_version eq 'draft7' ? :
14768 4901 !$spec_version || $spec_version ne 'draft7' ? :
14768 4901 !$spec_version || $spec_version ne 'draft7' ? :
5197 14472 !$spec_version || $spec_version eq 'draft7' ? :
7394 12275 !($spec_version && $spec_version =~ qr/^draft(7|2019-09)$/u) ? :
12571 7098 !$spec_version || $spec_version =~ qr/^draft(?:7|2019-09)$/u ? :
14768 4901 !$spec_version || $spec_version ne 'draft7' ? :
14768 4901 !$spec_version || $spec_version ne 'draft7' ? :
14768 4901 !$spec_version || $spec_version ne 'draft7' ? :
189 653488 32648 unless exists $schema->{$keyword}
193 15 30874 if $keyword ne "\$ref" and $keyword ne "definitions" and exists $schema->{'$ref'} and $spec_version eq "draft7"
199 7145 22972 unless (&$sub($data, $schema, $state))
201 0 7145 if $error_count == @{$state->{'errors'}}
205 3487 4421 if not $valid and $state->{'short_circuit'}
210 59654 214 unless exists $schema->{$keyword}
213 214 0 if (my $alternates = $removed_keywords{$spec_version}{$keyword})
215 0 214 if @list > 2
216 162 52 if @list > 1
232 1 5211 if length $state->{'schema_path'}
235 29 5182 unless $spec_version
239 1 5181 if defined $SPECIFICATION_VERSION and $SPECIFICATION_VERSION ne $spec_version
244 1 5180 if exists $schema->{'$ref'} and $spec_version eq "draft7"
255 94 1539 unless ($uri->fragment // "") =~ m[^(/(?:[^~]|~[01])*|)$]u
261 479 1060 if $uri->clone->fragment(undef) ne "Mojo::URL"->new($state->{'root_schema'}{'$id'} // "")
264 5 1055 unless defined $subschema
279 0 52 unless ($uri->fragment // "") =~ m[^(/(?:[^~]|~[01])*|)$]u
286 44 8 if $uri->clone->fragment(undef) ne "Mojo::URL"->new($state->{'root_schema'}{'$id'} // "")
289 0 8 unless defined $subschema
291 0 0 if (is_type("boolean", $subschema->{'$recursiveAnchor'}) and $subschema->{'$recursiveAnchor'})
295 0 0 unless defined $subschema
314 121 473 if (($state->{'spec_version'} // '') eq 'draft7') { }
315 3 118 if (length $uri->fragment)
316 0 3 if length $uri->clone->fragment(undef)
319 1 2 unless $uri->fragment =~ /^[A-Za-z][A-Za-z0-9_:.-]*$/u
326 2 471 if length $uri->fragment
330 24 565 unless length $uri
332 444 121 $uri->is_abs ? :
347 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
354 41 39 if not $schema->{'$recursiveAnchor'} or exists $state->{'recursive_anchor_uri'}
359 0 39 unless exists $schema->{'$id'}
369 0 14 unless assert_keyword_type($state, $schema, "string")
372 0 14 unless $schema->{'$dynamicAnchor'} =~ /^[A-Za-z_][A-Za-z0-9._-]*$/u
385 0 4 if length $state->{'schema_path'}
388 0 4 if length $state->{'traversed_schema_path'} . $state->{'schema_path'}
406 159 3420 if (XXX) { }
407 0 159 unless @{$schema->{'type'}}
410 6 330 unless &any(sub {
412 0 153 unless is_elements_unique($schema->{'type'})
416 222 0 unless $type eq $_ or $_ eq "number" and $type eq "integer"
418 64 89 if &any(sub {
424 2 3412 unless &any(sub {
428 190 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"
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 822 if $schema->{'multipleOf'} <= 0
454 188 634 unless is_type("number", $data)
457 49 585 if (ref($data) =~ /^Math::Big(?:Int|Float)$/u or ref($schema->{'multipleOf'}) =~ /^Math::Big(?:Int|Float)$/u or get_type($data) eq 'number' or get_type($schema->{'multipleOf'}) eq 'number') { }
460 30 19 ref($data) =~ /^Math::Big(?:Int|Float)$/u ? :
461 48 1 ref($schema->{'multipleOf'}) =~ /^Math::Big(?:Int|Float)$/u ? :
463 0 49 if $quotient->is_inf
464 30 19 if $remainder == 0
468 585 0 "$]" >= 5.022 ? :
0 585 if "$]" >= "5.022" ? isinf($quotient) : $quotient =~ /^-?Inf$/iu
470 313 272 if int $quotient == $quotient
478 194 385 unless is_type("number", $data)
479 216 169 if $data <= $schema->{'maximum'}
485 188 289 unless is_type("number", $data)
486 138 151 if $data < $schema->{'exclusiveMaximum'}
492 203 504 unless is_type("number", $data)
493 265 239 if $data >= $schema->{'minimum'}
499 188 229 unless is_type("number", $data)
500 108 121 if $data > $schema->{'exclusiveMinimum'}
507 209 344 unless is_type("string", $data)
508 182 162 if length $data <= $schema->{'maxLength'}
515 210 302 unless is_type("string", $data)
516 160 142 if length $data >= $schema->{'minLength'}
524 227 667 unless is_type("string", $data)
525 353 313 if $data =~ /(?:$schema->{'pattern'})/u
532 169 256 unless is_type("array", $data)
533 134 122 if @$data <= $schema->{'maxItems'}
534 22 100 $schema->{'maxItems'} > 1 ? :
540 167 257 unless is_type("array", $data)
541 133 124 if @$data >= $schema->{'minItems'}
542 112 12 $schema->{'minItems'} > 1 ? :
547 161 608 unless is_type("array", $data)
548 165 443 unless $schema->{'uniqueItems'}
549 242 201 if is_elements_unique($data, my $equal_indices = [])
555 8 76 unless exists $state->{'_num_contains'}
556 0 76 unless is_type("array", $data)
559 32 44 if $state->{'_num_contains'} > $schema->{'maxContains'}
566 8 94 unless exists $state->{'_num_contains'}
567 0 94 unless is_type("array", $data)
570 34 60 if $state->{'_num_contains'} < $schema->{'minContains'}
578 138 202 unless is_type("object", $data)
579 104 98 if keys %$data <= $schema->{'maxProperties'}
581 12 86 $schema->{'maxProperties'} > 1 ? :
587 138 202 unless is_type("object", $data)
588 104 98 if keys %$data >= $schema->{'minProperties'}
590 6 92 $schema->{'minProperties'} > 1 ? :
596 0 1410 if &any(sub {
597 0 1410 unless is_elements_unique($schema->{'required'})
599 150 1260 unless is_type("object", $data)
602 694 566 unless @missing
603 36 530 @missing > 1 ? :
611 0 287 unless is_type("array", $schema->{'dependentRequired'}{$property})
615 1 300 unless is_type("string", $schema->{'dependentRequired'}{$property}[$index])
619 0 286 unless is_elements_unique($schema->{'dependentRequired'}{$property})
622 97 173 unless is_type("object", $data)
626 36 153 unless exists $data->{$property}
628 79 74 if (my(@missing) = grep((!exists $data->{$_}), @{$$schema{"dependentRequired"}{$property}}))
629 5 74 @missing > 1 ? :
634 94 79 if $valid
644 451 187 if _eval_subschema($data, $schema->{'allOf'}[$idx], {%$state, "schema_path", $state->{'schema_path'} . "/allOf/" . $idx})
647 66 121 if $state->{'short_circuit'}
650 228 154 if @invalid == 0
653 31 123 $pl ? :
31 123 $pl ? :
663 382 239 unless _eval_subschema($data, $schema->{'anyOf'}[$idx], {%$state, "errors", \@errors, "schema_path", $state->{'schema_path'} . "/anyOf/" . $idx})
665 98 141 if $state->{'short_circuit'}
668 202 92 if $valid
679 533 377 unless _eval_subschema($data, $schema->{'oneOf'}[$idx], {%$state, "errors", \@errors, "schema_path", $state->{'schema_path'} . "/oneOf/" . $idx})
681 44 47 if @valid > 1 and $state->{'short_circuit'}
684 157 201 if @valid == 1
686 123 78 if (not @valid) { }
697 39 84 unless _eval_subschema($data, $schema->{'not'}, {%$state, "schema_path", $state->{'schema_path'} . "/not", "short_circuit", 1, "errors", []})
703 28 40 unless exists $schema->{'then'} or exists $schema->{'else'}
705 132 138 _eval_subschema($data, $schema->{'if'}, {%$state, 'schema_path', $state->{'schema_path'} . '/if', 'short_circuit', 1, 'errors', []}) ? :
708 46 224 unless exists $schema->{$keyword}
710 136 70 if _eval_subschema($data, $schema->{$keyword}, {%$state, "schema_path", $state->{'schema_path'} . "/" . $keyword})
717 124 173 unless is_type("object", $data)
723 110 89 if not exists $data->{$property} or _eval_subschema($data, $schema->{'dependentSchemas'}{$property}, {%$state, "schema_path", jsonp($state->{'schema_path'}, "dependentSchemas", $property)})
726 44 45 if $state->{'short_circuit'}
729 89 84 unless $valid
736 67 111 unless is_type("object", $data)
740 52 106 if (is_type('array', $schema->{'dependencies'}{$property})) { }
745 0 62 unless is_type("string", $schema->{'dependencies'}{$property}[$index])
749 0 52 unless is_elements_unique($schema->{'dependencies'}{$property})
751 28 24 unless exists $data->{$property}
753 14 10 if (my(@missing) = grep((!exists $data->{$_}), @{$$schema{"dependencies"}{$property}}))
754 3 11 @missing > 1 ? :
762 63 43 if not exists $data->{$property} or _eval_subschema($data, $schema->{'dependencies'}{$property}, {%$state, "schema_path", jsonp($state->{'schema_path'}, "dependencies", $property)})
765 21 22 if $state->{'short_circuit'}
769 56 55 if $valid
802 0 395 unless assert_array_schemas($schema, $state)
807 684 600 if (XXX)
809 1 683 if ($state->{'spec_version'} // "") eq "draft2020-12"
819 32 183 unless exists $state->{'_last_items_index'}
825 0 1078 unless @{$$schema{$state->{'keyword'}}}
826 213 865 unless is_type("array", $data)
831 269 1250 if $idx > $#{$$schema{$state->{'keyword'}}}
834 274 976 if (is_type('boolean', $$schema{$state->{'keyword'}}[$idx])) { }
835 166 108 if $$schema{$state->{'keyword'}}[$idx]
842 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})
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 693 unless $valid
858 104 679 unless is_type("array", $data)
859 238 441 if $state->{'_last_items_index'} == $#$data
863 26 641 if (is_type('boolean', $$schema{$state->{'keyword'}}) and $state->{'keyword'} eq 'additionalItems') { }
865 6 20 if $$schema{$state->{'keyword'}}
868 20 0 exists $schema->{'prefixItems'} || $state->{'keyword'} eq 'additionalItems' ? :
873 360 216 if _eval_subschema($data->[$idx], $$schema{$state->{'keyword'}}, {%$state, "data_path", $state->{'data_path'} . "/" . $idx, "schema_path", $state->{'schema_path'} . "/" . $state->{'keyword'}})
877 87 149 if $state->{'short_circuit'}
883 53 144 exists $schema->{'prefixItems'} || $state->{'keyword'} eq 'additionalItems' ? :
197 179 unless $valid
889 213 496 unless is_type("array", $data)
894 385 229 if (_eval_subschema($data->[$idx], $schema->{'contains'}, {%$state, "errors", \@errors, "data_path", $state->{'data_path'} . "/" . $idx, "schema_path", $state->{'schema_path'} . "/contains"}))
902 124 60 if $state->{'short_circuit'} and !exists $schema->{'maxContains'} || $state->{'_num_contains'} > $schema->{'maxContains'} and $state->{'_num_contains'} >= ($schema->{'minContains'} // 1)
907 195 12 if (not $state->{'_num_contains'} and ($schema->{'minContains'} // 1) > 0 || $state->{'spec_version'} && $state->{'spec_version'} eq 'draft7')
918 251 2032 unless is_type("object", $data)
922 1001 1586 unless exists $data->{$property}
924 323 1263 if (is_type('boolean', $schema->{'properties'}{$property})) { }
925 217 106 if $schema->{'properties'}{$property}
933 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)})
937 201 220 if $state->{'short_circuit'}
940 399 1486 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 520 unless is_type("object", $data)
982 110 67 if exists $schema->{'properties'} and exists $schema->{'properties'}{$property}
984 88 305 if exists $schema->{'patternProperties'} and &any(sub {
986 164 141 if (is_type('boolean', $schema->{'additionalProperties'})) { }
987 16 148 if $schema->{'additionalProperties'}
996 52 37 if _eval_subschema($data->{$property}, $schema->{'additionalProperties'}, {%$state, "data_path", jsonp($state->{'data_path'}, $property), "schema_path", $state->{'schema_path'} . "/additionalProperties"})
1000 90 95 if $state->{'short_circuit'}
1003 184 284 unless $valid
1008 175 238 unless is_type("object", $data)
1015 50 104 if _eval_subschema($property, $schema->{'propertyNames'}, {%$state, "data_path", jsonp($state->{'data_path'}, $property), "schema_path", $state->{'schema_path'} . "/propertyNames"})
1018 55 49 if $state->{'short_circuit'}
1021 104 134 unless $valid
1036 71 50420 if ($type eq "null")
1039 5295 45125 if ($type eq "boolean")
1042 11605 33520 if ($type eq "object")
1045 8569 24951 if ($type eq "array")
1049 8938 18 if ($type eq "string" or $type eq "number" or $type eq "integer")
1050 18 24915 unless defined $value
1053 15981 8934 if ($type eq "string")
1057 6067 2867 if ($type eq "number")
1062 2867 0 if ($type eq "integer")
1068 14 4 if ($type =~ /^reference to (.+)$/u)
1076 288 33050 unless defined $value
1077 21092 11958 if XXX
1078 1111 10847 if XXX
1079 1942 8905 if is_bool($value)
1081 270 81 $value->is_int ? :
3 76 &blessed($value) ? :
351 79 ref($value) =~ /^Math::Big(?:Int|Float)$/u ? :
430 8475 if XXX
1086 4288 4187 if $flags & 1024 and not $flags & 768
1087 4183 3 int $value == $value ? :
4186 1 if not $flags & 1024 and $flags & 768
1102 93 3776 if ($SCALARREF_BOOLEANS)
1103 10 83 if $types[0] eq "reference to SCALAR"
1104 17 76 if $types[1] eq "reference to SCALAR"
1107 817 3052 if $types[0] ne $types[1]
1108 14 3038 if $types[0] eq "null"
1109 1429 1609 if $types[0] eq "string"
1110 1079 530 if grep(($types[0] eq $_), ("boolean", "number", "integer"))
1113 208 322 if ($types[0] eq "object")
1114 16 192 if keys %$x != keys %$y
1115 6 186 unless is_equal([sort(keys %$x)], [sort(keys %$y)])
1118 86 132 unless is_equal($x->{$property}, $y->{$property}, $state)
1123 322 0 if ($types[0] eq "array")
1124 8 314 if @$x != @$y
1127 88 264 unless is_equal($x->[$idx], $y->[$idx], $state)
1140 201 1040 if (is_equal($array->[$idx0], $array->[$idx1]))
1141 201 0 if defined $equal_indices
1151 1 24484 XXX ? :
1156 1 30397 if @extra_path and XXX
1159 12664 17734 unless length $uri->fragment
1171 8169 1247 if $uri eq "" and $keyword_location eq "" or ($uri->fragment // "") eq $keyword_location and $uri->clone->fragment(undef) eq ""
1176 1247 8169 defined $uri ? :
4626 4790 @args ? :
1198 0 0 XXX ? :
4 0 XXX ? :
4 26791 if exists $state->{'_schema_path_suffix'}
1199 26787 8 if is_type($type, $value)
1200 2 6 $type =~ /^[aeiou]/u ? :
1217 0 1129 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
1231 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
1247 0 2780 if $$schema{$state->{'keyword'}} < 0
1253 0 1886 unless @{$$schema{$state->{'keyword'}}}
1259 66 905 ref($value) =~ /^Math::Big(?:Int|Float)$/u ? :