Skip to content

Commit 5b9baeb

Browse files
authored
Add proper Draft 3 type trace tests (#782)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent bac3ea7 commit 5b9baeb

6 files changed

Lines changed: 2083 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ if(PROJECT_IS_TOP_LEVEL)
104104
add_custom_target(blaze_format_trace_json
105105
COMMAND "${Python3_EXECUTABLE}"
106106
"${PROJECT_SOURCE_DIR}/contrib/format_trace_json.py"
107+
"${PROJECT_SOURCE_DIR}/test/evaluator/evaluator_draft3.json"
107108
"${PROJECT_SOURCE_DIR}/test/evaluator/evaluator_draft4.json"
108109
"${PROJECT_SOURCE_DIR}/test/evaluator/evaluator_draft6.json"
109110
"${PROJECT_SOURCE_DIR}/test/evaluator/evaluator_draft7.json"

src/compiler/default_compiler_draft3.h

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,28 @@ auto properties_as_loop(const Context &context,
389389
}));
390390
}
391391

392+
auto draft3_any_type_instructions(const Context &context,
393+
const SchemaContext &schema_context,
394+
const DynamicContext &dynamic_context)
395+
-> Instructions {
396+
if (context.mode != Mode::Exhaustive) {
397+
return {};
398+
}
399+
400+
using sourcemeta::core::JSON;
401+
ValueTypes types{};
402+
types.set(std::to_underlying(JSON::Type::Null));
403+
types.set(std::to_underlying(JSON::Type::Boolean));
404+
types.set(std::to_underlying(JSON::Type::Object));
405+
types.set(std::to_underlying(JSON::Type::Array));
406+
types.set(std::to_underlying(JSON::Type::Integer));
407+
types.set(std::to_underlying(JSON::Type::Real));
408+
types.set(std::to_underlying(JSON::Type::Decimal));
409+
types.set(std::to_underlying(JSON::Type::String));
410+
return {make(sourcemeta::blaze::InstructionIndex::AssertionTypeStrictAny,
411+
context, schema_context, dynamic_context, types)};
412+
}
413+
392414
auto draft3_set_type_bits(const std::string &name, ValueTypes &types) -> bool {
393415
using sourcemeta::core::JSON;
394416
if (name == "null") {
@@ -1857,21 +1879,29 @@ auto compiler_draft3_validation_type(const Context &context,
18571879

18581880
if (is_draft3) {
18591881
if (value.is_string() && value.to_string() == "any") {
1860-
return {};
1882+
return draft3_any_type_instructions(context, schema_context,
1883+
dynamic_context);
18611884
}
18621885

18631886
if (value.is_array()) {
18641887
bool has_object{false};
18651888
for (const auto &element : value.as_array()) {
18661889
if (element.is_string() && element.to_string() == "any") {
1867-
return {};
1890+
return draft3_any_type_instructions(context, schema_context,
1891+
dynamic_context);
18681892
}
18691893
if (element.is_object()) {
18701894
has_object = true;
18711895
}
18721896
}
18731897

18741898
if (has_object) {
1899+
if (context.mode == Mode::FastValidation && value.size() == 1) {
1900+
return compile(
1901+
context, schema_context, dynamic_context,
1902+
{static_cast<sourcemeta::core::Pointer::Token::Index>(0)});
1903+
}
1904+
18751905
Instructions disjunctors;
18761906
for (std::uint64_t index = 0; index < value.size(); index++) {
18771907
const auto &element{value.at(index)};
@@ -2167,7 +2197,11 @@ auto compiler_draft3_validation_type(const Context &context,
21672197
}
21682198
}
21692199

2170-
assert(types.any());
2200+
if (!types.any()) {
2201+
return {make(sourcemeta::blaze::InstructionIndex::AssertionFail, context,
2202+
schema_context, dynamic_context, ValueNone{})};
2203+
}
2204+
21712205
return {make(sourcemeta::blaze::InstructionIndex::AssertionTypeStrictAny,
21722206
context, schema_context, dynamic_context, types)};
21732207
}

test/evaluator/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ sourcemeta_googletest(NAMESPACE sourcemeta PROJECT blaze NAME evaluator
44
evaluator_utils.h
55
evaluator_2019_09_test.cc
66
evaluator_2020_12_test.cc
7+
evaluator_draft3_test.cc
78
evaluator_draft4_test.cc
89
evaluator_draft6_test.cc
910
evaluator_draft7_test.cc

0 commit comments

Comments
 (0)