| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include "gtest/internal/gtest-internal.h"
- #include <gmock/gmock.h>
- #include <gtest/gtest.h>
- #include <ios>
- #include <jvalidate/detail/pointer.h>
- #include <jvalidate/validation_result.h>
- #include <json/reader.h>
- #include <json/value.h>
- inline auto operator""_jptr(char const * data, size_t len) {
- return jvalidate::detail::Pointer::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<Json::CharReader> reader(builder.newCharReader());
- std::string error;
- if (not reader->parse(data, data + len, &value, &error)) {
- throw std::runtime_error(error);
- }
- return value;
- }
- 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 <typename M> auto AnnotationAt(std::string const & key, M && matcher) {
- return AnnotationAt(jvalidate::detail::Pointer(), jvalidate::detail::Pointer(), key,
- std::forward<M>(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 <typename M> auto ErrorAt(std::string const & key, M && matcher) {
- return ErrorAt(jvalidate::detail::Pointer(), jvalidate::detail::Pointer(), key,
- std::forward<M>(matcher));
- }
|