diff --git a/src/ir/ir_default_compiler.h b/src/ir/ir_default_compiler.h index c7edc38..745888f 100644 --- a/src/ir/ir_default_compiler.h +++ b/src/ir/ir_default_compiler.h @@ -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"); \ } \ } \ } @@ -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"); } } diff --git a/test/ir/CMakeLists.txt b/test/ir/CMakeLists.txt index 71da014..a91d037 100644 --- a/test/ir/CMakeLists.txt +++ b/test/ir/CMakeLists.txt @@ -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) diff --git a/test/ir/ir_test.cc b/test/ir/ir_test.cc new file mode 100644 index 0000000..d7e7797 --- /dev/null +++ b/test/ir/ir_test.cc @@ -0,0 +1,71 @@ +#include + +#include +#include + +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); +}