Skip to content

Commit ec82307

Browse files
authored
Fix SimpleOutput not reporting contains annotations (#423)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent b37258d commit ec82307

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

src/compiler/compile_output_simple.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ auto SimpleOutput::operator()(
7171
this->mask.emplace(evaluate_path, false);
7272
}
7373
} else if (type == EvaluationType::Post &&
74-
this->mask.contains(evaluate_path)) {
74+
this->mask.contains(evaluate_path) &&
75+
76+
// TODO: We only have to do this because "contains" emits this
77+
// instructions, when it should not
78+
step.type != InstructionIndex::ControlEvaluate) {
7579
this->mask.erase(evaluate_path);
7680
}
7781

test/compiler/compiler_output_simple_test.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,42 @@ TEST(Compiler_output_simple, annotations_success_8) {
767767
0, sourcemeta::core::JSON{true});
768768
}
769769

770+
TEST(Compiler_output_simple, annotations_success_9) {
771+
const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({
772+
"$schema": "https://json-schema.org/draft/2020-12/schema",
773+
"contains": { "type": "boolean" },
774+
"unevaluatedItems": { "type": "number" }
775+
})JSON")};
776+
777+
const auto schema_template{sourcemeta::blaze::compile(
778+
schema, sourcemeta::core::schema_official_walker,
779+
sourcemeta::core::schema_official_resolver,
780+
sourcemeta::blaze::default_schema_compiler,
781+
sourcemeta::blaze::Mode::Exhaustive)};
782+
783+
const sourcemeta::core::JSON instance{
784+
sourcemeta::core::parse_json("[ true, 1, false, 2 ]")};
785+
786+
sourcemeta::blaze::SimpleOutput output{instance};
787+
sourcemeta::blaze::Evaluator evaluator;
788+
const auto result{
789+
evaluator.validate(schema_template, instance, std::ref(output))};
790+
EXPECT_TRUE(result);
791+
792+
EXPECT_ANNOTATION_COUNT(output, 2);
793+
794+
EXPECT_ANNOTATION_ENTRY(output, "", "/contains", "#/contains", 2);
795+
EXPECT_ANNOTATION_VALUE(output, "", "/contains", "#/contains", 0,
796+
sourcemeta::core::JSON{0});
797+
EXPECT_ANNOTATION_VALUE(output, "", "/contains", "#/contains", 1,
798+
sourcemeta::core::JSON{2});
799+
800+
EXPECT_ANNOTATION_ENTRY(output, "", "/unevaluatedItems", "#/unevaluatedItems",
801+
1);
802+
EXPECT_ANNOTATION_VALUE(output, "", "/unevaluatedItems", "#/unevaluatedItems",
803+
0, sourcemeta::core::JSON{true});
804+
}
805+
770806
TEST(Compiler_output_simple, annotations_failure_1) {
771807
const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({
772808
"$schema": "https://json-schema.org/draft/2020-12/schema",

0 commit comments

Comments
 (0)