mirror of
https://github.com/google/googletest.git
synced 2024-12-26 17:41:03 +08:00
StartsWith: Explicitly construct matcher-typed strings from matchee parameter
The current implementation breaks for absl::string_view on gcc, c++14: https://godbolt.org/z/Tzd3q1fqx Closes #4391 PiperOrigin-RevId: 575853981 Change-Id: I7b782598add480eb69d4ca27ea4a4bf5f758f6a3
This commit is contained in:
parent
116b7e5528
commit
518387203b
@ -1048,7 +1048,7 @@ class StartsWithMatcher {
|
||||
template <typename MatcheeStringType>
|
||||
bool MatchAndExplain(const MatcheeStringType& s,
|
||||
MatchResultListener* /* listener */) const {
|
||||
const StringType& s2(s);
|
||||
const StringType s2(s);
|
||||
return s2.length() >= prefix_.length() &&
|
||||
s2.substr(0, prefix_.length()) == prefix_;
|
||||
}
|
||||
@ -1102,7 +1102,7 @@ class EndsWithMatcher {
|
||||
template <typename MatcheeStringType>
|
||||
bool MatchAndExplain(const MatcheeStringType& s,
|
||||
MatchResultListener* /* listener */) const {
|
||||
const StringType& s2(s);
|
||||
const StringType s2(s);
|
||||
return s2.length() >= suffix_.length() &&
|
||||
s2.substr(s2.length() - suffix_.length()) == suffix_;
|
||||
}
|
||||
|
@ -1769,6 +1769,15 @@ TEST(StartsWithTest, CanDescribeSelf) {
|
||||
EXPECT_EQ("starts with \"Hi\"", Describe(m));
|
||||
}
|
||||
|
||||
TEST(StartsWithTest, WorksWithStringMatcherOnStringViewMatchee) {
|
||||
#if GTEST_INTERNAL_HAS_STRING_VIEW
|
||||
EXPECT_THAT(internal::StringView("talk to me goose"),
|
||||
StartsWith(std::string("talk")));
|
||||
#else
|
||||
GTEST_SKIP() << "Not applicable without internal::StringView.";
|
||||
#endif // GTEST_INTERNAL_HAS_STRING_VIEW
|
||||
}
|
||||
|
||||
// Tests EndsWith(s).
|
||||
|
||||
TEST(EndsWithTest, MatchesStringWithGivenSuffix) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user