@@ -1226,6 +1226,25 @@ TEST(RefTest, ExplainsResult) {
12261226
12271227// Tests string comparison matchers.
12281228
1229+ template <typename T = std::string>
1230+ std::string FromStringLike (internal::StringLike<T> str) {
1231+ return std::string (str);
1232+ }
1233+
1234+ TEST (StringLike, TestConversions) {
1235+ EXPECT_EQ (" foo" , FromStringLike (" foo" ));
1236+ EXPECT_EQ (" foo" , FromStringLike (std::string (" foo" )));
1237+ #if GTEST_INTERNAL_HAS_STRING_VIEW
1238+ EXPECT_EQ (" foo" , FromStringLike (internal::StringView (" foo" )));
1239+ #endif // GTEST_INTERNAL_HAS_STRING_VIEW
1240+
1241+ // Non deducible types.
1242+ EXPECT_EQ (" " , FromStringLike ({}));
1243+ EXPECT_EQ (" foo" , FromStringLike ({' f' , ' o' , ' o' }));
1244+ const char buf[] = " foo" ;
1245+ EXPECT_EQ (" foo" , FromStringLike ({buf, buf + 3 }));
1246+ }
1247+
12291248TEST (StrEqTest, MatchesEqualString) {
12301249 Matcher<const char *> m = StrEq (std::string (" Hello" ));
12311250 EXPECT_TRUE (m.Matches (" Hello" ));
@@ -1237,7 +1256,8 @@ TEST(StrEqTest, MatchesEqualString) {
12371256 EXPECT_FALSE (m2.Matches (" Hi" ));
12381257
12391258#if GTEST_INTERNAL_HAS_STRING_VIEW
1240- Matcher<const internal::StringView&> m3 = StrEq (" Hello" );
1259+ Matcher<const internal::StringView&> m3 =
1260+ StrEq (internal::StringView (" Hello" ));
12411261 EXPECT_TRUE (m3.Matches (internal::StringView (" Hello" )));
12421262 EXPECT_FALSE (m3.Matches (internal::StringView (" hello" )));
12431263 EXPECT_FALSE (m3.Matches (internal::StringView ()));
@@ -1274,7 +1294,7 @@ TEST(StrNeTest, MatchesUnequalString) {
12741294 EXPECT_FALSE (m2.Matches (" Hello" ));
12751295
12761296#if GTEST_INTERNAL_HAS_STRING_VIEW
1277- Matcher<const internal::StringView> m3 = StrNe (" Hello" );
1297+ Matcher<const internal::StringView> m3 = StrNe (internal::StringView ( " Hello" ) );
12781298 EXPECT_TRUE (m3.Matches (internal::StringView (" " )));
12791299 EXPECT_TRUE (m3.Matches (internal::StringView ()));
12801300 EXPECT_FALSE (m3.Matches (internal::StringView (" Hello" )));
@@ -1298,7 +1318,8 @@ TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) {
12981318 EXPECT_FALSE (m2.Matches (" Hi" ));
12991319
13001320#if GTEST_INTERNAL_HAS_STRING_VIEW
1301- Matcher<const internal::StringView&> m3 = StrCaseEq (std::string (" Hello" ));
1321+ Matcher<const internal::StringView&> m3 =
1322+ StrCaseEq (internal::StringView (" Hello" ));
13021323 EXPECT_TRUE (m3.Matches (internal::StringView (" Hello" )));
13031324 EXPECT_TRUE (m3.Matches (internal::StringView (" hello" )));
13041325 EXPECT_FALSE (m3.Matches (internal::StringView (" Hi" )));
@@ -1348,7 +1369,8 @@ TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) {
13481369 EXPECT_FALSE (m2.Matches (" Hello" ));
13491370
13501371#if GTEST_INTERNAL_HAS_STRING_VIEW
1351- Matcher<const internal::StringView> m3 = StrCaseNe (" Hello" );
1372+ Matcher<const internal::StringView> m3 =
1373+ StrCaseNe (internal::StringView (" Hello" ));
13521374 EXPECT_TRUE (m3.Matches (internal::StringView (" Hi" )));
13531375 EXPECT_TRUE (m3.Matches (internal::StringView ()));
13541376 EXPECT_FALSE (m3.Matches (internal::StringView (" Hello" )));
@@ -1397,7 +1419,8 @@ TEST(HasSubstrTest, WorksForCStrings) {
13971419#if GTEST_INTERNAL_HAS_STRING_VIEW
13981420// Tests that HasSubstr() works for matching StringView-typed values.
13991421TEST (HasSubstrTest, WorksForStringViewClasses) {
1400- const Matcher<internal::StringView> m1 = HasSubstr (" foo" );
1422+ const Matcher<internal::StringView> m1 =
1423+ HasSubstr (internal::StringView (" foo" ));
14011424 EXPECT_TRUE (m1.Matches (internal::StringView (" I love food." )));
14021425 EXPECT_FALSE (m1.Matches (internal::StringView (" tofo" )));
14031426 EXPECT_FALSE (m1.Matches (internal::StringView ()));
@@ -1650,7 +1673,8 @@ TEST(StartsWithTest, MatchesStringWithGivenPrefix) {
16501673 EXPECT_FALSE (m2.Matches (" Hi" ));
16511674
16521675#if GTEST_INTERNAL_HAS_STRING_VIEW
1653- const Matcher<internal::StringView> m_empty = StartsWith (" " );
1676+ const Matcher<internal::StringView> m_empty =
1677+ StartsWith (internal::StringView (" " ));
16541678 EXPECT_TRUE (m_empty.Matches (internal::StringView ()));
16551679 EXPECT_TRUE (m_empty.Matches (internal::StringView (" " )));
16561680 EXPECT_TRUE (m_empty.Matches (internal::StringView (" not empty" )));
@@ -1678,7 +1702,8 @@ TEST(EndsWithTest, MatchesStringWithGivenSuffix) {
16781702 EXPECT_FALSE (m2.Matches (" Hi " ));
16791703
16801704#if GTEST_INTERNAL_HAS_STRING_VIEW
1681- const Matcher<const internal::StringView&> m4 = EndsWith (" " );
1705+ const Matcher<const internal::StringView&> m4 =
1706+ EndsWith (internal::StringView (" " ));
16821707 EXPECT_TRUE (m4.Matches (" Hi" ));
16831708 EXPECT_TRUE (m4.Matches (" " ));
16841709 EXPECT_TRUE (m4.Matches (internal::StringView ()));
@@ -1710,7 +1735,8 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) {
17101735 EXPECT_TRUE (m3.Matches (internal::StringView (" abcz" )));
17111736 EXPECT_FALSE (m3.Matches (internal::StringView (" 1az" )));
17121737 EXPECT_FALSE (m3.Matches (internal::StringView ()));
1713- const Matcher<const internal::StringView&> m4 = MatchesRegex (" " );
1738+ const Matcher<const internal::StringView&> m4 =
1739+ MatchesRegex (internal::StringView (" " ));
17141740 EXPECT_TRUE (m4.Matches (internal::StringView (" " )));
17151741 EXPECT_TRUE (m4.Matches (internal::StringView ()));
17161742#endif // GTEST_INTERNAL_HAS_STRING_VIEW
@@ -1749,7 +1775,8 @@ TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) {
17491775 EXPECT_TRUE (m3.Matches (internal::StringView (" az1" )));
17501776 EXPECT_FALSE (m3.Matches (internal::StringView (" 1a" )));
17511777 EXPECT_FALSE (m3.Matches (internal::StringView ()));
1752- const Matcher<const internal::StringView&> m4 = ContainsRegex (" " );
1778+ const Matcher<const internal::StringView&> m4 =
1779+ ContainsRegex (internal::StringView (" " ));
17531780 EXPECT_TRUE (m4.Matches (internal::StringView (" " )));
17541781 EXPECT_TRUE (m4.Matches (internal::StringView ()));
17551782#endif // GTEST_INTERNAL_HAS_STRING_VIEW
0 commit comments