From 60323bc3ef9b2da7dd7a9261bce849b8b92543cd Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 23 Dec 2024 18:29:04 -0400 Subject: [PATCH] Mark subschemas in `.frame()` Signed-off-by: Juan Cruz Viotti --- src/jsonschema/frame.cc | 20 +++- .../sourcemeta/jsontoolkit/jsonschema_frame.h | 7 +- .../jsonschema_frame_2019_09_test.cc | 103 ++++++++++-------- .../jsonschema_frame_2020_12_test.cc | 83 +++++++------- .../jsonschema_frame_draft0_test.cc | 26 +++-- .../jsonschema_frame_draft1_test.cc | 26 +++-- .../jsonschema_frame_draft2_test.cc | 26 +++-- .../jsonschema_frame_draft3_test.cc | 28 +++-- .../jsonschema_frame_draft4_test.cc | 46 ++++---- .../jsonschema_frame_draft6_test.cc | 46 ++++---- .../jsonschema_frame_draft7_test.cc | 46 ++++---- test/jsonschema/jsonschema_frame_test.cc | 53 ++++----- test/jsonschema/jsonschema_test_utils.h | 24 ++++ 13 files changed, 323 insertions(+), 211 deletions(-) diff --git a/src/jsonschema/frame.cc b/src/jsonschema/frame.cc index 1a9461ae1..0dd1f0929 100644 --- a/src/jsonschema/frame.cc +++ b/src/jsonschema/frame.cc @@ -8,12 +8,11 @@ #include // std::less #include // std::map #include // std::optional +#include // std::set #include // std::ostringstream #include // std::pair, std::move #include // std::vector -#include - static auto find_nearest_bases(const std::map> &bases, const sourcemeta::jsontoolkit::Pointer &pointer, @@ -138,6 +137,7 @@ auto sourcemeta::jsontoolkit::frame( const std::optional &default_dialect, const std::optional &default_id) -> void { std::vector subschema_entries; + std::set subschemas; std::map> base_uris; std::map> @@ -186,6 +186,7 @@ auto sourcemeta::jsontoolkit::frame( // Store information subschema_entries.emplace_back(InternalEntry{entry, std::move(id)}); + subschemas.insert(entry.pointer); } for (const auto &entry : subschema_entries) { @@ -376,10 +377,17 @@ auto sourcemeta::jsontoolkit::frame( const auto nearest_bases{ find_nearest_bases(base_uris, pointer, base.first)}; assert(!nearest_bases.first.empty()); - store(frame, ReferenceType::Static, FrameLocationType::Pointer, result, - root_id, nearest_bases.first.front(), pointer, - pointer.resolve_from(nearest_bases.second), - dialects.first.front()); + if (subschemas.contains(pointer)) { + store(frame, ReferenceType::Static, FrameLocationType::Subschema, + result, root_id, nearest_bases.first.front(), pointer, + pointer.resolve_from(nearest_bases.second), + dialects.first.front()); + } else { + store(frame, ReferenceType::Static, FrameLocationType::Pointer, + result, root_id, nearest_bases.first.front(), pointer, + pointer.resolve_from(nearest_bases.second), + dialects.first.front()); + } } } } diff --git a/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_frame.h b/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_frame.h index ae5bf1964..8a491fe35 100644 --- a/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_frame.h +++ b/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_frame.h @@ -48,7 +48,12 @@ using FrameReferences = #endif /// @ingroup jsonschema /// The type of a location frame -enum class FrameLocationType : std::uint8_t { Resource, Anchor, Pointer }; +enum class FrameLocationType : std::uint8_t { + Resource, + Anchor, + Pointer, + Subschema +}; #if defined(__GNUC__) #pragma GCC diagnostic pop #endif diff --git a/test/jsonschema/jsonschema_frame_2019_09_test.cc b/test/jsonschema/jsonschema_frame_2019_09_test.cc index d58eeffb1..0410b4827 100644 --- a/test/jsonschema/jsonschema_frame_2019_09_test.cc +++ b/test/jsonschema/jsonschema_frame_2019_09_test.cc @@ -30,6 +30,14 @@ expected_base, expected_relative_pointer, \ expected_destination_of_size); +#define EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( \ + frame, reference, root_id, expected_pointer, expected_base, \ + expected_relative_pointer, expected_destination_of_size) \ + EXPECT_FRAME_STATIC_SUBSCHEMA( \ + frame, reference, root_id, expected_pointer, \ + "https://json-schema.org/draft/2019-09/schema", expected_base, \ + expected_relative_pointer, expected_destination_of_size); + #define EXPECT_FRAME_DYNAMIC_2019_09_ANCHOR( \ frame, reference, root_id, expected_pointer, expected_base, \ expected_relative_pointer, expected_destination_of_size) \ @@ -62,12 +70,12 @@ TEST(JSONSchema_frame_2019_09, anonymous_with_nested_schema_resource) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "https://example.com#/$id", "/additionalProperties/$id", "https://json-schema.org/draft/2019-09/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "https://json-schema.org/draft/2019-09/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalProperties", "/additionalProperties", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -155,7 +163,7 @@ TEST(JSONSchema_frame_2019_09, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/schema", "/items", 0); @@ -167,7 +175,7 @@ TEST(JSONSchema_frame_2019_09, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.sourcemeta.com/schema", "/properties", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", 0); @@ -230,7 +238,7 @@ TEST(JSONSchema_frame_2019_09, one_level_applicators_with_identifiers) { frame, "https://www.sourcemeta.com/test/qux#/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/test/qux#/items", "https://www.sourcemeta.com/test/qux", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -246,7 +254,7 @@ TEST(JSONSchema_frame_2019_09, one_level_applicators_with_identifiers) { frame, "https://www.sourcemeta.com/test/qux#/properties", "https://www.sourcemeta.com/test/qux", "/properties", "https://www.sourcemeta.com/test/qux", "/properties", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/test/qux#/properties/foo", "https://www.sourcemeta.com/test/qux", "/properties/foo", "https://www.sourcemeta.com/test/qux", "/properties/foo", 0); @@ -314,7 +322,7 @@ TEST(JSONSchema_frame_2019_09, subschema_absolute_identifier) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -422,7 +430,7 @@ TEST(JSONSchema_frame_2019_09, nested_schemas) { "https://www.sourcemeta.com/schema", "/properties", 0); // foo - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", "https://www.sourcemeta.com/foo", "", 0); @@ -434,7 +442,7 @@ TEST(JSONSchema_frame_2019_09, nested_schemas) { frame, "https://www.sourcemeta.com/schema#/properties/foo/$anchor", "https://www.sourcemeta.com/schema", "/properties/foo/$anchor", "https://www.sourcemeta.com/foo", "/$anchor", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo/items", "https://www.sourcemeta.com/schema", "/properties/foo/items", "https://www.sourcemeta.com/qux", "", 0); @@ -451,7 +459,7 @@ TEST(JSONSchema_frame_2019_09, nested_schemas) { frame, "https://www.sourcemeta.com/foo#/$anchor", "https://www.sourcemeta.com/schema", "/properties/foo/$anchor", "https://www.sourcemeta.com/foo", "/$anchor", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/foo#/items", "https://www.sourcemeta.com/schema", "/properties/foo/items", "https://www.sourcemeta.com/qux", "", 0); @@ -465,7 +473,7 @@ TEST(JSONSchema_frame_2019_09, nested_schemas) { "https://www.sourcemeta.com/qux", "/$id", 0); // bar - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/bar", "https://www.sourcemeta.com/schema", "/properties/bar", "https://www.sourcemeta.com/bar", "", 0); @@ -479,7 +487,7 @@ TEST(JSONSchema_frame_2019_09, nested_schemas) { "https://www.sourcemeta.com/bar", "/$id", 0); // baz - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/baz", "https://www.sourcemeta.com/schema", "/properties/baz", "https://www.sourcemeta.com/baz", "", 0); @@ -487,7 +495,7 @@ TEST(JSONSchema_frame_2019_09, nested_schemas) { frame, "https://www.sourcemeta.com/schema#/properties/baz/$id", "https://www.sourcemeta.com/schema", "/properties/baz/$id", "https://www.sourcemeta.com/baz", "/$id", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/baz/items", "https://www.sourcemeta.com/schema", "/properties/baz/items", "https://www.sourcemeta.com/baz", "/items", 0); @@ -500,7 +508,7 @@ TEST(JSONSchema_frame_2019_09, nested_schemas) { frame, "https://www.sourcemeta.com/baz#/$id", "https://www.sourcemeta.com/schema", "/properties/baz/$id", "https://www.sourcemeta.com/baz", "/$id", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/baz#/items", "https://www.sourcemeta.com/schema", "/properties/baz/items", "https://www.sourcemeta.com/baz", "/items", 0); @@ -723,7 +731,7 @@ TEST(JSONSchema_frame_2019_09, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.example.com", "/$schema", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.example.com", "/items", 0); @@ -735,7 +743,7 @@ TEST(JSONSchema_frame_2019_09, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.example.com", "/properties", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/one", "https://www.sourcemeta.com/schema", "/properties/one", "https://www.example.com/test", "", 0); @@ -747,7 +755,7 @@ TEST(JSONSchema_frame_2019_09, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties/one/$anchor", "https://www.sourcemeta.com/schema", "/properties/one/$anchor", "https://www.example.com/test", "/$anchor", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/two", "https://www.sourcemeta.com/schema", "/properties/two", "https://www.test.com", "", 0); @@ -799,7 +807,7 @@ TEST(JSONSchema_frame_2019_09, ref_metaschema) { EXPECT_EQ(frame.size(), 3); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", @@ -972,7 +980,7 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_true_without_id) { // Static frames - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", @@ -980,7 +988,7 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_true_without_id) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/properties", "/properties", "https://json-schema.org/draft/2019-09/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/properties/foo", "/properties/foo", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -1018,7 +1026,7 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_false_without_id) { // Static frames - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", @@ -1026,7 +1034,7 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_false_without_id) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/properties", "/properties", "https://json-schema.org/draft/2019-09/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/properties/foo", "/properties/foo", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -1060,12 +1068,12 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_no_recursive_anchor_anonymous) { EXPECT_EQ(frame.size(), 4); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "https://json-schema.org/draft/2019-09/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalItems", "/additionalItems", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -1115,7 +1123,7 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_no_recursive_anchor) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/additionalItems", "https://www.sourcemeta.com/schema", "/additionalItems", "https://www.sourcemeta.com/schema", "/additionalItems", 0); @@ -1154,7 +1162,7 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_false_anonymous) { EXPECT_EQ(frame.size(), 5); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", @@ -1162,7 +1170,7 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_false_anonymous) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$recursiveAnchor", "/$recursiveAnchor", "https://json-schema.org/draft/2019-09/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalItems", "/additionalItems", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -1217,7 +1225,7 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_false) { frame, "https://www.sourcemeta.com/schema#/$recursiveAnchor", "https://www.sourcemeta.com/schema", "/$recursiveAnchor", "https://www.sourcemeta.com/schema", "/$recursiveAnchor", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/additionalItems", "https://www.sourcemeta.com/schema", "/additionalItems", "https://www.sourcemeta.com/schema", "/additionalItems", 0); @@ -1256,7 +1264,7 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_true_anonymous) { EXPECT_EQ(frame.size(), 6); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", @@ -1264,7 +1272,7 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_true_anonymous) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$recursiveAnchor", "/$recursiveAnchor", "https://json-schema.org/draft/2019-09/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalItems", "/additionalItems", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -1324,7 +1332,7 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_true) { frame, "https://www.sourcemeta.com/schema#/$recursiveAnchor", "https://www.sourcemeta.com/schema", "/$recursiveAnchor", "https://www.sourcemeta.com/schema", "/$recursiveAnchor", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/additionalItems", "https://www.sourcemeta.com/schema", "/additionalItems", "https://www.sourcemeta.com/schema", "/additionalItems", 0); @@ -1376,12 +1384,12 @@ TEST(JSONSchema_frame_2019_09, frame, "https://example.com", "/additionalItems", "https://json-schema.org/draft/2019-09/schema", 1); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "https://json-schema.org/draft/2019-09/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalItems", "/additionalItems", "https://json-schema.org/draft/2019-09/schema", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -1444,12 +1452,12 @@ TEST(JSONSchema_frame_2019_09, frame, "https://example.com", "/additionalItems", "https://json-schema.org/draft/2019-09/schema", 1); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "https://json-schema.org/draft/2019-09/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalItems", "/additionalItems", "https://json-schema.org/draft/2019-09/schema", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -1532,7 +1540,7 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_nested_recursive_anchor_true) { "https://www.sourcemeta.com/schema", "/additionalItems/$recursiveAnchor", "https://www.sourcemeta.com/schema", "/additionalItems/$recursiveAnchor", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/additionalItems", "https://www.sourcemeta.com/schema", "/additionalItems", "https://www.sourcemeta.com/schema", "/additionalItems", 1); @@ -1602,7 +1610,7 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_multiple_recursive_anchor_true) { frame, "https://www.sourcemeta.com/schema#/$recursiveAnchor", "https://www.sourcemeta.com/schema", "/$recursiveAnchor", "https://www.sourcemeta.com/schema", "/$recursiveAnchor", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/additionalItems", "https://www.sourcemeta.com/schema", "/additionalItems", "https://www.sourcemeta.com/nested", "", 1); @@ -1712,7 +1720,7 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_on_relative_id) { EXPECT_EQ(frame.size(), 11); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_RESOURCE( frame, "middle", "/additionalItems", @@ -1720,7 +1728,7 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_on_relative_id) { // JSON Pointers - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", @@ -1729,7 +1737,7 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_on_relative_id) { frame, "#/$recursiveAnchor", "/$recursiveAnchor", "https://json-schema.org/draft/2019-09/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalItems", "/additionalItems", "https://json-schema.org/draft/2019-09/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -1802,7 +1810,7 @@ TEST(JSONSchema_frame_2019_09, ref_with_id) { frame, "https://www.sourcemeta.com/schema#/$defs", "https://www.sourcemeta.com/schema", "/$defs", "https://www.sourcemeta.com/schema", "/$defs", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/$defs/string", "https://www.sourcemeta.com/schema", "/$defs/string", "https://www.sourcemeta.com/schema", "/$defs/string", 1); @@ -1866,7 +1874,7 @@ TEST(JSONSchema_frame_2019_09, ref_from_definitions) { frame, "https://www.sourcemeta.com/schema#/definitions", "https://www.sourcemeta.com/schema", "/definitions", "https://www.sourcemeta.com/schema", "/definitions", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/definitions/middle", "https://www.sourcemeta.com/schema", "/definitions/middle", "https://www.sourcemeta.com/schema", "/definitions/middle", 1); @@ -1874,7 +1882,7 @@ TEST(JSONSchema_frame_2019_09, ref_from_definitions) { frame, "https://www.sourcemeta.com/schema#/definitions/middle/$ref", "https://www.sourcemeta.com/schema", "/definitions/middle/$ref", "https://www.sourcemeta.com/schema", "/definitions/middle/$ref", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER( + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/definitions/string", "https://www.sourcemeta.com/schema", "/definitions/string", "https://www.sourcemeta.com/schema", "/definitions/string", 1); @@ -1970,15 +1978,16 @@ TEST(JSONSchema_frame_2019_09, relative_base_uri_with_ref) { "common", "/$id", 0); EXPECT_FRAME_STATIC_2019_09_POINTER(frame, "common#/allOf", "common", "/allOf", "common", "/allOf", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER(frame, "common#/allOf/0", "common", - "/allOf/0", "common", "/allOf/0", 0); + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA(frame, "common#/allOf/0", "common", + "/allOf/0", "common", "/allOf/0", 0); EXPECT_FRAME_STATIC_2019_09_POINTER(frame, "common#/allOf/0/$ref", "common", "/allOf/0/$ref", "common", "/allOf/0/$ref", 0); EXPECT_FRAME_STATIC_2019_09_POINTER(frame, "common#/$defs", "common", "/$defs", "common", "/$defs", 0); - EXPECT_FRAME_STATIC_2019_09_POINTER(frame, "common#/$defs/foo", "common", - "/$defs/foo", "common", "/$defs/foo", 1); + EXPECT_FRAME_STATIC_2019_09_SUBSCHEMA(frame, "common#/$defs/foo", "common", + "/$defs/foo", "common", "/$defs/foo", + 1); EXPECT_FRAME_STATIC_2019_09_POINTER(frame, "common#/$defs/foo/$anchor", "common", "/$defs/foo/$anchor", "common", "/$defs/foo/$anchor", 0); diff --git a/test/jsonschema/jsonschema_frame_2020_12_test.cc b/test/jsonschema/jsonschema_frame_2020_12_test.cc index ea656a2a8..5bb1828cc 100644 --- a/test/jsonschema/jsonschema_frame_2020_12_test.cc +++ b/test/jsonschema/jsonschema_frame_2020_12_test.cc @@ -30,6 +30,14 @@ expected_base, expected_relative_pointer, \ expected_destination_of_size); +#define EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( \ + frame, reference, root_id, expected_pointer, expected_base, \ + expected_relative_pointer, expected_destination_of_size) \ + EXPECT_FRAME_STATIC_SUBSCHEMA( \ + frame, reference, root_id, expected_pointer, \ + "https://json-schema.org/draft/2020-12/schema", expected_base, \ + expected_relative_pointer, expected_destination_of_size); + #define EXPECT_FRAME_DYNAMIC_2020_12_ANCHOR( \ frame, reference, root_id, expected_pointer, expected_base, \ expected_relative_pointer, expected_destination_of_size) \ @@ -62,12 +70,12 @@ TEST(JSONSchema_frame_2020_12, anonymous_with_nested_schema_resource) { // JSON Pointers - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2020-12/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "https://json-schema.org/draft/2020-12/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalProperties", "/additionalProperties", "https://json-schema.org/draft/2020-12/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -155,7 +163,7 @@ TEST(JSONSchema_frame_2020_12, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/schema", "/items", 0); @@ -167,7 +175,7 @@ TEST(JSONSchema_frame_2020_12, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.sourcemeta.com/schema", "/properties", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", 0); @@ -229,7 +237,7 @@ TEST(JSONSchema_frame_2020_12, one_level_applicators_with_identifiers) { frame, "https://www.sourcemeta.com/test/qux#/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/test/qux#/items", "https://www.sourcemeta.com/test/qux", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -245,7 +253,7 @@ TEST(JSONSchema_frame_2020_12, one_level_applicators_with_identifiers) { frame, "https://www.sourcemeta.com/test/qux#/properties", "https://www.sourcemeta.com/test/qux", "/properties", "https://www.sourcemeta.com/test/qux", "/properties", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/test/qux#/properties/foo", "https://www.sourcemeta.com/test/qux", "/properties/foo", "https://www.sourcemeta.com/test/qux", "/properties/foo", 0); @@ -313,7 +321,7 @@ TEST(JSONSchema_frame_2020_12, subschema_absolute_identifier) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -413,7 +421,7 @@ TEST(JSONSchema_frame_2020_12, nested_schemas) { "https://www.sourcemeta.com/schema", "/properties", 0); // foo - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", "https://www.sourcemeta.com/foo", "", 0); @@ -425,7 +433,7 @@ TEST(JSONSchema_frame_2020_12, nested_schemas) { frame, "https://www.sourcemeta.com/schema#/properties/foo/$anchor", "https://www.sourcemeta.com/schema", "/properties/foo/$anchor", "https://www.sourcemeta.com/foo", "/$anchor", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo/items", "https://www.sourcemeta.com/schema", "/properties/foo/items", "https://www.sourcemeta.com/qux", "", 0); @@ -442,7 +450,7 @@ TEST(JSONSchema_frame_2020_12, nested_schemas) { frame, "https://www.sourcemeta.com/foo#/$anchor", "https://www.sourcemeta.com/schema", "/properties/foo/$anchor", "https://www.sourcemeta.com/foo", "/$anchor", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/foo#/items", "https://www.sourcemeta.com/schema", "/properties/foo/items", "https://www.sourcemeta.com/qux", "", 0); @@ -456,7 +464,7 @@ TEST(JSONSchema_frame_2020_12, nested_schemas) { "https://www.sourcemeta.com/qux", "/$id", 0); // bar - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/bar", "https://www.sourcemeta.com/schema", "/properties/bar", "https://www.sourcemeta.com/bar", "", 0); @@ -470,7 +478,7 @@ TEST(JSONSchema_frame_2020_12, nested_schemas) { "https://www.sourcemeta.com/bar", "/$id", 0); // baz - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/baz", "https://www.sourcemeta.com/schema", "/properties/baz", "https://www.sourcemeta.com/baz", "", 0); @@ -478,7 +486,7 @@ TEST(JSONSchema_frame_2020_12, nested_schemas) { frame, "https://www.sourcemeta.com/schema#/properties/baz/$id", "https://www.sourcemeta.com/schema", "/properties/baz/$id", "https://www.sourcemeta.com/baz", "/$id", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/baz/items", "https://www.sourcemeta.com/schema", "/properties/baz/items", "https://www.sourcemeta.com/baz", "/items", 0); @@ -491,7 +499,7 @@ TEST(JSONSchema_frame_2020_12, nested_schemas) { frame, "https://www.sourcemeta.com/baz#/$id", "https://www.sourcemeta.com/schema", "/properties/baz/$id", "https://www.sourcemeta.com/baz", "/$id", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/baz#/items", "https://www.sourcemeta.com/schema", "/properties/baz/items", "https://www.sourcemeta.com/baz", "/items", 0); @@ -714,7 +722,7 @@ TEST(JSONSchema_frame_2020_12, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.example.com", "/$schema", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.example.com", "/items", 0); @@ -726,7 +734,7 @@ TEST(JSONSchema_frame_2020_12, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.example.com", "/properties", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/one", "https://www.sourcemeta.com/schema", "/properties/one", "https://www.example.com/test", "", 0); @@ -738,7 +746,7 @@ TEST(JSONSchema_frame_2020_12, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties/one/$anchor", "https://www.sourcemeta.com/schema", "/properties/one/$anchor", "https://www.example.com/test", "/$anchor", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/two", "https://www.sourcemeta.com/schema", "/properties/two", "https://www.test.com", "", 0); @@ -1085,7 +1093,7 @@ TEST(JSONSchema_frame_2020_12, dynamic_anchor_with_id) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.sourcemeta.com/schema", "/properties", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", 0); @@ -1093,7 +1101,7 @@ TEST(JSONSchema_frame_2020_12, dynamic_anchor_with_id) { frame, "https://www.sourcemeta.com/schema#/properties/foo/$dynamicAnchor", "https://www.sourcemeta.com/schema", "/properties/foo/$dynamicAnchor", "https://www.sourcemeta.com/schema", "/properties/foo/$dynamicAnchor", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/bar", "https://www.sourcemeta.com/schema", "/properties/bar", "https://www.sourcemeta.com/bar", "", 0); @@ -1161,7 +1169,7 @@ TEST(JSONSchema_frame_2020_12, dynamic_anchor_without_id) { // Static frames - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2020-12/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", @@ -1169,7 +1177,7 @@ TEST(JSONSchema_frame_2020_12, dynamic_anchor_without_id) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/properties", "/properties", "https://json-schema.org/draft/2020-12/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/properties/foo", "/properties/foo", "https://json-schema.org/draft/2020-12/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -1218,7 +1226,7 @@ TEST(JSONSchema_frame_2020_12, // Static frames - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2020-12/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", @@ -1229,7 +1237,7 @@ TEST(JSONSchema_frame_2020_12, EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$defs", "/$defs", "https://json-schema.org/draft/2020-12/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/$defs/test", "/$defs/test", "https://json-schema.org/draft/2020-12/schema", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -1281,7 +1289,7 @@ TEST(JSONSchema_frame_2020_12, dynamic_ref_to_single_dynamic_anchor_external) { // Static frames - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2020-12/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", @@ -1292,13 +1300,13 @@ TEST(JSONSchema_frame_2020_12, dynamic_ref_to_single_dynamic_anchor_external) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$defs", "/$defs", "https://json-schema.org/draft/2020-12/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/$defs/test", "/$defs/test", "https://json-schema.org/draft/2020-12/schema", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$defs/test/$dynamicAnchor", "/$defs/test/$dynamicAnchor", "https://json-schema.org/draft/2020-12/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/$defs/foo", "/$defs/foo", "https://json-schema.org/draft/2020-12/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -1358,7 +1366,7 @@ TEST(JSONSchema_frame_2020_12, no_id_recursive_empty_pointer) { EXPECT_EQ(frame.size(), 5); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2020-12/schema", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", @@ -1366,7 +1374,7 @@ TEST(JSONSchema_frame_2020_12, no_id_recursive_empty_pointer) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/properties", "/properties", "https://json-schema.org/draft/2020-12/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/properties/foo", "/properties/foo", "https://json-schema.org/draft/2020-12/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -1399,7 +1407,7 @@ TEST(JSONSchema_frame_2020_12, ref_metaschema) { EXPECT_EQ(frame.size(), 3); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2020-12/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", @@ -1486,7 +1494,7 @@ TEST(JSONSchema_frame_2020_12, ref_with_id) { frame, "https://www.sourcemeta.com/schema#/$defs", "https://www.sourcemeta.com/schema", "/$defs", "https://www.sourcemeta.com/schema", "/$defs", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/$defs/string", "https://www.sourcemeta.com/schema", "/$defs/string", "https://www.sourcemeta.com/schema", "/$defs/string", 1); @@ -1550,7 +1558,7 @@ TEST(JSONSchema_frame_2020_12, ref_from_definitions) { frame, "https://www.sourcemeta.com/schema#/definitions", "https://www.sourcemeta.com/schema", "/definitions", "https://www.sourcemeta.com/schema", "/definitions", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/definitions/middle", "https://www.sourcemeta.com/schema", "/definitions/middle", "https://www.sourcemeta.com/schema", "/definitions/middle", 1); @@ -1558,7 +1566,7 @@ TEST(JSONSchema_frame_2020_12, ref_from_definitions) { frame, "https://www.sourcemeta.com/schema#/definitions/middle/$ref", "https://www.sourcemeta.com/schema", "/definitions/middle/$ref", "https://www.sourcemeta.com/schema", "/definitions/middle/$ref", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/definitions/string", "https://www.sourcemeta.com/schema", "/definitions/string", "https://www.sourcemeta.com/schema", "/definitions/string", 1); @@ -1654,15 +1662,16 @@ TEST(JSONSchema_frame_2020_12, relative_base_uri_with_ref) { "common", "/$id", 0); EXPECT_FRAME_STATIC_2020_12_POINTER(frame, "common#/allOf", "common", "/allOf", "common", "/allOf", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER(frame, "common#/allOf/0", "common", - "/allOf/0", "common", "/allOf/0", 0); + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA(frame, "common#/allOf/0", "common", + "/allOf/0", "common", "/allOf/0", 0); EXPECT_FRAME_STATIC_2020_12_POINTER(frame, "common#/allOf/0/$ref", "common", "/allOf/0/$ref", "common", "/allOf/0/$ref", 0); EXPECT_FRAME_STATIC_2020_12_POINTER(frame, "common#/$defs", "common", "/$defs", "common", "/$defs", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER(frame, "common#/$defs/foo", "common", - "/$defs/foo", "common", "/$defs/foo", 1); + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA(frame, "common#/$defs/foo", "common", + "/$defs/foo", "common", "/$defs/foo", + 1); EXPECT_FRAME_STATIC_2020_12_POINTER(frame, "common#/$defs/foo/$anchor", "common", "/$defs/foo/$anchor", "common", "/$defs/foo/$anchor", 0); @@ -1727,7 +1736,7 @@ TEST(JSONSchema_frame_2020_12, idempotent_with_refs) { frame, "https://www.sourcemeta.com/schema#/$defs", "https://www.sourcemeta.com/schema", "/$defs", "https://www.sourcemeta.com/schema", "/$defs", 0); - EXPECT_FRAME_STATIC_2020_12_POINTER( + EXPECT_FRAME_STATIC_2020_12_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/$defs/string", "https://www.sourcemeta.com/schema", "/$defs/string", "https://www.sourcemeta.com/schema", "/$defs/string", 1); diff --git a/test/jsonschema/jsonschema_frame_draft0_test.cc b/test/jsonschema/jsonschema_frame_draft0_test.cc index 6f4ef8ca0..cfa96f88b 100644 --- a/test/jsonschema/jsonschema_frame_draft0_test.cc +++ b/test/jsonschema/jsonschema_frame_draft0_test.cc @@ -22,6 +22,14 @@ expected_base, expected_relative_pointer, \ expected_destination_of_size); +#define EXPECT_FRAME_STATIC_DRAFT0_SUBSCHEMA( \ + frame, reference, root_id, expected_pointer, expected_base, \ + expected_relative_pointer, expected_destination_of_size) \ + EXPECT_FRAME_STATIC_SUBSCHEMA(frame, reference, root_id, expected_pointer, \ + "http://json-schema.org/draft-00/schema#", \ + expected_base, expected_relative_pointer, \ + expected_destination_of_size); + TEST(JSONSchema_frame_draft0, anonymous_with_nested_schema_resource) { const sourcemeta::jsontoolkit::JSON document = sourcemeta::jsontoolkit::parse(R"JSON({ @@ -46,12 +54,12 @@ TEST(JSONSchema_frame_draft0, anonymous_with_nested_schema_resource) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "https://example.com#/id", "/additionalProperties/id", "http://json-schema.org/draft-00/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-00/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-00/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalProperties", "/additionalProperties", "http://json-schema.org/draft-00/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -139,7 +147,7 @@ TEST(JSONSchema_frame_draft0, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT0_POINTER( + EXPECT_FRAME_STATIC_DRAFT0_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/schema", "/items", 0); @@ -151,7 +159,7 @@ TEST(JSONSchema_frame_draft0, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.sourcemeta.com/schema", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT0_POINTER( + EXPECT_FRAME_STATIC_DRAFT0_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", 0); @@ -203,7 +211,7 @@ TEST(JSONSchema_frame_draft0, one_level_applicators_with_identifiers) { frame, "https://www.sourcemeta.com/test/qux#/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT0_POINTER( + EXPECT_FRAME_STATIC_DRAFT0_SUBSCHEMA( frame, "https://www.sourcemeta.com/test/qux#/items", "https://www.sourcemeta.com/test/qux", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -270,7 +278,7 @@ TEST(JSONSchema_frame_draft0, subschema_absolute_identifier) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT0_POINTER( + EXPECT_FRAME_STATIC_DRAFT0_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -416,7 +424,7 @@ TEST(JSONSchema_frame_draft0, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.example.com", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT0_POINTER( + EXPECT_FRAME_STATIC_DRAFT0_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/one", "https://www.sourcemeta.com/schema", "/properties/one", "https://www.example.com/test", "", 0); @@ -424,7 +432,7 @@ TEST(JSONSchema_frame_draft0, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties/one/id", "https://www.sourcemeta.com/schema", "/properties/one/id", "https://www.example.com/test", "/id", 0); - EXPECT_FRAME_STATIC_DRAFT0_POINTER( + EXPECT_FRAME_STATIC_DRAFT0_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/two", "https://www.sourcemeta.com/schema", "/properties/two", "https://www.test.com", "", 0); @@ -464,7 +472,7 @@ TEST(JSONSchema_frame_draft0, ref_metaschema) { EXPECT_EQ(frame.size(), 3); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-00/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-00/schema#", diff --git a/test/jsonschema/jsonschema_frame_draft1_test.cc b/test/jsonschema/jsonschema_frame_draft1_test.cc index 034d8838d..25db24de6 100644 --- a/test/jsonschema/jsonschema_frame_draft1_test.cc +++ b/test/jsonschema/jsonschema_frame_draft1_test.cc @@ -22,6 +22,14 @@ expected_base, expected_relative_pointer, \ expected_destination_of_size); +#define EXPECT_FRAME_STATIC_DRAFT1_SUBSCHEMA( \ + frame, reference, root_id, expected_pointer, expected_base, \ + expected_relative_pointer, expected_destination_of_size) \ + EXPECT_FRAME_STATIC_SUBSCHEMA(frame, reference, root_id, expected_pointer, \ + "http://json-schema.org/draft-01/schema#", \ + expected_base, expected_relative_pointer, \ + expected_destination_of_size); + TEST(JSONSchema_frame_draft1, anonymous_with_nested_schema_resource) { const sourcemeta::jsontoolkit::JSON document = sourcemeta::jsontoolkit::parse(R"JSON({ @@ -46,12 +54,12 @@ TEST(JSONSchema_frame_draft1, anonymous_with_nested_schema_resource) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "https://example.com#/id", "/additionalProperties/id", "http://json-schema.org/draft-01/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-01/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-01/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalProperties", "/additionalProperties", "http://json-schema.org/draft-01/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -139,7 +147,7 @@ TEST(JSONSchema_frame_draft1, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT1_POINTER( + EXPECT_FRAME_STATIC_DRAFT1_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/schema", "/items", 0); @@ -151,7 +159,7 @@ TEST(JSONSchema_frame_draft1, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.sourcemeta.com/schema", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT1_POINTER( + EXPECT_FRAME_STATIC_DRAFT1_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", 0); @@ -203,7 +211,7 @@ TEST(JSONSchema_frame_draft1, one_level_applicators_with_identifiers) { frame, "https://www.sourcemeta.com/test/qux#/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT1_POINTER( + EXPECT_FRAME_STATIC_DRAFT1_SUBSCHEMA( frame, "https://www.sourcemeta.com/test/qux#/items", "https://www.sourcemeta.com/test/qux", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -270,7 +278,7 @@ TEST(JSONSchema_frame_draft1, subschema_absolute_identifier) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT1_POINTER( + EXPECT_FRAME_STATIC_DRAFT1_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -416,7 +424,7 @@ TEST(JSONSchema_frame_draft1, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.example.com", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT1_POINTER( + EXPECT_FRAME_STATIC_DRAFT1_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/one", "https://www.sourcemeta.com/schema", "/properties/one", "https://www.example.com/test", "", 0); @@ -424,7 +432,7 @@ TEST(JSONSchema_frame_draft1, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties/one/id", "https://www.sourcemeta.com/schema", "/properties/one/id", "https://www.example.com/test", "/id", 0); - EXPECT_FRAME_STATIC_DRAFT1_POINTER( + EXPECT_FRAME_STATIC_DRAFT1_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/two", "https://www.sourcemeta.com/schema", "/properties/two", "https://www.test.com", "", 0); @@ -464,7 +472,7 @@ TEST(JSONSchema_frame_draft1, ref_metaschema) { EXPECT_EQ(frame.size(), 3); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-01/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-01/schema#", diff --git a/test/jsonschema/jsonschema_frame_draft2_test.cc b/test/jsonschema/jsonschema_frame_draft2_test.cc index 45596dcdc..32ab2322c 100644 --- a/test/jsonschema/jsonschema_frame_draft2_test.cc +++ b/test/jsonschema/jsonschema_frame_draft2_test.cc @@ -22,6 +22,14 @@ expected_base, expected_relative_pointer, \ expected_destination_of_size); +#define EXPECT_FRAME_STATIC_DRAFT2_SUBSCHEMA( \ + frame, reference, root_id, expected_pointer, expected_base, \ + expected_relative_pointer, expected_destination_of_size) \ + EXPECT_FRAME_STATIC_SUBSCHEMA(frame, reference, root_id, expected_pointer, \ + "http://json-schema.org/draft-02/schema#", \ + expected_base, expected_relative_pointer, \ + expected_destination_of_size); + TEST(JSONSchema_frame_draft2, anonymous_with_nested_schema_resource) { const sourcemeta::jsontoolkit::JSON document = sourcemeta::jsontoolkit::parse(R"JSON({ @@ -46,12 +54,12 @@ TEST(JSONSchema_frame_draft2, anonymous_with_nested_schema_resource) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "https://example.com#/id", "/additionalProperties/id", "http://json-schema.org/draft-02/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-02/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-02/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalProperties", "/additionalProperties", "http://json-schema.org/draft-02/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -139,7 +147,7 @@ TEST(JSONSchema_frame_draft2, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT2_POINTER( + EXPECT_FRAME_STATIC_DRAFT2_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/schema", "/items", 0); @@ -151,7 +159,7 @@ TEST(JSONSchema_frame_draft2, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.sourcemeta.com/schema", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT2_POINTER( + EXPECT_FRAME_STATIC_DRAFT2_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", 0); @@ -203,7 +211,7 @@ TEST(JSONSchema_frame_draft2, one_level_applicators_with_identifiers) { frame, "https://www.sourcemeta.com/test/qux#/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT2_POINTER( + EXPECT_FRAME_STATIC_DRAFT2_SUBSCHEMA( frame, "https://www.sourcemeta.com/test/qux#/items", "https://www.sourcemeta.com/test/qux", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -270,7 +278,7 @@ TEST(JSONSchema_frame_draft2, subschema_absolute_identifier) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT2_POINTER( + EXPECT_FRAME_STATIC_DRAFT2_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -416,7 +424,7 @@ TEST(JSONSchema_frame_draft2, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.example.com", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT2_POINTER( + EXPECT_FRAME_STATIC_DRAFT2_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/one", "https://www.sourcemeta.com/schema", "/properties/one", "https://www.example.com/test", "", 0); @@ -424,7 +432,7 @@ TEST(JSONSchema_frame_draft2, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties/one/id", "https://www.sourcemeta.com/schema", "/properties/one/id", "https://www.example.com/test", "/id", 0); - EXPECT_FRAME_STATIC_DRAFT2_POINTER( + EXPECT_FRAME_STATIC_DRAFT2_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/two", "https://www.sourcemeta.com/schema", "/properties/two", "https://www.test.com", "", 0); @@ -464,7 +472,7 @@ TEST(JSONSchema_frame_draft2, ref_metaschema) { EXPECT_EQ(frame.size(), 3); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-02/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-02/schema#", diff --git a/test/jsonschema/jsonschema_frame_draft3_test.cc b/test/jsonschema/jsonschema_frame_draft3_test.cc index da2172b89..319da1fd9 100644 --- a/test/jsonschema/jsonschema_frame_draft3_test.cc +++ b/test/jsonschema/jsonschema_frame_draft3_test.cc @@ -22,6 +22,14 @@ expected_base, expected_relative_pointer, \ expected_destination_of_size); +#define EXPECT_FRAME_STATIC_DRAFT3_SUBSCHEMA( \ + frame, reference, root_id, expected_pointer, expected_base, \ + expected_relative_pointer, expected_destination_of_size) \ + EXPECT_FRAME_STATIC_SUBSCHEMA(frame, reference, root_id, expected_pointer, \ + "http://json-schema.org/draft-03/schema#", \ + expected_base, expected_relative_pointer, \ + expected_destination_of_size); + TEST(JSONSchema_frame_draft3, anonymous_with_nested_schema_resource) { const sourcemeta::jsontoolkit::JSON document = sourcemeta::jsontoolkit::parse(R"JSON({ @@ -46,12 +54,12 @@ TEST(JSONSchema_frame_draft3, anonymous_with_nested_schema_resource) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "https://example.com#/id", "/additionalProperties/id", "http://json-schema.org/draft-03/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-03/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-03/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalProperties", "/additionalProperties", "http://json-schema.org/draft-03/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -139,7 +147,7 @@ TEST(JSONSchema_frame_draft3, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT3_POINTER( + EXPECT_FRAME_STATIC_DRAFT3_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/schema", "/items", 0); @@ -151,7 +159,7 @@ TEST(JSONSchema_frame_draft3, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.sourcemeta.com/schema", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT3_POINTER( + EXPECT_FRAME_STATIC_DRAFT3_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", 0); @@ -203,7 +211,7 @@ TEST(JSONSchema_frame_draft3, one_level_applicators_with_identifiers) { frame, "https://www.sourcemeta.com/test/qux#/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT3_POINTER( + EXPECT_FRAME_STATIC_DRAFT3_SUBSCHEMA( frame, "https://www.sourcemeta.com/test/qux#/items", "https://www.sourcemeta.com/test/qux", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -270,7 +278,7 @@ TEST(JSONSchema_frame_draft3, subschema_absolute_identifier) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT3_POINTER( + EXPECT_FRAME_STATIC_DRAFT3_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -416,7 +424,7 @@ TEST(JSONSchema_frame_draft3, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.example.com", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT3_POINTER( + EXPECT_FRAME_STATIC_DRAFT3_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/one", "https://www.sourcemeta.com/schema", "/properties/one", "https://www.example.com/test", "", 0); @@ -424,7 +432,7 @@ TEST(JSONSchema_frame_draft3, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties/one/id", "https://www.sourcemeta.com/schema", "/properties/one/id", "https://www.example.com/test", "/id", 0); - EXPECT_FRAME_STATIC_DRAFT3_POINTER( + EXPECT_FRAME_STATIC_DRAFT3_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/two", "https://www.sourcemeta.com/schema", "/properties/two", "https://www.test.com", "", 0); @@ -464,7 +472,7 @@ TEST(JSONSchema_frame_draft3, ref_metaschema) { EXPECT_EQ(frame.size(), 3); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-03/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-03/schema#", @@ -502,7 +510,7 @@ TEST(JSONSchema_frame_draft3, ref_with_id) { // JSON Pointers - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-03/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/id", "/id", "http://json-schema.org/draft-03/schema#", 0); diff --git a/test/jsonschema/jsonschema_frame_draft4_test.cc b/test/jsonschema/jsonschema_frame_draft4_test.cc index 3cb1d7124..ab77ae20f 100644 --- a/test/jsonschema/jsonschema_frame_draft4_test.cc +++ b/test/jsonschema/jsonschema_frame_draft4_test.cc @@ -30,6 +30,14 @@ expected_base, expected_relative_pointer, \ expected_destination_of_size); +#define EXPECT_FRAME_STATIC_DRAFT4_SUBSCHEMA( \ + frame, reference, root_id, expected_pointer, expected_base, \ + expected_relative_pointer, expected_destination_of_size) \ + EXPECT_FRAME_STATIC_SUBSCHEMA(frame, reference, root_id, expected_pointer, \ + "http://json-schema.org/draft-04/schema#", \ + expected_base, expected_relative_pointer, \ + expected_destination_of_size); + TEST(JSONSchema_frame_draft4, anonymous_with_nested_schema_resource) { const sourcemeta::jsontoolkit::JSON document = sourcemeta::jsontoolkit::parse(R"JSON({ @@ -54,12 +62,12 @@ TEST(JSONSchema_frame_draft4, anonymous_with_nested_schema_resource) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "https://example.com#/id", "/additionalProperties/id", "http://json-schema.org/draft-04/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-04/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-04/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalProperties", "/additionalProperties", "http://json-schema.org/draft-04/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -147,7 +155,7 @@ TEST(JSONSchema_frame_draft4, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT4_POINTER( + EXPECT_FRAME_STATIC_DRAFT4_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/schema", "/items", 0); @@ -159,7 +167,7 @@ TEST(JSONSchema_frame_draft4, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.sourcemeta.com/schema", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT4_POINTER( + EXPECT_FRAME_STATIC_DRAFT4_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", 0); @@ -211,7 +219,7 @@ TEST(JSONSchema_frame_draft4, one_level_applicators_with_identifiers) { frame, "https://www.sourcemeta.com/test/qux#/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT4_POINTER( + EXPECT_FRAME_STATIC_DRAFT4_SUBSCHEMA( frame, "https://www.sourcemeta.com/test/qux#/items", "https://www.sourcemeta.com/test/qux", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -278,7 +286,7 @@ TEST(JSONSchema_frame_draft4, subschema_absolute_identifier) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT4_POINTER( + EXPECT_FRAME_STATIC_DRAFT4_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -424,7 +432,7 @@ TEST(JSONSchema_frame_draft4, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.example.com", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT4_POINTER( + EXPECT_FRAME_STATIC_DRAFT4_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/one", "https://www.sourcemeta.com/schema", "/properties/one", "https://www.example.com/test", "", 0); @@ -432,7 +440,7 @@ TEST(JSONSchema_frame_draft4, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties/one/id", "https://www.sourcemeta.com/schema", "/properties/one/id", "https://www.example.com/test", "/id", 0); - EXPECT_FRAME_STATIC_DRAFT4_POINTER( + EXPECT_FRAME_STATIC_DRAFT4_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/two", "https://www.sourcemeta.com/schema", "/properties/two", "https://www.test.com", "", 0); @@ -472,7 +480,7 @@ TEST(JSONSchema_frame_draft4, ref_metaschema) { EXPECT_EQ(frame.size(), 3); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-04/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-04/schema#", @@ -515,7 +523,7 @@ TEST(JSONSchema_frame_draft4, location_independent_identifier_anonymous) { EXPECT_EQ(frame.size(), 8); // Pointers - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-04/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-04/schema#", @@ -525,7 +533,7 @@ TEST(JSONSchema_frame_draft4, location_independent_identifier_anonymous) { "http://json-schema.org/draft-04/schema#", 0); // Foo - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/definitions/foo", "/definitions/foo", "http://json-schema.org/draft-04/schema#", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -533,7 +541,7 @@ TEST(JSONSchema_frame_draft4, location_independent_identifier_anonymous) { "http://json-schema.org/draft-04/schema#", 0); // Bar - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/definitions/bar", "/definitions/bar", "http://json-schema.org/draft-04/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -577,7 +585,7 @@ TEST(JSONSchema_frame_draft4, ref_with_id) { // JSON Pointers - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-04/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/id", "/id", "http://json-schema.org/draft-04/schema#", 0); @@ -589,7 +597,7 @@ TEST(JSONSchema_frame_draft4, ref_with_id) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/definitions", "/definitions", "http://json-schema.org/draft-04/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/definitions/string", "/definitions/string", "http://json-schema.org/draft-04/schema#", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -678,17 +686,17 @@ TEST(JSONSchema_frame_draft4, relative_base_uri_with_ref) { "common", "/id", 0); EXPECT_FRAME_STATIC_DRAFT4_POINTER(frame, "common#/allOf", "common", "/allOf", "common", "/allOf", 0); - EXPECT_FRAME_STATIC_DRAFT4_POINTER(frame, "common#/allOf/0", "common", - "/allOf/0", "common", "/allOf/0", 0); + EXPECT_FRAME_STATIC_DRAFT4_SUBSCHEMA(frame, "common#/allOf/0", "common", + "/allOf/0", "common", "/allOf/0", 0); EXPECT_FRAME_STATIC_DRAFT4_POINTER(frame, "common#/allOf/0/$ref", "common", "/allOf/0/$ref", "common", "/allOf/0/$ref", 0); EXPECT_FRAME_STATIC_DRAFT4_POINTER(frame, "common#/definitions", "common", "/definitions", "common", "/definitions", 0); - EXPECT_FRAME_STATIC_DRAFT4_POINTER(frame, "common#/definitions/foo", "common", - "/definitions/foo", "common", - "/definitions/foo", 1); + EXPECT_FRAME_STATIC_DRAFT4_SUBSCHEMA(frame, "common#/definitions/foo", + "common", "/definitions/foo", "common", + "/definitions/foo", 1); EXPECT_FRAME_STATIC_DRAFT4_POINTER(frame, "common#/definitions/foo/id", "common", "/definitions/foo/id", "common", "/definitions/foo/id", 0); diff --git a/test/jsonschema/jsonschema_frame_draft6_test.cc b/test/jsonschema/jsonschema_frame_draft6_test.cc index 238a9d683..89844ac95 100644 --- a/test/jsonschema/jsonschema_frame_draft6_test.cc +++ b/test/jsonschema/jsonschema_frame_draft6_test.cc @@ -30,6 +30,14 @@ expected_base, expected_relative_pointer, \ expected_destination_of_size); +#define EXPECT_FRAME_STATIC_DRAFT6_SUBSCHEMA( \ + frame, reference, root_id, expected_pointer, expected_base, \ + expected_relative_pointer, expected_destination_of_size) \ + EXPECT_FRAME_STATIC_SUBSCHEMA(frame, reference, root_id, expected_pointer, \ + "http://json-schema.org/draft-06/schema#", \ + expected_base, expected_relative_pointer, \ + expected_destination_of_size); + TEST(JSONSchema_frame_draft6, anonymous_with_nested_schema_resource) { const sourcemeta::jsontoolkit::JSON document = sourcemeta::jsontoolkit::parse(R"JSON({ @@ -54,12 +62,12 @@ TEST(JSONSchema_frame_draft6, anonymous_with_nested_schema_resource) { // JSON Pointers - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-06/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-06/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalProperties", "/additionalProperties", "http://json-schema.org/draft-06/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -147,7 +155,7 @@ TEST(JSONSchema_frame_draft6, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT6_POINTER( + EXPECT_FRAME_STATIC_DRAFT6_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/schema", "/items", 0); @@ -159,7 +167,7 @@ TEST(JSONSchema_frame_draft6, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.sourcemeta.com/schema", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT6_POINTER( + EXPECT_FRAME_STATIC_DRAFT6_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", 0); @@ -211,7 +219,7 @@ TEST(JSONSchema_frame_draft6, one_level_applicators_with_identifiers) { frame, "https://www.sourcemeta.com/test/qux#/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT6_POINTER( + EXPECT_FRAME_STATIC_DRAFT6_SUBSCHEMA( frame, "https://www.sourcemeta.com/test/qux#/items", "https://www.sourcemeta.com/test/qux", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -278,7 +286,7 @@ TEST(JSONSchema_frame_draft6, subschema_absolute_identifier) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT6_POINTER( + EXPECT_FRAME_STATIC_DRAFT6_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -424,7 +432,7 @@ TEST(JSONSchema_frame_draft6, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.example.com", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT6_POINTER( + EXPECT_FRAME_STATIC_DRAFT6_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/one", "https://www.sourcemeta.com/schema", "/properties/one", "https://www.example.com/test", "", 0); @@ -432,7 +440,7 @@ TEST(JSONSchema_frame_draft6, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties/one/$id", "https://www.sourcemeta.com/schema", "/properties/one/$id", "https://www.example.com/test", "/$id", 0); - EXPECT_FRAME_STATIC_DRAFT6_POINTER( + EXPECT_FRAME_STATIC_DRAFT6_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/two", "https://www.sourcemeta.com/schema", "/properties/two", "https://www.test.com", "", 0); @@ -472,7 +480,7 @@ TEST(JSONSchema_frame_draft6, ref_metaschema) { EXPECT_EQ(frame.size(), 3); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-06/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-06/schema#", @@ -515,7 +523,7 @@ TEST(JSONSchema_frame_draft6, location_independent_identifier_anonymous) { EXPECT_EQ(frame.size(), 8); // Pointers - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-06/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-06/schema#", @@ -525,7 +533,7 @@ TEST(JSONSchema_frame_draft6, location_independent_identifier_anonymous) { "http://json-schema.org/draft-06/schema#", 0); // Foo - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/definitions/foo", "/definitions/foo", "http://json-schema.org/draft-06/schema#", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -533,7 +541,7 @@ TEST(JSONSchema_frame_draft6, location_independent_identifier_anonymous) { "http://json-schema.org/draft-06/schema#", 0); // Bar - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/definitions/bar", "/definitions/bar", "http://json-schema.org/draft-06/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -577,7 +585,7 @@ TEST(JSONSchema_frame_draft6, ref_with_id) { // JSON Pointers - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-06/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$id", "/$id", "http://json-schema.org/draft-06/schema#", 0); @@ -589,7 +597,7 @@ TEST(JSONSchema_frame_draft6, ref_with_id) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/definitions", "/definitions", "http://json-schema.org/draft-06/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/definitions/string", "/definitions/string", "http://json-schema.org/draft-06/schema#", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -678,17 +686,17 @@ TEST(JSONSchema_frame_draft6, relative_base_uri_with_ref) { "common", "/$id", 0); EXPECT_FRAME_STATIC_DRAFT6_POINTER(frame, "common#/allOf", "common", "/allOf", "common", "/allOf", 0); - EXPECT_FRAME_STATIC_DRAFT6_POINTER(frame, "common#/allOf/0", "common", - "/allOf/0", "common", "/allOf/0", 0); + EXPECT_FRAME_STATIC_DRAFT6_SUBSCHEMA(frame, "common#/allOf/0", "common", + "/allOf/0", "common", "/allOf/0", 0); EXPECT_FRAME_STATIC_DRAFT6_POINTER(frame, "common#/allOf/0/$ref", "common", "/allOf/0/$ref", "common", "/allOf/0/$ref", 0); EXPECT_FRAME_STATIC_DRAFT6_POINTER(frame, "common#/definitions", "common", "/definitions", "common", "/definitions", 0); - EXPECT_FRAME_STATIC_DRAFT6_POINTER(frame, "common#/definitions/foo", "common", - "/definitions/foo", "common", - "/definitions/foo", 1); + EXPECT_FRAME_STATIC_DRAFT6_SUBSCHEMA(frame, "common#/definitions/foo", + "common", "/definitions/foo", "common", + "/definitions/foo", 1); EXPECT_FRAME_STATIC_DRAFT6_POINTER(frame, "common#/definitions/foo/$id", "common", "/definitions/foo/$id", "common", "/definitions/foo/$id", 0); diff --git a/test/jsonschema/jsonschema_frame_draft7_test.cc b/test/jsonschema/jsonschema_frame_draft7_test.cc index 108e1973d..12f6c2d03 100644 --- a/test/jsonschema/jsonschema_frame_draft7_test.cc +++ b/test/jsonschema/jsonschema_frame_draft7_test.cc @@ -30,6 +30,14 @@ expected_base, expected_relative_pointer, \ expected_destination_of_size); +#define EXPECT_FRAME_STATIC_DRAFT7_SUBSCHEMA( \ + frame, reference, root_id, expected_pointer, expected_base, \ + expected_relative_pointer, expected_destination_of_size) \ + EXPECT_FRAME_STATIC_SUBSCHEMA(frame, reference, root_id, expected_pointer, \ + "http://json-schema.org/draft-07/schema#", \ + expected_base, expected_relative_pointer, \ + expected_destination_of_size); + TEST(JSONSchema_frame_draft7, anonymous_with_nested_schema_resource) { const sourcemeta::jsontoolkit::JSON document = sourcemeta::jsontoolkit::parse(R"JSON({ @@ -54,12 +62,12 @@ TEST(JSONSchema_frame_draft7, anonymous_with_nested_schema_resource) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "https://example.com#/$id", "/additionalProperties/$id", "http://json-schema.org/draft-07/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-07/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-07/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/additionalProperties", "/additionalProperties", "http://json-schema.org/draft-07/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -147,7 +155,7 @@ TEST(JSONSchema_frame_draft7, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT7_POINTER( + EXPECT_FRAME_STATIC_DRAFT7_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/schema", "/items", 0); @@ -159,7 +167,7 @@ TEST(JSONSchema_frame_draft7, one_level_applicators_without_identifiers) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.sourcemeta.com/schema", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT7_POINTER( + EXPECT_FRAME_STATIC_DRAFT7_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", "https://www.sourcemeta.com/schema", "/properties/foo", 0); @@ -211,7 +219,7 @@ TEST(JSONSchema_frame_draft7, one_level_applicators_with_identifiers) { frame, "https://www.sourcemeta.com/test/qux#/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", "https://www.sourcemeta.com/test/qux", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT7_POINTER( + EXPECT_FRAME_STATIC_DRAFT7_SUBSCHEMA( frame, "https://www.sourcemeta.com/test/qux#/items", "https://www.sourcemeta.com/test/qux", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -278,7 +286,7 @@ TEST(JSONSchema_frame_draft7, subschema_absolute_identifier) { frame, "https://www.sourcemeta.com/schema#/$schema", "https://www.sourcemeta.com/schema", "/$schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_DRAFT7_POINTER( + EXPECT_FRAME_STATIC_DRAFT7_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/items", "https://www.sourcemeta.com/schema", "/items", "https://www.sourcemeta.com/foo", "", 0); @@ -424,7 +432,7 @@ TEST(JSONSchema_frame_draft7, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties", "https://www.sourcemeta.com/schema", "/properties", "https://www.example.com", "/properties", 0); - EXPECT_FRAME_STATIC_DRAFT7_POINTER( + EXPECT_FRAME_STATIC_DRAFT7_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/one", "https://www.sourcemeta.com/schema", "/properties/one", "https://www.example.com/test", "", 0); @@ -432,7 +440,7 @@ TEST(JSONSchema_frame_draft7, explicit_argument_id_different) { frame, "https://www.sourcemeta.com/schema#/properties/one/$id", "https://www.sourcemeta.com/schema", "/properties/one/$id", "https://www.example.com/test", "/$id", 0); - EXPECT_FRAME_STATIC_DRAFT7_POINTER( + EXPECT_FRAME_STATIC_DRAFT7_SUBSCHEMA( frame, "https://www.sourcemeta.com/schema#/properties/two", "https://www.sourcemeta.com/schema", "/properties/two", "https://www.test.com", "", 0); @@ -472,7 +480,7 @@ TEST(JSONSchema_frame_draft7, ref_metaschema) { EXPECT_EQ(frame.size(), 3); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-07/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-07/schema#", @@ -515,7 +523,7 @@ TEST(JSONSchema_frame_draft7, location_independent_identifier_anonymous) { EXPECT_EQ(frame.size(), 8); // Pointers - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-07/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", "http://json-schema.org/draft-07/schema#", @@ -525,7 +533,7 @@ TEST(JSONSchema_frame_draft7, location_independent_identifier_anonymous) { "http://json-schema.org/draft-07/schema#", 0); // Foo - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/definitions/foo", "/definitions/foo", "http://json-schema.org/draft-07/schema#", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -533,7 +541,7 @@ TEST(JSONSchema_frame_draft7, location_independent_identifier_anonymous) { "http://json-schema.org/draft-07/schema#", 0); // Bar - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/definitions/bar", "/definitions/bar", "http://json-schema.org/draft-07/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -577,7 +585,7 @@ TEST(JSONSchema_frame_draft7, ref_with_id) { // JSON Pointers - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-07/schema#", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$id", "/$id", "http://json-schema.org/draft-07/schema#", 0); @@ -589,7 +597,7 @@ TEST(JSONSchema_frame_draft7, ref_with_id) { EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/definitions", "/definitions", "http://json-schema.org/draft-07/schema#", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/definitions/string", "/definitions/string", "http://json-schema.org/draft-07/schema#", 1); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -678,17 +686,17 @@ TEST(JSONSchema_frame_draft7, relative_base_uri_with_ref) { "common", "/$id", 0); EXPECT_FRAME_STATIC_DRAFT7_POINTER(frame, "common#/allOf", "common", "/allOf", "common", "/allOf", 0); - EXPECT_FRAME_STATIC_DRAFT7_POINTER(frame, "common#/allOf/0", "common", - "/allOf/0", "common", "/allOf/0", 0); + EXPECT_FRAME_STATIC_DRAFT7_SUBSCHEMA(frame, "common#/allOf/0", "common", + "/allOf/0", "common", "/allOf/0", 0); EXPECT_FRAME_STATIC_DRAFT7_POINTER(frame, "common#/allOf/0/$ref", "common", "/allOf/0/$ref", "common", "/allOf/0/$ref", 0); EXPECT_FRAME_STATIC_DRAFT7_POINTER(frame, "common#/definitions", "common", "/definitions", "common", "/definitions", 0); - EXPECT_FRAME_STATIC_DRAFT7_POINTER(frame, "common#/definitions/foo", "common", - "/definitions/foo", "common", - "/definitions/foo", 1); + EXPECT_FRAME_STATIC_DRAFT7_SUBSCHEMA(frame, "common#/definitions/foo", + "common", "/definitions/foo", "common", + "/definitions/foo", 1); EXPECT_FRAME_STATIC_DRAFT7_POINTER(frame, "common#/definitions/foo/$id", "common", "/definitions/foo/$id", "common", "/definitions/foo/$id", 0); diff --git a/test/jsonschema/jsonschema_frame_test.cc b/test/jsonschema/jsonschema_frame_test.cc index 92fcc5749..214b9d553 100644 --- a/test/jsonschema/jsonschema_frame_test.cc +++ b/test/jsonschema/jsonschema_frame_test.cc @@ -63,11 +63,11 @@ TEST(JSONSchema_frame, nested_schemas_mixing_dialects) { "https://www.sourcemeta.com/test", "/$defs", "https://json-schema.org/draft/2020-12/schema", "https://www.sourcemeta.com/test", "/$defs", 0); - EXPECT_FRAME_STATIC_POINTER(frame, - "https://www.sourcemeta.com/test#/$defs/foo", - "https://www.sourcemeta.com/test", "/$defs/foo", - "http://json-schema.org/draft-04/schema#", - "https://www.sourcemeta.com/foo", "", 0); + EXPECT_FRAME_STATIC_SUBSCHEMA(frame, + "https://www.sourcemeta.com/test#/$defs/foo", + "https://www.sourcemeta.com/test", "/$defs/foo", + "http://json-schema.org/draft-04/schema#", + "https://www.sourcemeta.com/foo", "", 0); EXPECT_FRAME_STATIC_POINTER( frame, "https://www.sourcemeta.com/test#/$defs/foo/id", "https://www.sourcemeta.com/test", "/$defs/foo/id", @@ -83,7 +83,7 @@ TEST(JSONSchema_frame, nested_schemas_mixing_dialects) { "https://www.sourcemeta.com/test", "/$defs/foo/definitions", "http://json-schema.org/draft-04/schema#", "https://www.sourcemeta.com/foo", "/definitions", 0); - EXPECT_FRAME_STATIC_POINTER( + EXPECT_FRAME_STATIC_SUBSCHEMA( frame, "https://www.sourcemeta.com/test#/$defs/foo/definitions/bar", "https://www.sourcemeta.com/test", "/$defs/foo/definitions/bar", "http://json-schema.org/draft-04/schema#", @@ -113,7 +113,7 @@ TEST(JSONSchema_frame, nested_schemas_mixing_dialects) { "https://www.sourcemeta.com/test", "/$defs/foo/definitions", "http://json-schema.org/draft-04/schema#", "https://www.sourcemeta.com/foo", "/definitions", 0); - EXPECT_FRAME_STATIC_POINTER( + EXPECT_FRAME_STATIC_SUBSCHEMA( frame, "https://www.sourcemeta.com/foo#/definitions/bar", "https://www.sourcemeta.com/test", "/$defs/foo/definitions/bar", "http://json-schema.org/draft-04/schema#", @@ -178,7 +178,7 @@ TEST(JSONSchema_frame, no_id) { // Top level - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2020-12/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( frame, "#/$schema", "/$schema", @@ -189,7 +189,7 @@ TEST(JSONSchema_frame, no_id) { // Foo - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/properties/foo", "/properties/foo", "https://json-schema.org/draft/2020-12/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -217,7 +217,7 @@ TEST(JSONSchema_frame, no_id) { frame, "https://example.com#/$anchor", "/properties/bar/$anchor", "https://json-schema.org/draft/2020-12/schema", 0); - EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( + EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "#/properties/bar", "/properties/bar", "https://json-schema.org/draft/2020-12/schema", 0); EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( @@ -261,10 +261,11 @@ TEST(JSONSchema_frame, no_id_with_default) { "https://www.sourcemeta.com/schema", "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://www.sourcemeta.com/schema", "/$schema", 0); - EXPECT_FRAME_STATIC_POINTER(frame, "https://www.sourcemeta.com/schema#/items", - "https://www.sourcemeta.com/schema", "/items", - "https://json-schema.org/draft/2020-12/schema", - "https://www.sourcemeta.com/schema", "/items", 0); + EXPECT_FRAME_STATIC_SUBSCHEMA( + frame, "https://www.sourcemeta.com/schema#/items", + "https://www.sourcemeta.com/schema", "/items", + "https://json-schema.org/draft/2020-12/schema", + "https://www.sourcemeta.com/schema", "/items", 0); EXPECT_FRAME_STATIC_POINTER( frame, "https://www.sourcemeta.com/schema#/items/type", "https://www.sourcemeta.com/schema", "/items/type", @@ -323,18 +324,18 @@ TEST(JSONSchema_frame, anchor_on_absolute_subid) { "https://www.example.com", "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://www.example.com", "/$schema", 0); - EXPECT_FRAME_STATIC_POINTER(frame, "https://www.example.com#/items", - "https://www.example.com", "/items", - "https://json-schema.org/draft/2020-12/schema", - "https://www.example.org", "", 0); + EXPECT_FRAME_STATIC_SUBSCHEMA(frame, "https://www.example.com#/items", + "https://www.example.com", "/items", + "https://json-schema.org/draft/2020-12/schema", + "https://www.example.org", "", 0); EXPECT_FRAME_STATIC_POINTER(frame, "https://www.example.com#/items/$id", "https://www.example.com", "/items/$id", "https://json-schema.org/draft/2020-12/schema", "https://www.example.org", "/$id", 0); - EXPECT_FRAME_STATIC_POINTER(frame, "https://www.example.com#/items/items", - "https://www.example.com", "/items/items", - "https://json-schema.org/draft/2020-12/schema", - "https://www.example.org", "/items", 0); + EXPECT_FRAME_STATIC_SUBSCHEMA(frame, "https://www.example.com#/items/items", + "https://www.example.com", "/items/items", + "https://json-schema.org/draft/2020-12/schema", + "https://www.example.org", "/items", 0); EXPECT_FRAME_STATIC_POINTER(frame, "https://www.example.com#/items/items/$anchor", "https://www.example.com", "/items/items/$anchor", @@ -344,10 +345,10 @@ TEST(JSONSchema_frame, anchor_on_absolute_subid) { "https://www.example.com", "/items/$id", "https://json-schema.org/draft/2020-12/schema", "https://www.example.org", "/$id", 0); - EXPECT_FRAME_STATIC_POINTER(frame, "https://www.example.org#/items", - "https://www.example.com", "/items/items", - "https://json-schema.org/draft/2020-12/schema", - "https://www.example.org", "/items", 0); + EXPECT_FRAME_STATIC_SUBSCHEMA(frame, "https://www.example.org#/items", + "https://www.example.com", "/items/items", + "https://json-schema.org/draft/2020-12/schema", + "https://www.example.org", "/items", 0); EXPECT_FRAME_STATIC_POINTER(frame, "https://www.example.org#/items/$anchor", "https://www.example.com", "/items/items/$anchor", "https://json-schema.org/draft/2020-12/schema", diff --git a/test/jsonschema/jsonschema_test_utils.h b/test/jsonschema/jsonschema_test_utils.h index 4ceaca75c..c5e9fa3ec 100644 --- a/test/jsonschema/jsonschema_test_utils.h +++ b/test/jsonschema/jsonschema_test_utils.h @@ -57,6 +57,18 @@ .type, \ sourcemeta::jsontoolkit::FrameLocationType::Pointer); +#define EXPECT_FRAME_STATIC_SUBSCHEMA( \ + frame, reference, root_id, expected_pointer, expected_dialect, \ + expected_base, expected_relative_pointer, expected_destination_of_size) \ + EXPECT_FRAME_STATIC(frame, reference, root_id, expected_pointer, \ + expected_dialect, expected_base, \ + expected_relative_pointer, expected_destination_of_size) \ + EXPECT_EQ( \ + (frame) \ + .at({sourcemeta::jsontoolkit::ReferenceType::Static, (reference)}) \ + .type, \ + sourcemeta::jsontoolkit::FrameLocationType::Subschema); + #define EXPECT_FRAME_STATIC_ANCHOR( \ frame, reference, root_id, expected_pointer, expected_dialect, \ expected_base, expected_relative_pointer, expected_destination_of_size) \ @@ -132,6 +144,18 @@ .type, \ sourcemeta::jsontoolkit::FrameLocationType::Pointer); +#define EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( \ + frame, reference, expected_pointer, expected_dialect, \ + expected_destination_of_size) \ + __EXPECT_ANONYMOUS_FRAME( \ + frame, sourcemeta::jsontoolkit::ReferenceType::Static, reference, \ + expected_pointer, expected_dialect, expected_destination_of_size) \ + EXPECT_EQ( \ + (frame) \ + .at({sourcemeta::jsontoolkit::ReferenceType::Static, (reference)}) \ + .type, \ + sourcemeta::jsontoolkit::FrameLocationType::Subschema); + #define EXPECT_ANONYMOUS_FRAME_STATIC_ANCHOR( \ frame, reference, expected_pointer, expected_dialect, \ expected_destination_of_size) \