Skip to content

Commit

Permalink
Test oneOf smart properties short-circuit checks (#1265)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Oct 4, 2024
1 parent b61df71 commit a96af18
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions test/evaluator/evaluator_draft4_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2915,6 +2915,109 @@ TEST(JSONSchema_evaluator_draft4, oneOf_4) {
"The number value was expected to validate against the given subschema");
}

TEST(JSONSchema_evaluator_draft4, oneOf_5) {
const sourcemeta::jsontoolkit::JSON schema{
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "http://json-schema.org/draft-04/schema#",
"oneOf": [
{
"properties": {
"version": { "enum": [ 1 ] },
"one": { "items": { "type": "integer" } },
"two": { "items": { "type": "boolean" } },
"three": { "items": { "type": "object" } }
}
},
{
"properties": {
"version": { "enum": [ 2 ] },
"one": { "type": "string" }
}
},
{
"properties": {
"version": { "enum": [ 3 ] },
"one": { "items": { "type": "integer" } },
"two": { "items": { "type": "boolean" } },
"three": { "items": { "type": "object" } }
}
}
]
})JSON")};

const auto compiled_schema{sourcemeta::jsontoolkit::compile(
schema, sourcemeta::jsontoolkit::default_schema_walker,
sourcemeta::jsontoolkit::official_resolver,
sourcemeta::jsontoolkit::default_schema_compiler)};

const sourcemeta::jsontoolkit::JSON instance{
sourcemeta::jsontoolkit::parse("{ \"version\": 2, \"one\": \"two\" }")};

EVALUATE_WITH_TRACE_FAST_SUCCESS(compiled_schema, instance, 8);

EVALUATE_TRACE_PRE(0, LogicalXor, "/oneOf", "#/oneOf", "");
EVALUATE_TRACE_PRE(1, LogicalAnd, "/oneOf/0/properties",
"#/oneOf/0/properties", "");
EVALUATE_TRACE_PRE(2, AssertionEqual, "/oneOf/0/properties/version/enum",
"#/oneOf/0/properties/version/enum", "/version");
EVALUATE_TRACE_PRE(3, LogicalAnd, "/oneOf/1/properties",
"#/oneOf/1/properties", "");
EVALUATE_TRACE_PRE(4, AssertionPropertyTypeStrict,
"/oneOf/1/properties/one/type",
"#/oneOf/1/properties/one/type", "/one");
EVALUATE_TRACE_PRE(5, AssertionEqual, "/oneOf/1/properties/version/enum",
"#/oneOf/1/properties/version/enum", "/version");
EVALUATE_TRACE_PRE(6, LogicalAnd, "/oneOf/2/properties",
"#/oneOf/2/properties", "");
EVALUATE_TRACE_PRE(7, AssertionEqual, "/oneOf/2/properties/version/enum",
"#/oneOf/2/properties/version/enum", "/version");

EVALUATE_TRACE_POST_FAILURE(0, AssertionEqual,
"/oneOf/0/properties/version/enum",
"#/oneOf/0/properties/version/enum", "/version");
EVALUATE_TRACE_POST_FAILURE(1, LogicalAnd, "/oneOf/0/properties",
"#/oneOf/0/properties", "");
EVALUATE_TRACE_POST_SUCCESS(2, AssertionPropertyTypeStrict,
"/oneOf/1/properties/one/type",
"#/oneOf/1/properties/one/type", "/one");
EVALUATE_TRACE_POST_SUCCESS(3, AssertionEqual,
"/oneOf/1/properties/version/enum",
"#/oneOf/1/properties/version/enum", "/version");
EVALUATE_TRACE_POST_SUCCESS(4, LogicalAnd, "/oneOf/1/properties",
"#/oneOf/1/properties", "");
EVALUATE_TRACE_POST_FAILURE(5, AssertionEqual,
"/oneOf/2/properties/version/enum",
"#/oneOf/2/properties/version/enum", "/version");
EVALUATE_TRACE_POST_FAILURE(6, LogicalAnd, "/oneOf/2/properties",
"#/oneOf/2/properties", "");
EVALUATE_TRACE_POST_SUCCESS(7, LogicalXor, "/oneOf", "#/oneOf", "");

