|
| 1 | +#include <gtest/gtest.h> |
| 2 | + |
| 3 | +#include <sourcemeta/codegen/ir.h> |
| 4 | +#include <sourcemeta/core/jsonschema.h> |
| 5 | + |
| 6 | +TEST(IR, unsupported_dialect_draft3) { |
| 7 | + const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({ |
| 8 | + "$schema": "http://json-schema.org/draft-03/schema#", |
| 9 | + "type": "string" |
| 10 | + })JSON")}; |
| 11 | + |
| 12 | + EXPECT_THROW( |
| 13 | + sourcemeta::codegen::compile(schema, sourcemeta::core::schema_walker, |
| 14 | + sourcemeta::core::schema_resolver, |
| 15 | + sourcemeta::codegen::default_compiler), |
| 16 | + sourcemeta::core::SchemaVocabularyError); |
| 17 | +} |
| 18 | + |
| 19 | +TEST(IR, unsupported_keyword_error) { |
| 20 | + const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({ |
| 21 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 22 | + "type": "string", |
| 23 | + "if": { "minLength": 5 }, |
| 24 | + "then": { "maxLength": 10 } |
| 25 | + })JSON")}; |
| 26 | + |
| 27 | + EXPECT_THROW( |
| 28 | + sourcemeta::codegen::compile(schema, sourcemeta::core::schema_walker, |
| 29 | + sourcemeta::core::schema_resolver, |
| 30 | + sourcemeta::codegen::default_compiler), |
| 31 | + sourcemeta::codegen::UnsupportedKeywordError); |
| 32 | +} |
| 33 | + |
| 34 | +TEST(IR, unsupported_keyword_value_error_type_not_string) { |
| 35 | + const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({ |
| 36 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 37 | + "type": 123 |
| 38 | + })JSON")}; |
| 39 | + |
| 40 | + EXPECT_THROW( |
| 41 | + sourcemeta::codegen::compile(schema, sourcemeta::core::schema_walker, |
| 42 | + sourcemeta::core::schema_resolver, |
| 43 | + sourcemeta::codegen::default_compiler), |
| 44 | + sourcemeta::codegen::UnsupportedKeywordValueError); |
| 45 | +} |
| 46 | + |
| 47 | +TEST(IR, unsupported_keyword_value_error_unknown_type) { |
| 48 | + const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({ |
| 49 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 50 | + "type": "foo" |
| 51 | + })JSON")}; |
| 52 | + |
| 53 | + EXPECT_THROW( |
| 54 | + sourcemeta::codegen::compile(schema, sourcemeta::core::schema_walker, |
| 55 | + sourcemeta::core::schema_resolver, |
| 56 | + sourcemeta::codegen::default_compiler), |
| 57 | + sourcemeta::codegen::UnsupportedKeywordValueError); |
| 58 | +} |
| 59 | + |
| 60 | +TEST(IR, unexpected_schema_error_unsupported_shape) { |
| 61 | + const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({ |
| 62 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 63 | + "not": { "type": "string" } |
| 64 | + })JSON")}; |
| 65 | + |
| 66 | + EXPECT_THROW( |
| 67 | + sourcemeta::codegen::compile(schema, sourcemeta::core::schema_walker, |
| 68 | + sourcemeta::core::schema_resolver, |
| 69 | + sourcemeta::codegen::default_compiler), |
| 70 | + sourcemeta::codegen::UnexpectedSchemaError); |
| 71 | +} |
0 commit comments