Skip to content

Commit

Permalink
Report all dependentSchemas steps
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Oct 17, 2024
1 parent 012b106 commit 884466b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
10 changes: 7 additions & 3 deletions src/compiler/compile_describe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,13 @@ struct DescribeVisitor {
return message.str();
}

auto operator()(const LogicalWhenDefines &step) const -> std::string {
std::ostringstream message;
message << "The object value defined the property \"" << step_value(step)
<< "\"";
return message.str();
}

auto operator()(const LogicalWhenType &step) const -> std::string {
if (this->keyword == "patternProperties") {
assert(!step.children.empty());
Expand Down Expand Up @@ -1686,9 +1693,6 @@ struct DescribeVisitor {
auto operator()(const LogicalWhenArraySizeEqual &) const -> std::string {
return unknown();
}
auto operator()(const LogicalWhenDefines &) const -> std::string {
return unknown();
}
auto operator()(const LoopPropertiesRegex &) const -> std::string {
return unknown();
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/default_compiler_2019_09.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ auto compiler_2019_09_applicator_dependentschemas(

if (!dependency.is_boolean() || !dependency.to_boolean()) {
children.push_back(make<LogicalWhenDefines>(
false, context, schema_context, relative_dynamic_context,
true, context, schema_context, relative_dynamic_context,
ValueString{dependent},
compile(context, schema_context, relative_dynamic_context,
{dependent}, sourcemeta::jsontoolkit::empty_pointer)));
Expand Down
40 changes: 29 additions & 11 deletions test/evaluator/evaluator_2019_09_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,24 +307,30 @@ TEST(Evaluator_2019_09, dependentSchemas_2) {

const sourcemeta::jsontoolkit::JSON instance{
sourcemeta::jsontoolkit::parse("{ \"qux\": 1, \"extra\": 2 }")};
EVALUATE_WITH_TRACE_FAST_SUCCESS(schema, instance, 2);
EVALUATE_WITH_TRACE_FAST_SUCCESS(schema, instance, 3);

EVALUATE_TRACE_PRE(0, LogicalWhenType, "/dependentSchemas",
"#/dependentSchemas", "");
EVALUATE_TRACE_PRE(1, AssertionDefines, "/dependentSchemas/qux/required",
EVALUATE_TRACE_PRE(1, LogicalWhenDefines, "/dependentSchemas",
"#/dependentSchemas", "");
EVALUATE_TRACE_PRE(2, AssertionDefines, "/dependentSchemas/qux/required",
"#/dependentSchemas/qux/required", "");

EVALUATE_TRACE_POST_SUCCESS(0, AssertionDefines,
"/dependentSchemas/qux/required",
"#/dependentSchemas/qux/required", "");
EVALUATE_TRACE_POST_SUCCESS(1, LogicalWhenType, "/dependentSchemas",
EVALUATE_TRACE_POST_SUCCESS(1, LogicalWhenDefines, "/dependentSchemas",
"#/dependentSchemas", "");
EVALUATE_TRACE_POST_SUCCESS(2, LogicalWhenType, "/dependentSchemas",
"#/dependentSchemas", "");

EVALUATE_TRACE_POST_DESCRIBE(
instance, 0,
"The object value was expected to define the property \"extra\"");
EVALUATE_TRACE_POST_DESCRIBE(instance, 1,
"The object value defined the property \"qux\"");
EVALUATE_TRACE_POST_DESCRIBE(
instance, 1,
instance, 2,
"Because the object value defined the property \"qux\", it was also "
"expected to validate against the corresponding subschema");
}
Expand Down Expand Up @@ -365,32 +371,44 @@ TEST(Evaluator_2019_09, dependentSchemas_4) {

const sourcemeta::jsontoolkit::JSON instance{sourcemeta::jsontoolkit::parse(
"{ \"foo\": 1, \"bar\": 2, \"baz\": 3, \"qux\": 4 }")};
EVALUATE_WITH_TRACE_FAST_SUCCESS(schema, instance, 3);
EVALUATE_WITH_TRACE_FAST_SUCCESS(schema, instance, 5);

EVALUATE_TRACE_PRE(0, LogicalWhenType, "/dependentSchemas",
"#/dependentSchemas", "");
EVALUATE_TRACE_PRE(1, AssertionDefines, "/dependentSchemas/baz/required",
EVALUATE_TRACE_PRE(1, LogicalWhenDefines, "/dependentSchemas",
"#/dependentSchemas", "");
EVALUATE_TRACE_PRE(2, AssertionDefines, "/dependentSchemas/baz/required",
"#/dependentSchemas/baz/required", "");
EVALUATE_TRACE_PRE(2, AssertionDefines, "/dependentSchemas/foo/required",
EVALUATE_TRACE_PRE(3, LogicalWhenDefines, "/dependentSchemas",
"#/dependentSchemas", "");
EVALUATE_TRACE_PRE(4, AssertionDefines, "/dependentSchemas/foo/required",
"#/dependentSchemas/foo/required", "");

EVALUATE_TRACE_POST_SUCCESS(0, AssertionDefines,
"/dependentSchemas/baz/required",
"#/dependentSchemas/baz/required", "");
EVALUATE_TRACE_POST_SUCCESS(1, AssertionDefines,
EVALUATE_TRACE_POST_SUCCESS(1, LogicalWhenDefines, "/dependentSchemas",
"#/dependentSchemas", "");
EVALUATE_TRACE_POST_SUCCESS(2, AssertionDefines,
"/dependentSchemas/foo/required",
"#/dependentSchemas/foo/required", "");
EVALUATE_TRACE_POST_SUCCESS(2, LogicalWhenType, "/dependentSchemas",
EVALUATE_TRACE_POST_SUCCESS(3, LogicalWhenDefines, "/dependentSchemas",
"#/dependentSchemas", "");
EVALUATE_TRACE_POST_SUCCESS(4, LogicalWhenType, "/dependentSchemas",
"#/dependentSchemas", "");

EVALUATE_TRACE_POST_DESCRIBE(
instance, 0,
"The object value was expected to define the property \"qux\"");
EVALUATE_TRACE_POST_DESCRIBE(instance, 1,
"The object value defined the property \"baz\"");
EVALUATE_TRACE_POST_DESCRIBE(
instance, 1,
instance, 2,
"The object value was expected to define the property \"bar\"");
EVALUATE_TRACE_POST_DESCRIBE(instance, 3,
"The object value defined the property \"foo\"");
EVALUATE_TRACE_POST_DESCRIBE(
instance, 2,
instance, 4,
"Because the object value defined the properties \"baz\", and \"foo\", "
"it was also expected to validate against the corresponding subschemas");
}
Expand Down

0 comments on commit 884466b

Please sign in to comment.