Skip to content

Commit

Permalink
Googletest export
Browse files Browse the repository at this point in the history
Add gmock Matcher<std::string_view> specialization.

PiperOrigin-RevId: 294443240
  • Loading branch information
Abseil Team authored and mbxx committed Feb 11, 2020
1 parent d093073 commit 6f5fd0d
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 164 deletions.
40 changes: 20 additions & 20 deletions googlemock/include/gmock/gmock-matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -906,15 +906,15 @@ class StrEqualityMatcher {
bool case_sensitive)
: string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {}

#if GTEST_HAS_ABSL
bool MatchAndExplain(const absl::string_view& s,
#if GTEST_INTERNAL_HAS_STRING_VIEW
bool MatchAndExplain(const internal::StringView& s,
MatchResultListener* listener) const {
// This should fail to compile if absl::string_view is used with wide
// This should fail to compile if StringView is used with wide
// strings.
const StringType& str = std::string(s);
return MatchAndExplain(str, listener);
}
#endif // GTEST_HAS_ABSL
#endif // GTEST_INTERNAL_HAS_STRING_VIEW

// Accepts pointer types, particularly:
// const char*
Expand All @@ -932,7 +932,7 @@ class StrEqualityMatcher {
// Matches anything that can convert to StringType.
//
// This is a template, not just a plain function with const StringType&,
// because absl::string_view has some interfering non-explicit constructors.
// because StringView has some interfering non-explicit constructors.
template <typename MatcheeStringType>
bool MatchAndExplain(const MatcheeStringType& s,
MatchResultListener* /* listener */) const {
Expand Down Expand Up @@ -976,15 +976,15 @@ class HasSubstrMatcher {
explicit HasSubstrMatcher(const StringType& substring)
: substring_(substring) {}

#if GTEST_HAS_ABSL
bool MatchAndExplain(const absl::string_view& s,
#if GTEST_INTERNAL_HAS_STRING_VIEW
bool MatchAndExplain(const internal::StringView& s,
MatchResultListener* listener) const {
// This should fail to compile if absl::string_view is used with wide
// This should fail to compile if StringView is used with wide
// strings.
const StringType& str = std::string(s);
return MatchAndExplain(str, listener);
}
#endif // GTEST_HAS_ABSL
#endif // GTEST_INTERNAL_HAS_STRING_VIEW

// Accepts pointer types, particularly:
// const char*
Expand All @@ -999,7 +999,7 @@ class HasSubstrMatcher {
// Matches anything that can convert to StringType.
//
// This is a template, not just a plain function with const StringType&,
// because absl::string_view has some interfering non-explicit constructors.
// because StringView has some interfering non-explicit constructors.
template <typename MatcheeStringType>
bool MatchAndExplain(const MatcheeStringType& s,
MatchResultListener* /* listener */) const {
Expand Down Expand Up @@ -1032,15 +1032,15 @@ class StartsWithMatcher {
explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
}

#if GTEST_HAS_ABSL
bool MatchAndExplain(const absl::string_view& s,
#if GTEST_INTERNAL_HAS_STRING_VIEW
bool MatchAndExplain(const internal::StringView& s,
MatchResultListener* listener) const {
// This should fail to compile if absl::string_view is used with wide
// This should fail to compile if StringView is used with wide
// strings.
const StringType& str = std::string(s);
return MatchAndExplain(str, listener);
}
#endif // GTEST_HAS_ABSL
#endif // GTEST_INTERNAL_HAS_STRING_VIEW

// Accepts pointer types, particularly:
// const char*
Expand All @@ -1055,7 +1055,7 @@ class StartsWithMatcher {
// Matches anything that can convert to StringType.
//
// This is a template, not just a plain function with const StringType&,
// because absl::string_view has some interfering non-explicit constructors.
// because StringView has some interfering non-explicit constructors.
template <typename MatcheeStringType>
bool MatchAndExplain(const MatcheeStringType& s,
MatchResultListener* /* listener */) const {
Expand Down Expand Up @@ -1088,15 +1088,15 @@ class EndsWithMatcher {
public:
explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}

#if GTEST_HAS_ABSL
bool MatchAndExplain(const absl::string_view& s,
#if GTEST_INTERNAL_HAS_STRING_VIEW
bool MatchAndExplain(const internal::StringView& s,
MatchResultListener* listener) const {
// This should fail to compile if absl::string_view is used with wide
// This should fail to compile if StringView is used with wide
// strings.
const StringType& str = std::string(s);
return MatchAndExplain(str, listener);
}
#endif // GTEST_HAS_ABSL
#endif // GTEST_INTERNAL_HAS_STRING_VIEW

// Accepts pointer types, particularly:
// const char*
Expand All @@ -1111,7 +1111,7 @@ class EndsWithMatcher {
// Matches anything that can convert to StringType.
//
// This is a template, not just a plain function with const StringType&,
// because absl::string_view has some interfering non-explicit constructors.
// because StringView has some interfering non-explicit constructors.
template <typename MatcheeStringType>
bool MatchAndExplain(const MatcheeStringType& s,
MatchResultListener* /* listener */) const {
Expand Down
Loading

0 comments on commit 6f5fd0d

Please sign in to comment.