matchers.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #pragma once
  2. #include <util/generic/string.h>
  3. #include <gtest/gtest.h>
  4. #include <gmock/gmock.h>
  5. namespace testing {
  6. /**
  7. * When matching `const TStringBuf&`, implicitly convert other strings and string views to `Eq` matchers.
  8. */
  9. template <typename T, typename TT>
  10. class Matcher<const TBasicStringBuf<T, TT>&>: public internal::MatcherBase<const TBasicStringBuf<T, TT>&> {
  11. public:
  12. Matcher() {
  13. }
  14. explicit Matcher(const MatcherInterface<const TBasicStringBuf<T, TT>&>* impl)
  15. : internal::MatcherBase<const TBasicStringBuf<T, TT>&>(impl) {
  16. }
  17. template <typename M, typename = typename std::remove_reference<M>::type::is_gtest_matcher>
  18. Matcher(M&& m)
  19. : internal::MatcherBase<const TBasicStringBuf<T, TT>&>(std::forward<M>(m)) {
  20. }
  21. Matcher(const TBasicString<T, TT>& s) {
  22. *this = Eq(TBasicStringBuf<T, TT>(s));
  23. }
  24. Matcher(const T* s) {
  25. *this = Eq(TBasicStringBuf<T, TT>(s));
  26. }
  27. Matcher(TBasicStringBuf<T, TT> s) {
  28. *this = Eq(s);
  29. }
  30. };
  31. /**
  32. * When matching `TBasicBuf`, implicitly convert other strings and string views to `Eq` matchers.
  33. */
  34. template <typename T, typename TT>
  35. class Matcher<TBasicStringBuf<T, TT>>: public internal::MatcherBase<TBasicStringBuf<T, TT>> {
  36. public:
  37. Matcher() {
  38. }
  39. explicit Matcher(const MatcherInterface <TBasicStringBuf<T, TT>>* impl)
  40. : internal::MatcherBase<TBasicStringBuf<T, TT>>(impl) {
  41. }
  42. explicit Matcher(const MatcherInterface<const TBasicStringBuf<T, TT>&>* impl)
  43. : internal::MatcherBase<TBasicStringBuf<T, TT>>(impl) {
  44. }
  45. template <typename M, typename = typename std::remove_reference<M>::type::is_gtest_matcher>
  46. Matcher(M&& m)
  47. : internal::MatcherBase<TBasicStringBuf<T, TT>>(std::forward<M>(m)) {
  48. }
  49. Matcher(const TBasicString<T, TT>& s) {
  50. *this = Eq(TBasicString<T, TT>(s));
  51. }
  52. Matcher(const T* s) {
  53. *this = Eq(TBasicString<T, TT>(s));
  54. }
  55. Matcher(TBasicStringBuf<T, TT> s) {
  56. *this = Eq(s);
  57. }
  58. };
  59. /**
  60. * When matching `const TString&`, implicitly convert other strings and string views to `Eq` matchers.
  61. */
  62. template <typename T, typename TT>
  63. class Matcher<const TBasicString<T, TT>&>: public internal::MatcherBase<const TBasicString<T, TT>&> {
  64. public:
  65. Matcher() {
  66. }
  67. explicit Matcher(const MatcherInterface<const TBasicString<T, TT>&>* impl)
  68. : internal::MatcherBase<const TBasicString<T, TT>&>(impl) {
  69. }
  70. Matcher(const TBasicString<T, TT>& s) {
  71. *this = Eq(s);
  72. }
  73. template <typename M, typename = typename std::remove_reference<M>::type::is_gtest_matcher>
  74. Matcher(M&& m)
  75. : internal::MatcherBase<const TBasicString<T, TT>&>(std::forward<M>(m)) {
  76. }
  77. Matcher(const T* s) {
  78. *this = Eq(TBasicString<T, TT>(s));
  79. }
  80. };
  81. /**
  82. * When matching `TString`, implicitly convert other strings and string views to `Eq` matchers.
  83. */
  84. template <typename T, typename TT>
  85. class Matcher<TBasicString<T, TT>>: public internal::MatcherBase<TBasicString<T, TT>> {
  86. public:
  87. Matcher() {
  88. }
  89. explicit Matcher(const MatcherInterface <TBasicString<T, TT>>* impl)
  90. : internal::MatcherBase<TBasicString<T, TT>>(impl) {
  91. }
  92. explicit Matcher(const MatcherInterface<const TBasicString<T, TT>&>* impl)
  93. : internal::MatcherBase<TBasicString<T, TT>>(impl) {
  94. }
  95. template <typename M, typename = typename std::remove_reference<M>::type::is_gtest_matcher>
  96. Matcher(M&& m)
  97. : internal::MatcherBase<TBasicString<T, TT>>(std::forward<M>(m)) {
  98. }
  99. Matcher(const TBasicString<T, TT>& s) {
  100. *this = Eq(s);
  101. }
  102. Matcher(const T* s) {
  103. *this = Eq(TBasicString<T, TT>(s));
  104. }
  105. };
  106. }