#include #include #include #include #include #include #include inline auto operator""_jptr(char const * data, size_t len) { return jvalidate::detail::Pointer::parse(std::string_view{data, len}).value(); } inline auto operator""_relptr(char const * data, size_t len) { return jvalidate::detail::RelativePointer::parse(std::string_view{data, len}).value(); } inline Json::Value operator""_json(char const * data, size_t len) { Json::Value value; Json::CharReaderBuilder builder; std::unique_ptr reader(builder.newCharReader()); std::string error; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (not reader->parse(data, data + len, &value, &error)) { throw std::runtime_error(error); } return value; } MATCHER_P(Expected, m, "") { if (arg.has_value()) { return testing::ExplainMatchResult(m, arg.value(), result_listener); } return false; } MATCHER_P(Unexpected, m, "") { if (not arg.has_value()) { return testing::ExplainMatchResult(m, arg.error(), result_listener); } return false; } MATCHER(Valid, "") { return arg.valid(); } MATCHER_P(HasAnnotationsFor, doc_path, "") { return arg.has(doc_path); } MATCHER_P2(HasAnnotationAt, doc_path, schema_path, "") { return arg.has(doc_path, schema_path); } MATCHER_P4(AnnotationAt, doc_path, schema_path, key, matcher, "") { auto const * anno = arg.annotation(doc_path, schema_path, key); *result_listener << "\ninstanceLocation: " << doc_path << " is " << (arg.has(doc_path) ? "present" : "missing"); *result_listener << "\nevaluationLocation: " << schema_path << " is " << (arg.has(doc_path, schema_path) ? "present" : "missing"); if (not anno) { *result_listener << "\nannotation: (nil)"; return false; } *result_listener << "\nannotation: " << testing::PrintToString(*anno); return testing::ExplainMatchResult(matcher, *anno, result_listener); } template auto AnnotationAt(std::string const & key, M && matcher) { return AnnotationAt(jvalidate::detail::Pointer(), jvalidate::detail::Pointer(), key, std::forward(matcher)); } MATCHER_P4(ErrorAt, doc_path, schema_path, key, matcher, "") { auto const * anno = arg.error(doc_path, schema_path, key); *result_listener << "\ninstanceLocation: " << doc_path << " is " << (arg.has(doc_path) ? "present" : "missing"); *result_listener << "\nevaluationLocation: " << schema_path << " is " << (arg.has(doc_path, schema_path) ? "present" : "missing"); if (not anno) { *result_listener << "\nannotation: (nil)"; return false; } *result_listener << "\nannotation: " << testing::PrintToString(*anno); return testing::ExplainMatchResult(matcher, *anno, result_listener); } template auto ErrorAt(std::string const & key, M && matcher) { return ErrorAt(jvalidate::detail::Pointer(), jvalidate::detail::Pointer(), key, std::forward(matcher)); }