| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include "gtest/internal/gtest-internal.h"
- #include <gmock/gmock.h>
- #include <gtest/gtest.h>
- #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(std::string_view{data, len});
- }
- inline Json::Value const 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));
- }
|