| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #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 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_P2(AnnotationAt, key, matcher, "") {
- auto const * anno = arg.annotation({}, {}, key);
- if (not anno) {
- return false;
- }
- return testing::ExplainMatchResult(matcher, *anno, result_listener);
- }
- MATCHER_P4(AnnotationAt, doc_path, schema_path, key, matcher, "") {
- auto const * anno = arg.annotation(doc_path, schema_path, key);
- if (not anno) {
- return false;
- }
- return testing::ExplainMatchResult(matcher, *anno, result_listener);
- }
- MATCHER_P2(ErrorAt, key, matcher, "") {
- auto const * anno = arg.error({}, {}, key);
- if (not anno) {
- return false;
- }
- return testing::ExplainMatchResult(matcher, *anno, result_listener);
- }
- MATCHER_P4(ErrorAt, doc_path, schema_path, key, matcher, "") {
- auto const * anno = arg.error(doc_path, schema_path, key);
- if (not anno) {
- return false;
- }
- return testing::ExplainMatchResult(matcher, *anno, result_listener);
- }
|