Make string matchers work with std::wstring_view

Fixes: #4912
PiperOrigin-RevId: 953423131
Change-Id: Id288c01c9d1bd9c92ce78b89ec3e8587f4ffc2a7
This commit is contained in:
Abseil Team
2026-07-24 10:03:44 -07:00
committed by Copybara-Service
parent a798392000
commit fef8e5e23b
3 changed files with 77 additions and 95 deletions
@@ -1254,22 +1254,22 @@ TEST(RefTest, ExplainsResult) {
// Tests string comparison matchers.
template <typename T = std::string>
std::string FromStringLike(internal::StringLike<T> str) {
return std::string(str);
internal::StringType<T> ToString(T str) {
return internal::StringType<T>(str);
}
TEST(StringLike, TestConversions) {
EXPECT_EQ("foo", FromStringLike("foo"));
EXPECT_EQ("foo", FromStringLike(std::string("foo")));
TEST(StringType, TestConversions) {
EXPECT_EQ("foo", ToString("foo"));
EXPECT_EQ("foo", ToString(std::string("foo")));
#if GTEST_INTERNAL_HAS_STRING_VIEW
EXPECT_EQ("foo", FromStringLike(internal::StringView("foo")));
EXPECT_EQ("foo", ToString(internal::StringView("foo")));
#endif // GTEST_INTERNAL_HAS_STRING_VIEW
// Non deducible types.
EXPECT_EQ("", FromStringLike({}));
EXPECT_EQ("foo", FromStringLike({'f', 'o', 'o'}));
EXPECT_EQ("", ToString({}));
EXPECT_EQ("foo", ToString({'f', 'o', 'o'}));
const char buf[] = "foo";
EXPECT_EQ("foo", FromStringLike({buf, buf + 3}));
EXPECT_EQ("foo", ToString({buf, buf + 3}));
}
TEST(StrEqTest, MatchesEqualString) {