From c2656586f991e25d69ff58173fe2c653869ec427 Mon Sep 17 00:00:00 2001 From: Patrick Boettcher Date: Fri, 10 Dec 2021 15:13:26 +0100 Subject: [PATCH] more complex default-value-tests - fails --- test/issue-189-default-values.cpp | 43 +++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/test/issue-189-default-values.cpp b/test/issue-189-default-values.cpp index 0fb7cc5..94ec2db 100644 --- a/test/issue-189-default-values.cpp +++ b/test/issue-189-default-values.cpp @@ -2,35 +2,52 @@ #include using nlohmann::json; +using nlohmann::json_uri; using nlohmann::json_schema::json_validator; -static const json rectangle_schema = R"( +static const json quad_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", - "title": "A rectangle", "properties": { "width": { "$ref": "#/definitions/length", - "default": 20 + "default": 20 }, "height": { "$ref": "#/definitions/length" + }, + "depths": { + "$ref": "default_schema#/definitions/defaultLength" } }, - "definitions": { + "definitions": { "length": { - "type": "integer", - "default": 10 - } - }, - "additionalProperties": false, - "type": "object" + "$ref": "default_schema#/definitions/defaultLength", + "default": 10 + } + } })"_json; +static const json default_schema = R"( +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "defaultLength": { + "default": 5 + } + } +})"_json; + +static void loader(const json_uri &uri, json &schema) +{ + schema = default_schema; +} + int main(void) { - json_validator validator{}; - validator.set_root_schema(rectangle_schema); + json_validator validator(loader); + + validator.set_root_schema(quad_schema); { json empty_rectangle = R"({})"_json; @@ -39,7 +56,7 @@ int main(void) const auto actual = empty_rectangle.patch(default_patch); // height must be 10 according to the default specified in the length definition while width must be 10 overridden by the width element - const auto expected = R"({"height":10,"width":20})"_json; + const auto expected = R"({"height":10,"width":20,"depth":5})"_json; if (actual != expected) { std::cerr << "Patch with defaults contains wrong value: '" << actual << "' instead of expected '" << expected.dump() << "'" << std::endl; return 1;