aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/testing/gtest_extensions/matchers.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/testing/gtest_extensions/matchers.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/testing/gtest_extensions/matchers.h')
-rw-r--r--library/cpp/testing/gtest_extensions/matchers.h132
1 files changed, 132 insertions, 0 deletions
diff --git a/library/cpp/testing/gtest_extensions/matchers.h b/library/cpp/testing/gtest_extensions/matchers.h
new file mode 100644
index 0000000000..044c1c3ee4
--- /dev/null
+++ b/library/cpp/testing/gtest_extensions/matchers.h
@@ -0,0 +1,132 @@
+#pragma once
+
+#include <util/generic/string.h>
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+namespace testing {
+ /**
+ * When matching `const TStringBuf&`, implicitly convert other strings and string views to `Eq` matchers.
+ */
+ template <typename T, typename TT>
+ class Matcher<const TBasicStringBuf<T, TT>&>: public internal::MatcherBase<const TBasicStringBuf<T, TT>&> {
+ public:
+ Matcher() {
+ }
+
+ explicit Matcher(const MatcherInterface<const TBasicStringBuf<T, TT>&>* impl)
+ : internal::MatcherBase<const TBasicStringBuf<T, TT>&>(impl) {
+ }
+
+ template <typename M, typename = typename std::remove_reference<M>::type::is_gtest_matcher>
+ Matcher(M&& m)
+ : internal::MatcherBase<const TBasicStringBuf<T, TT>&>(std::forward<M>(m)) {
+ }
+
+ Matcher(const TBasicString<T, TT>& s) {
+ *this = Eq(TBasicStringBuf<T, TT>(s));
+ }
+
+ Matcher(const T* s) {
+ *this = Eq(TBasicStringBuf<T, TT>(s));
+ }
+
+ Matcher(TBasicStringBuf<T, TT> s) {
+ *this = Eq(s);
+ }
+ };
+
+ /**
+ * When matching `TBasicBuf`, implicitly convert other strings and string views to `Eq` matchers.
+ */
+ template <typename T, typename TT>
+ class Matcher<TBasicStringBuf<T, TT>>: public internal::MatcherBase<TBasicStringBuf<T, TT>> {
+ public:
+ Matcher() {
+ }
+
+ explicit Matcher(const MatcherInterface <TBasicStringBuf<T, TT>>* impl)
+ : internal::MatcherBase<TBasicStringBuf<T, TT>>(impl) {
+ }
+
+ explicit Matcher(const MatcherInterface<const TBasicStringBuf<T, TT>&>* impl)
+ : internal::MatcherBase<TBasicStringBuf<T, TT>>(impl) {
+ }
+
+ template <typename M, typename = typename std::remove_reference<M>::type::is_gtest_matcher>
+ Matcher(M&& m)
+ : internal::MatcherBase<TBasicStringBuf<T, TT>>(std::forward<M>(m)) {
+ }
+
+ Matcher(const TBasicString<T, TT>& s) {
+ *this = Eq(TBasicString<T, TT>(s));
+ }
+
+ Matcher(const T* s) {
+ *this = Eq(TBasicString<T, TT>(s));
+ }
+
+ Matcher(TBasicStringBuf<T, TT> s) {
+ *this = Eq(s);
+ }
+ };
+
+ /**
+ * When matching `const TString&`, implicitly convert other strings and string views to `Eq` matchers.
+ */
+ template <typename T, typename TT>
+ class Matcher<const TBasicString<T, TT>&>: public internal::MatcherBase<const TBasicString<T, TT>&> {
+ public:
+ Matcher() {
+ }
+
+ explicit Matcher(const MatcherInterface<const TBasicString<T, TT>&>* impl)
+ : internal::MatcherBase<const TBasicString<T, TT>&>(impl) {
+ }
+
+ Matcher(const TBasicString<T, TT>& s) {
+ *this = Eq(s);
+ }
+
+ template <typename M, typename = typename std::remove_reference<M>::type::is_gtest_matcher>
+ Matcher(M&& m)
+ : internal::MatcherBase<const TBasicString<T, TT>&>(std::forward<M>(m)) {
+ }
+
+ Matcher(const T* s) {
+ *this = Eq(TBasicString<T, TT>(s));
+ }
+ };
+
+ /**
+ * When matching `TString`, implicitly convert other strings and string views to `Eq` matchers.
+ */
+ template <typename T, typename TT>
+ class Matcher<TBasicString<T, TT>>: public internal::MatcherBase<TBasicString<T, TT>> {
+ public:
+ Matcher() {
+ }
+
+ explicit Matcher(const MatcherInterface <TBasicString<T, TT>>* impl)
+ : internal::MatcherBase<TBasicString<T, TT>>(impl) {
+ }
+
+ explicit Matcher(const MatcherInterface<const TBasicString<T, TT>&>* impl)
+ : internal::MatcherBase<TBasicString<T, TT>>(impl) {
+ }
+
+ template <typename M, typename = typename std::remove_reference<M>::type::is_gtest_matcher>
+ Matcher(M&& m)
+ : internal::MatcherBase<TBasicString<T, TT>>(std::forward<M>(m)) {
+ }
+
+ Matcher(const TBasicString<T, TT>& s) {
+ *this = Eq(s);
+ }
+
+ Matcher(const T* s) {
+ *this = Eq(TBasicString<T, TT>(s));
+ }
+ };
+}