|
|
@@ -1,6 +1,8 @@
|
|
|
+#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>
|
|
|
|
|
|
@@ -31,34 +33,40 @@ 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);
|
|
|
+ *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);
|
|
|
}
|
|
|
|
|
|
-MATCHER_P2(ErrorAt, key, matcher, "") {
|
|
|
- auto const * anno = arg.error({}, {}, key);
|
|
|
- if (not anno) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- 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));
|
|
|
+}
|