EVALUATE_TRACE_POST_DESCRIBE(
instance, 0,
"The integer value 2 was expected to equal the integer constant 1");
EVALUATE_TRACE_POST_DESCRIBE(instance, 1,
"The object value was expected to validate "
"against the defined properties subschemas");
EVALUATE_TRACE_POST_DESCRIBE(instance, 2,
"The value was expected to be of type string");
EVALUATE_TRACE_POST_DESCRIBE(
instance, 3,
"The integer value 2 was expected to equal the integer constant 2");
EVALUATE_TRACE_POST_DESCRIBE(instance, 4,
"The object value was expected to validate "
"against the defined properties subschemas");
EVALUATE_TRACE_POST_DESCRIBE(
instance, 5,
"The integer value 2 was expected to equal the integer constant 3");
EVALUATE_TRACE_POST_DESCRIBE(instance, 6,
"The object value was expected to validate "
"against the defined properties subschemas");
EVALUATE_TRACE_POST_DESCRIBE(
instance, 7,
"The object value was expected to validate against one and only one of "
"the 3 given subschemas");
}

TEST(JSONSchema_evaluator_draft4, dependencies_1) {
const sourcemeta::jsontoolkit::JSON schema{
sourcemeta::jsontoolkit::parse(R"JSON({
Expand Down

4 comments on commit a96af18

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (macos/llvm)

Benchmark suite Current: a96af18 Previous: b61df71 Ratio
JSON_Array_Of_Objects_Unique 3772.666168375686 ns/iter 4228.983833536213 ns/iter 0.89
JSONSchema_Validate_Draft4_Meta_1_No_Callback 798.8218122838375 ns/iter 756.8970007657384 ns/iter 1.06
JSONSchema_Validate_Draft4_Required_Properties 984.8737681073043 ns/iter 944.3472298982031 ns/iter 1.04
JSONSchema_Validate_Draft4_Many_Optional_Properties_Minimal_Match 161.7606787317781 ns/iter 163.10640559463337 ns/iter 0.99
JSONSchema_Validate_Draft4_Few_Optional_Properties_Minimal_Match 108.23454075527242 ns/iter 110.2332090922805 ns/iter 0.98
JSONSchema_Validate_Draft4_Items_Schema 2907.0150849245283 ns/iter 2997.754831915101 ns/iter 0.97
JSONSchema_Validate_Draft4_Nested_Object 1396.4825398588503 ns/iter 1425.7948252337903 ns/iter 0.98
JSONSchema_Validate_Draft4_Properties_Triad_Optional 1441.0745587386216 ns/iter 1407.773732902339 ns/iter 1.02
JSONSchema_Validate_Draft4_Properties_Triad_Closed 1084.2239261613552 ns/iter 1127.4141609006783 ns/iter 0.96
JSONSchema_Validate_Draft4_Properties_Triad_Required 1492.663575334233 ns/iter 1447.88217283138 ns/iter 1.03
JSONSchema_Validate_Draft4_Non_Recursive_Ref 210.09074203237444 ns/iter 199.9800586967782 ns/iter 1.05
JSONSchema_Validate_Draft4_Pattern_Properties_True 1473.984636420372 ns/iter 1422.2993634325308 ns/iter 1.04
JSONSchema_Validate_Draft4_Ref_To_Single_Property 113.56637504633795 ns/iter 118.82817779364315 ns/iter 0.96
JSONSchema_Validate_Draft4_Additional_Properties_Type 378.5809854852923 ns/iter 431.2833290797157 ns/iter 0.88
JSONSchema_Validate_Draft4_Nested_Oneof 395.5197416313751 ns/iter 388.48040997733597 ns/iter 1.02
JSONSchema_Validate_Draft6_Property_Names 828.272124823517 ns/iter 798.4428659732785 ns/iter 1.04
JSONSchema_Validate_Draft7_If_Then_Else 181.41307257638772 ns/iter 175.58734697807049 ns/iter 1.03
JSONSchema_Compiler_Draft6_AdaptiveCard 3205865166.999956 ns/iter 3289723541.9999332 ns/iter 0.97

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/llvm)

Benchmark suite Current: a96af18 Previous: b61df71 Ratio
JSON_Array_Of_Objects_Unique 2130.281557214664 ns/iter 2125.466187203498 ns/iter 1.00
JSONSchema_Validate_Draft4_Meta_1_No_Callback 977.0449984502455 ns/iter 969.8297490641231 ns/iter 1.01
JSONSchema_Validate_Draft4_Required_Properties 1524.52299449641 ns/iter 1550.6650848154436 ns/iter 0.98
JSONSchema_Validate_Draft4_Many_Optional_Properties_Minimal_Match 179.07401254213346 ns/iter 178.66687902311585 ns/iter 1.00
JSONSchema_Validate_Draft4_Few_Optional_Properties_Minimal_Match 124.54725571924801 ns/iter 127.76845643075254 ns/iter 0.97
JSONSchema_Validate_Draft4_Items_Schema 3924.226127206713 ns/iter 4021.3208777623354 ns/iter 0.98
JSONSchema_Validate_Draft4_Nested_Object 1601.6905582110778 ns/iter 1623.690513745676 ns/iter 0.99
JSONSchema_Validate_Draft4_Properties_Triad_Optional 1833.571606347944 ns/iter 1830.8155239609716 ns/iter 1.00
JSONSchema_Validate_Draft4_Properties_Triad_Closed 1489.8944377184082 ns/iter 1522.9760682388805 ns/iter 0.98
JSONSchema_Validate_Draft4_Properties_Triad_Required 1946.970206136997 ns/iter 1918.1837939895374 ns/iter 1.02
JSONSchema_Validate_Draft4_Non_Recursive_Ref 478.5392142297824 ns/iter 484.9073095400828 ns/iter 0.99
JSONSchema_Validate_Draft4_Pattern_Properties_True 2492.8287404090147 ns/iter 2485.7303650443373 ns/iter 1.00
JSONSchema_Validate_Draft4_Ref_To_Single_Property 130.06606385632944 ns/iter 130.3317448280249 ns/iter 1.00
JSONSchema_Validate_Draft4_Additional_Properties_Type 596.402069900963 ns/iter 607.4604941581644 ns/iter 0.98
JSONSchema_Validate_Draft4_Nested_Oneof 481.59809131341433 ns/iter 501.29739099998005 ns/iter 0.96
JSONSchema_Validate_Draft6_Property_Names 1221.5853069156099 ns/iter 1266.1937730728878 ns/iter 0.96
JSONSchema_Validate_Draft7_If_Then_Else 213.65062247577202 ns/iter 216.23716011899097 ns/iter 0.99
JSONSchema_Compiler_Draft6_AdaptiveCard 5610572218.000015 ns/iter 5718458451.999936 ns/iter 0.98

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/gcc)

Benchmark suite Current: a96af18 Previous: b61df71 Ratio
JSONSchema_Compiler_Draft6_AdaptiveCard 6348054746.999992 ns/iter 6337498589.000006 ns/iter 1.00
JSONSchema_Validate_Draft4_Meta_1_No_Callback 1088.126740080621 ns/iter 1071.00218471577 ns/iter 1.02
JSONSchema_Validate_Draft4_Required_Properties 2206.4449579926536 ns/iter 2213.849232737453 ns/iter 1.00
JSONSchema_Validate_Draft4_Many_Optional_Properties_Minimal_Match 189.0431641560868 ns/iter 189.939282994826 ns/iter 1.00
JSONSchema_Validate_Draft4_Few_Optional_Properties_Minimal_Match 135.53462753011607 ns/iter 133.7014831079329 ns/iter 1.01
JSONSchema_Validate_Draft4_Items_Schema 3403.1124227470605 ns/iter 3323.038183948757 ns/iter 1.02
JSONSchema_Validate_Draft4_Nested_Object 1749.9168887323171 ns/iter 1728.2659043137805 ns/iter 1.01
JSONSchema_Validate_Draft4_Properties_Triad_Optional 1665.566032903209 ns/iter 1664.5526159290514 ns/iter 1.00
JSONSchema_Validate_Draft4_Properties_Triad_Closed 1348.5714959613802 ns/iter 1350.834848610817 ns/iter 1.00
JSONSchema_Validate_Draft4_Properties_Triad_Required 1746.903289475379 ns/iter 1752.186969079661 ns/iter 1.00
JSONSchema_Validate_Draft4_Non_Recursive_Ref 472.5515056974417 ns/iter 468.0941453933242 ns/iter 1.01
JSONSchema_Validate_Draft4_Pattern_Properties_True 2274.3214473859603 ns/iter 2260.2885569095783 ns/iter 1.01
JSONSchema_Validate_Draft4_Ref_To_Single_Property 140.50643940366206 ns/iter 143.19506605534158 ns/iter 0.98
JSONSchema_Validate_Draft4_Additional_Properties_Type 1110.7431182908397 ns/iter 1109.9155069693222 ns/iter 1.00
JSONSchema_Validate_Draft4_Nested_Oneof 428.7258172069613 ns/iter 429.05788632978897 ns/iter 1.00
JSONSchema_Validate_Draft6_Property_Names 1629.1300504728877 ns/iter 1653.3827042390626 ns/iter 0.99
JSONSchema_Validate_Draft7_If_Then_Else 203.53938163873653 ns/iter 203.44449435695464 ns/iter 1.00
JSON_Array_Of_Objects_Unique 3215.0072692228473 ns/iter 3192.926992207455 ns/iter 1.01

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (windows/msvc)

Benchmark suite Current: a96af18 Previous: b61df71 Ratio
JSON_Array_Of_Objects_Unique 5100.562999998601 ns/iter 5175.542857142342 ns/iter 0.99
JSONSchema_Validate_Draft4_Meta_1_No_Callback 2299.3671874999677 ns/iter 2275.7921874998033 ns/iter 1.01
JSONSchema_Validate_Draft4_Required_Properties 2073.748749999993 ns/iter 2082.5222349577925 ns/iter 1.00
JSONSchema_Validate_Draft4_Many_Optional_Properties_Minimal_Match 563.6942000001 ns/iter 549.6886000000814 ns/iter 1.03
JSONSchema_Validate_Draft4_Few_Optional_Properties_Minimal_Match 411.2463923550458 ns/iter 405.59359796460564 ns/iter 1.01
JSONSchema_Validate_Draft4_Items_Schema 6361.558035714715 ns/iter 6346.158035714415 ns/iter 1.00
JSONSchema_Validate_Draft4_Nested_Object 3893.939732142471 ns/iter 3838.726180846141 ns/iter 1.01
JSONSchema_Validate_Draft4_Properties_Triad_Optional 5349.292000000787 ns/iter 5329.37899999979 ns/iter 1.00
JSONSchema_Validate_Draft4_Properties_Triad_Closed 4358.120487445751 ns/iter 4358.736250000561 ns/iter 1.00
JSONSchema_Validate_Draft4_Properties_Triad_Required 5437.541071430019 ns/iter 5437.367999999196 ns/iter 1.00
JSONSchema_Validate_Draft4_Non_Recursive_Ref 568.3159999998679 ns/iter 559.1048214285925 ns/iter 1.02
JSONSchema_Validate_Draft4_Pattern_Properties_True 7959.120535715616 ns/iter 7977.271083610246 ns/iter 1.00
JSONSchema_Validate_Draft4_Ref_To_Single_Property 413.34818735354605 ns/iter 413.17045741501 ns/iter 1.00
JSONSchema_Validate_Draft4_Additional_Properties_Type 805.344283328414 ns/iter 798.640759535353 ns/iter 1.01
JSONSchema_Validate_Draft4_Nested_Oneof 1084.2971875000273 ns/iter 1066.4462499999418 ns/iter 1.02
JSONSchema_Validate_Draft6_Property_Names 1823.8151998348737 ns/iter 1847.3172743905548 ns/iter 0.99
JSONSchema_Validate_Draft7_If_Then_Else 566.0052999999152 ns/iter 566.4353571427837 ns/iter 1.00
JSONSchema_Compiler_Draft6_AdaptiveCard 11279013499.999792 ns/iter 11459921900.00004 ns/iter 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.