Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/ir/ir_default_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
if (!allowed.contains(entry.first)) { \
throw sourcemeta::codegen::UnsupportedKeywordError( \
(schema), (pointer), entry.first, \
"Unexpected keyword in subschema"); \
"Unsupported keyword in subschema"); \
} \
} \
}
Expand Down Expand Up @@ -497,8 +497,7 @@ auto default_compiler(const sourcemeta::core::JSON &schema,
return handle_ref(schema, frame, location, vocabularies, resolver,
subschema);
} else {
throw UnexpectedSchemaError(schema, location.pointer,
"Unsupported subschema");
throw UnexpectedSchemaError(schema, location.pointer, "Unsupported schema");
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/ir/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sourcemeta_googletest(NAMESPACE sourcemeta PROJECT codegen NAME ir
FOLDER "Codegen/IR"
SOURCES ir_2020_12_test.cc ir_symbol_test.cc ir_test_utils.h)
SOURCES ir_test.cc ir_2020_12_test.cc ir_symbol_test.cc ir_test_utils.h)

target_link_libraries(sourcemeta_codegen_ir_unit
PRIVATE sourcemeta::codegen::ir)
71 changes: 71 additions & 0 deletions test/ir/ir_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <gtest/gtest.h>

#include <sourcemeta/codegen/ir.h>
#include <sourcemeta/core/jsonschema.h>

TEST(IR, unsupported_dialect_draft3) {
const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({
"$schema": "http://json-schema.org/draft-03/schema#",
"type": "string"
})JSON")};

EXPECT_THROW(
sourcemeta::codegen::compile(schema, sourcemeta::core::schema_walker,
sourcemeta::core::schema_resolver,
sourcemeta::codegen::default_compiler),
sourcemeta::core::SchemaVocabularyError);
}

TEST(IR, unsupported_keyword_error) {
const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"if": { "minLength": 5 },
"then": { "maxLength": 10 }
})JSON")};

EXPECT_THROW(
sourcemeta::codegen::compile(schema, sourcemeta::core::schema_walker,
sourcemeta::core::schema_resolver,
sourcemeta::codegen::default_compiler),
sourcemeta::codegen::UnsupportedKeywordError);
}

TEST(IR, unsupported_keyword_value_error_type_not_string) {
const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": 123
})JSON")};

EXPECT_THROW(
sourcemeta::codegen::compile(schema, sourcemeta::core::schema_walker,
sourcemeta::core::schema_resolver,
sourcemeta::codegen::default_compiler),
sourcemeta::codegen::UnsupportedKeywordValueError);
}

TEST(IR, unsupported_keyword_value_error_unknown_type) {
const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "foo"
})JSON")};

EXPECT_THROW(
sourcemeta::codegen::compile(schema, sourcemeta::core::schema_walker,
sourcemeta::core::schema_resolver,
sourcemeta::codegen::default_compiler),
sourcemeta::codegen::UnsupportedKeywordValueError);
}

TEST(IR, unexpected_schema_error_unsupported_shape) {
const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"not": { "type": "string" }
})JSON")};

EXPECT_THROW(
sourcemeta::codegen::compile(schema, sourcemeta::core::schema_walker,
sourcemeta::core::schema_resolver,
sourcemeta::codegen::default_compiler),
sourcemeta::codegen::UnexpectedSchemaError);
}