Add test for issue 243
This commit is contained in:
parent
59c9d6200b
commit
cae6fad800
@ -73,3 +73,7 @@ add_test(NAME issue-149-entry-selection COMMAND issue-149-entry-selection)
|
||||
add_executable(issue-189-default-values issue-189-default-values.cpp)
|
||||
target_link_libraries(issue-189-default-values nlohmann_json_schema_validator)
|
||||
add_test(NAME issue-189-default-values COMMAND issue-189-default-values)
|
||||
|
||||
add_executable(issue-243-root-default-values issue-243-root-default-values.cpp)
|
||||
target_link_libraries(issue-243-root-default-values nlohmann_json_schema_validator)
|
||||
add_test(NAME issue-243-root-default-values COMMAND issue-243-root-default-values)
|
||||
|
||||
48
test/issue-243-root-default-values.cpp
Normal file
48
test/issue-243-root-default-values.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json-schema.hpp>
|
||||
|
||||
using nlohmann::json;
|
||||
using nlohmann::json_uri;
|
||||
using nlohmann::json_schema::json_validator;
|
||||
|
||||
static const json root_default = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
"width": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"width": 42
|
||||
}
|
||||
})"_json;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
json_validator validator{};
|
||||
|
||||
validator.set_root_schema(root_default);
|
||||
|
||||
{
|
||||
json nul_json;
|
||||
if (!nul_json.is_null()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const auto default_patch = validator.validate(nul_json);
|
||||
|
||||
if (default_patch.is_null()) {
|
||||
std::cerr << "Patch is null but should contain operation to add defaults to root" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const auto actual = nul_json.patch(default_patch);
|
||||
const auto expected = R"({"width": 42})"_json;
|
||||
if (actual != expected) {
|
||||
std::cerr << "Patch of defaults is wrong for root schema: '" << actual.dump() << "' instead of expected '" << expected.dump() << "'" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user