1#include "nlohmann/json-schema.hpp"
2#include "nlohmann/json.hpp"
12#define LOG_ERROR(LOG_ERROR__ARGS)
13 std::cerr << __FILE__ << ":" << __LINE__ << ": " << LOG_ERROR__ARGS << std::endl
15#define EXPECT_THROW_WITH_MESSAGE(EXPRESSION, MESSAGE)
19 LOG_ERROR("Expected exception not thrown with matching regex: \"" << MESSAGE << "\"");
21 } catch (const std::exception &error) {
22 const std::regex error_re{MESSAGE};
23 if (!std::regex_search(error.what(), error_re)) {
24 LOG_ERROR("Expected exception with matching regex: \"" << MESSAGE << "\", but got this instead: " << error.what());
30#define ASSERT_OR_EXPECT_EQ(FIRST_THING, SECOND_THING, RETURN_IN_CASE_OF_ERROR)
32 if ((FIRST_THING) != (SECOND_THING)) {
33 LOG_ERROR("The two values of " << (FIRST_THING) << " (" #FIRST_THING << ") and " << (SECOND_THING) << " (" #SECOND_THING << ") should be equal");
34 if (RETURN_IN_CASE_OF_ERROR) {
43#define EXPECT_MATCH(STRING, REGEX)
45 if (!std::regex_search((STRING), std::regex{(REGEX)})) {
46 LOG_ERROR("String \"" << (STRING) << "\" doesn't match with regex: \"" << (REGEX) << "\"");
63{
64 "properties": {
65 "first": {
66 "%COMBINATION_FIRST_LEVEL%": [
67 {
68 "properties": {
69 "second": {
70 "%COMBINATION_SECOND_LEVEL%": [
71 {
72 "minimum": 5,
73 "type": "integer"
74 },
75 {
76 "multipleOf": 2,
77 "type": "integer"
78 }
79 ]
80 }
81 },
82 "type": "object"
83 },
84 {
85 "minimum": 20,
86 "type": "integer"
87 },
88 {
89 "minLength": 10,
90 "type": "string"
91 }
92 ]
93 }
94 },
95 "type": "object"
96}
97)";
101 static const std::regex first_replace_re{
"%COMBINATION_FIRST_LEVEL%"};
102 static const std::regex second_replace_re{
"%COMBINATION_SECOND_LEVEL%"};
104 std::string intermediate = std::regex_replace(
g_schema_template, first_replace_re, first_combination);
106 return nlohmann::json::parse(std::regex_replace(intermediate, second_replace_re, second_combination));
129 auto error(
const nlohmann::json::json_pointer &ptr,
const nlohmann::json &instance,
const std::string &message) ->
void override
140auto operator<<(std::string first,
const std::string &second) -> std::string
147auto rootError(
const std::string &combination_type, std::size_t number_of_subschemas) -> std::string
149 return "no subschema has succeeded, but one of them is required to validate. Type: " + combination_type +
", number of failed subschemas: " + std::to_string(number_of_subschemas);
152auto combinationError(
const std::string &combination_type, std::size_t test_case_number) -> std::string
154 return "[combination: " + combination_type +
" / case#" + std::to_string(test_case_number) +
"]";
175auto simpleTest(
const std::string &first_combination,
const std::string &second_combination) ->
void
179 if (second_combination ==
"oneOf") {
186auto verboseTest(
const std::string &first_combination,
const std::string &second_combination) ->
void
242 if (second_combination ==
"oneOf") {
std::vector< ErrorEntry > ErrorEntryList
auto error(const nlohmann::json::json_pointer &ptr, const nlohmann::json &instance, const std::string &message) -> void override
ErrorEntryList m_error_list
auto getErrors() const -> const ErrorEntryList &
void set_root_schema(const json &)
json validate(const json &, error_handler &, const json_uri &initial_uri=json_uri("#")) const
json validate(const json &) const
#define ASSERT_OR_EXPECT_EQ(FIRST_THING, SECOND_THING, RETURN_IN_CASE_OF_ERROR)
#define EXPECT_THROW_WITH_MESSAGE(EXPRESSION, MESSAGE)
#define LOG_ERROR(LOG_ERROR__ARGS)
#define EXPECT_MATCH(STRING, REGEX)
auto combinationError(const std::string &combination_type, std::size_t test_case_number) -> std::string
auto simpleTest(const std::string &first_combination, const std::string &second_combination) -> void
auto validate(const nlohmann::json &schema, const nlohmann::json &instance, nlohmann::json_schema::error_handler *error_handler=nullptr) -> void
auto verboseTest(const std::string &first_combination, const std::string &second_combination) -> void
auto operator<<(std::string first, const std::string &second) -> std::string
auto rootError(const std::string &combination_type, std::size_t number_of_subschemas) -> std::string
auto generateSchema(const std::string &first_combination, const std::string &second_combination) -> nlohmann::json
const std::string g_schema_template
nlohmann::json::json_pointer ptr