|
1 | 1 | #include <gtest/gtest.h> |
2 | 2 |
|
| 3 | +#include <sourcemeta/blaze/compiler_error.h> |
3 | 4 | #include <sourcemeta/core/json.h> |
4 | 5 |
|
5 | 6 | #include "alterschema_test_utils.h" |
@@ -4456,3 +4457,47 @@ TEST(AlterSchema_lint_draft7, quintuple_negation_to_single) { |
4456 | 4457 |
|
4457 | 4458 | EXPECT_EQ(document, expected); |
4458 | 4459 | } |
| 4460 | + |
| 4461 | +TEST(AlterSchema_lint_draft7, valid_default_throws_on_invalid_ref_target) { |
| 4462 | + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ |
| 4463 | + "$schema": "http://json-schema.org/draft-07/schema#", |
| 4464 | + "allOf": [ |
| 4465 | + { "$ref": "#/$defs/foo" } |
| 4466 | + ], |
| 4467 | + "$defs": { |
| 4468 | + "foo": { "type": "string" } |
| 4469 | + }, |
| 4470 | + "default": "test" |
| 4471 | + })JSON"); |
| 4472 | + |
| 4473 | + sourcemeta::blaze::SchemaTransformer bundle; |
| 4474 | + sourcemeta::blaze::add(bundle, sourcemeta::blaze::AlterSchemaMode::Linter); |
| 4475 | + EXPECT_THROW(static_cast<void>( |
| 4476 | + bundle.check(document, sourcemeta::core::schema_walker, |
| 4477 | + alterschema_test_resolver, |
| 4478 | + [](const auto &, const auto &, const auto &, |
| 4479 | + const auto &, const auto &) {})), |
| 4480 | + sourcemeta::blaze::CompilerReferenceTargetNotSchemaError); |
| 4481 | +} |
| 4482 | + |
| 4483 | +TEST(AlterSchema_lint_draft7, valid_examples_throws_on_invalid_ref_target) { |
| 4484 | + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ |
| 4485 | + "$schema": "http://json-schema.org/draft-07/schema#", |
| 4486 | + "allOf": [ |
| 4487 | + { "$ref": "#/$defs/foo" } |
| 4488 | + ], |
| 4489 | + "$defs": { |
| 4490 | + "foo": { "type": "string" } |
| 4491 | + }, |
| 4492 | + "examples": [ "test" ] |
| 4493 | + })JSON"); |
| 4494 | + |
| 4495 | + sourcemeta::blaze::SchemaTransformer bundle; |
| 4496 | + sourcemeta::blaze::add(bundle, sourcemeta::blaze::AlterSchemaMode::Linter); |
| 4497 | + EXPECT_THROW(static_cast<void>( |
| 4498 | + bundle.check(document, sourcemeta::core::schema_walker, |
| 4499 | + alterschema_test_resolver, |
| 4500 | + [](const auto &, const auto &, const auto &, |
| 4501 | + const auto &, const auto &) {})), |
| 4502 | + sourcemeta::blaze::CompilerReferenceTargetNotSchemaError); |
| 4503 | +} |
0 commit comments