Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
6f5fd0d7
Commit
6f5fd0d7
authored
Feb 11, 2020
by
Abseil Team
Committed by
Mark Barolak
Feb 11, 2020
Browse files
Googletest export
Add gmock Matcher<std::string_view> specialization. PiperOrigin-RevId: 294443240
parent
d0930731
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
197 additions
and
164 deletions
+197
-164
googlemock/include/gmock/gmock-matchers.h
googlemock/include/gmock/gmock-matchers.h
+20
-20
googlemock/test/gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+95
-94
googletest/include/gtest/gtest-matchers.h
googletest/include/gtest/gtest-matchers.h
+19
-19
googletest/include/gtest/gtest-printers.h
googletest/include/gtest/gtest-printers.h
+13
-12
googletest/include/gtest/internal/gtest-port.h
googletest/include/gtest/internal/gtest-port.h
+31
-0
googletest/src/gtest-matchers.cc
googletest/src/gtest-matchers.cc
+14
-14
googletest/test/googletest-printers-test.cc
googletest/test/googletest-printers-test.cc
+5
-5
No files found.
googlemock/include/gmock/gmock-matchers.h
View file @
6f5fd0d7
...
@@ -906,15 +906,15 @@ class StrEqualityMatcher {
...
@@ -906,15 +906,15 @@ class StrEqualityMatcher {
bool
case_sensitive
)
bool
case_sensitive
)
:
string_
(
str
),
expect_eq_
(
expect_eq
),
case_sensitive_
(
case_sensitive
)
{}
:
string_
(
str
),
expect_eq_
(
expect_eq
),
case_sensitive_
(
case_sensitive
)
{}
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
bool
MatchAndExplain
(
const
abs
l
::
s
tring
_v
iew
&
s
,
bool
MatchAndExplain
(
const
interna
l
::
S
tring
V
iew
&
s
,
MatchResultListener
*
listener
)
const
{
MatchResultListener
*
listener
)
const
{
// This should fail to compile if
absl::s
tring
_v
iew is used with wide
// This should fail to compile if
S
tring
V
iew is used with wide
// strings.
// strings.
const
StringType
&
str
=
std
::
string
(
s
);
const
StringType
&
str
=
std
::
string
(
s
);
return
MatchAndExplain
(
str
,
listener
);
return
MatchAndExplain
(
str
,
listener
);
}
}
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
// Accepts pointer types, particularly:
// Accepts pointer types, particularly:
// const char*
// const char*
...
@@ -932,7 +932,7 @@ class StrEqualityMatcher {
...
@@ -932,7 +932,7 @@ class StrEqualityMatcher {
// Matches anything that can convert to StringType.
// Matches anything that can convert to StringType.
//
//
// This is a template, not just a plain function with const StringType&,
// This is a template, not just a plain function with const StringType&,
// because
absl::s
tring
_v
iew has some interfering non-explicit constructors.
// because
S
tring
V
iew has some interfering non-explicit constructors.
template
<
typename
MatcheeStringType
>
template
<
typename
MatcheeStringType
>
bool
MatchAndExplain
(
const
MatcheeStringType
&
s
,
bool
MatchAndExplain
(
const
MatcheeStringType
&
s
,
MatchResultListener
*
/* listener */
)
const
{
MatchResultListener
*
/* listener */
)
const
{
...
@@ -976,15 +976,15 @@ class HasSubstrMatcher {
...
@@ -976,15 +976,15 @@ class HasSubstrMatcher {
explicit
HasSubstrMatcher
(
const
StringType
&
substring
)
explicit
HasSubstrMatcher
(
const
StringType
&
substring
)
:
substring_
(
substring
)
{}
:
substring_
(
substring
)
{}
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
bool
MatchAndExplain
(
const
abs
l
::
s
tring
_v
iew
&
s
,
bool
MatchAndExplain
(
const
interna
l
::
S
tring
V
iew
&
s
,
MatchResultListener
*
listener
)
const
{
MatchResultListener
*
listener
)
const
{
// This should fail to compile if
absl::s
tring
_v
iew is used with wide
// This should fail to compile if
S
tring
V
iew is used with wide
// strings.
// strings.
const
StringType
&
str
=
std
::
string
(
s
);
const
StringType
&
str
=
std
::
string
(
s
);
return
MatchAndExplain
(
str
,
listener
);
return
MatchAndExplain
(
str
,
listener
);
}
}
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
// Accepts pointer types, particularly:
// Accepts pointer types, particularly:
// const char*
// const char*
...
@@ -999,7 +999,7 @@ class HasSubstrMatcher {
...
@@ -999,7 +999,7 @@ class HasSubstrMatcher {
// Matches anything that can convert to StringType.
// Matches anything that can convert to StringType.
//
//
// This is a template, not just a plain function with const StringType&,
// This is a template, not just a plain function with const StringType&,
// because
absl::s
tring
_v
iew has some interfering non-explicit constructors.
// because
S
tring
V
iew has some interfering non-explicit constructors.
template
<
typename
MatcheeStringType
>
template
<
typename
MatcheeStringType
>
bool
MatchAndExplain
(
const
MatcheeStringType
&
s
,
bool
MatchAndExplain
(
const
MatcheeStringType
&
s
,
MatchResultListener
*
/* listener */
)
const
{
MatchResultListener
*
/* listener */
)
const
{
...
@@ -1032,15 +1032,15 @@ class StartsWithMatcher {
...
@@ -1032,15 +1032,15 @@ class StartsWithMatcher {
explicit
StartsWithMatcher
(
const
StringType
&
prefix
)
:
prefix_
(
prefix
)
{
explicit
StartsWithMatcher
(
const
StringType
&
prefix
)
:
prefix_
(
prefix
)
{
}
}
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
bool
MatchAndExplain
(
const
abs
l
::
s
tring
_v
iew
&
s
,
bool
MatchAndExplain
(
const
interna
l
::
S
tring
V
iew
&
s
,
MatchResultListener
*
listener
)
const
{
MatchResultListener
*
listener
)
const
{
// This should fail to compile if
absl::s
tring
_v
iew is used with wide
// This should fail to compile if
S
tring
V
iew is used with wide
// strings.
// strings.
const
StringType
&
str
=
std
::
string
(
s
);
const
StringType
&
str
=
std
::
string
(
s
);
return
MatchAndExplain
(
str
,
listener
);
return
MatchAndExplain
(
str
,
listener
);
}
}
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
// Accepts pointer types, particularly:
// Accepts pointer types, particularly:
// const char*
// const char*
...
@@ -1055,7 +1055,7 @@ class StartsWithMatcher {
...
@@ -1055,7 +1055,7 @@ class StartsWithMatcher {
// Matches anything that can convert to StringType.
// Matches anything that can convert to StringType.
//
//
// This is a template, not just a plain function with const StringType&,
// This is a template, not just a plain function with const StringType&,
// because
absl::s
tring
_v
iew has some interfering non-explicit constructors.
// because
S
tring
V
iew has some interfering non-explicit constructors.
template
<
typename
MatcheeStringType
>
template
<
typename
MatcheeStringType
>
bool
MatchAndExplain
(
const
MatcheeStringType
&
s
,
bool
MatchAndExplain
(
const
MatcheeStringType
&
s
,
MatchResultListener
*
/* listener */
)
const
{
MatchResultListener
*
/* listener */
)
const
{
...
@@ -1088,15 +1088,15 @@ class EndsWithMatcher {
...
@@ -1088,15 +1088,15 @@ class EndsWithMatcher {
public:
public:
explicit
EndsWithMatcher
(
const
StringType
&
suffix
)
:
suffix_
(
suffix
)
{}
explicit
EndsWithMatcher
(
const
StringType
&
suffix
)
:
suffix_
(
suffix
)
{}
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
bool
MatchAndExplain
(
const
abs
l
::
s
tring
_v
iew
&
s
,
bool
MatchAndExplain
(
const
interna
l
::
S
tring
V
iew
&
s
,
MatchResultListener
*
listener
)
const
{
MatchResultListener
*
listener
)
const
{
// This should fail to compile if
absl::s
tring
_v
iew is used with wide
// This should fail to compile if
S
tring
V
iew is used with wide
// strings.
// strings.
const
StringType
&
str
=
std
::
string
(
s
);
const
StringType
&
str
=
std
::
string
(
s
);
return
MatchAndExplain
(
str
,
listener
);
return
MatchAndExplain
(
str
,
listener
);
}
}
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
// Accepts pointer types, particularly:
// Accepts pointer types, particularly:
// const char*
// const char*
...
@@ -1111,7 +1111,7 @@ class EndsWithMatcher {
...
@@ -1111,7 +1111,7 @@ class EndsWithMatcher {
// Matches anything that can convert to StringType.
// Matches anything that can convert to StringType.
//
//
// This is a template, not just a plain function with const StringType&,
// This is a template, not just a plain function with const StringType&,
// because
absl::s
tring
_v
iew has some interfering non-explicit constructors.
// because
S
tring
V
iew has some interfering non-explicit constructors.
template
<
typename
MatcheeStringType
>
template
<
typename
MatcheeStringType
>
bool
MatchAndExplain
(
const
MatcheeStringType
&
s
,
bool
MatchAndExplain
(
const
MatcheeStringType
&
s
,
MatchResultListener
*
/* listener */
)
const
{
MatchResultListener
*
/* listener */
)
const
{
...
...
googlemock/test/gmock-matchers_test.cc
View file @
6f5fd0d7
...
@@ -351,43 +351,43 @@ TEST(StringMatcherTest, CanBeImplicitlyConstructedFromString) {
...
@@ -351,43 +351,43 @@ TEST(StringMatcherTest, CanBeImplicitlyConstructedFromString) {
EXPECT_FALSE
(
m2
.
Matches
(
"hello"
));
EXPECT_FALSE
(
m2
.
Matches
(
"hello"
));
}
}
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
// Tests that a C-string literal can be implicitly converted to a
// Tests that a C-string literal can be implicitly converted to a
// Matcher<
absl::s
tring
_v
iew> or Matcher<const
absl::s
tring
_v
iew&>.
// Matcher<
S
tring
V
iew> or Matcher<const
S
tring
V
iew&>.
TEST
(
StringViewMatcherTest
,
CanBeImplicitlyConstructedFromCStringLiteral
)
{
TEST
(
StringViewMatcherTest
,
CanBeImplicitlyConstructedFromCStringLiteral
)
{
Matcher
<
abs
l
::
s
tring
_v
iew
>
m1
=
"cats"
;
Matcher
<
interna
l
::
S
tring
V
iew
>
m1
=
"cats"
;
EXPECT_TRUE
(
m1
.
Matches
(
"cats"
));
EXPECT_TRUE
(
m1
.
Matches
(
"cats"
));
EXPECT_FALSE
(
m1
.
Matches
(
"dogs"
));
EXPECT_FALSE
(
m1
.
Matches
(
"dogs"
));
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>
m2
=
"cats"
;
Matcher
<
const
interna
l
::
S
tring
V
iew
&>
m2
=
"cats"
;
EXPECT_TRUE
(
m2
.
Matches
(
"cats"
));
EXPECT_TRUE
(
m2
.
Matches
(
"cats"
));
EXPECT_FALSE
(
m2
.
Matches
(
"dogs"
));
EXPECT_FALSE
(
m2
.
Matches
(
"dogs"
));
}
}
// Tests that a std::string object can be implicitly converted to a
// Tests that a std::string object can be implicitly converted to a
// Matcher<
absl::s
tring
_v
iew> or Matcher<const
absl::s
tring
_v
iew&>.
// Matcher<
S
tring
V
iew> or Matcher<const
S
tring
V
iew&>.
TEST
(
StringViewMatcherTest
,
CanBeImplicitlyConstructedFromString
)
{
TEST
(
StringViewMatcherTest
,
CanBeImplicitlyConstructedFromString
)
{
Matcher
<
abs
l
::
s
tring
_v
iew
>
m1
=
std
::
string
(
"cats"
);
Matcher
<
interna
l
::
S
tring
V
iew
>
m1
=
std
::
string
(
"cats"
);
EXPECT_TRUE
(
m1
.
Matches
(
"cats"
));
EXPECT_TRUE
(
m1
.
Matches
(
"cats"
));
EXPECT_FALSE
(
m1
.
Matches
(
"dogs"
));
EXPECT_FALSE
(
m1
.
Matches
(
"dogs"
));
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>
m2
=
std
::
string
(
"cats"
);
Matcher
<
const
interna
l
::
S
tring
V
iew
&>
m2
=
std
::
string
(
"cats"
);
EXPECT_TRUE
(
m2
.
Matches
(
"cats"
));
EXPECT_TRUE
(
m2
.
Matches
(
"cats"
));
EXPECT_FALSE
(
m2
.
Matches
(
"dogs"
));
EXPECT_FALSE
(
m2
.
Matches
(
"dogs"
));
}
}
// Tests that a
absl::s
tring
_v
iew object can be implicitly converted to a
// Tests that a
S
tring
V
iew object can be implicitly converted to a
// Matcher<
absl::s
tring
_v
iew> or Matcher<const
absl::s
tring
_v
iew&>.
// Matcher<
S
tring
V
iew> or Matcher<const
S
tring
V
iew&>.
TEST
(
StringViewMatcherTest
,
CanBeImplicitlyConstructedFromStringView
)
{
TEST
(
StringViewMatcherTest
,
CanBeImplicitlyConstructedFromStringView
)
{
Matcher
<
abs
l
::
s
tring
_v
iew
>
m1
=
abs
l
::
s
tring
_v
iew
(
"cats"
);
Matcher
<
interna
l
::
S
tring
V
iew
>
m1
=
interna
l
::
S
tring
V
iew
(
"cats"
);
EXPECT_TRUE
(
m1
.
Matches
(
"cats"
));
EXPECT_TRUE
(
m1
.
Matches
(
"cats"
));
EXPECT_FALSE
(
m1
.
Matches
(
"dogs"
));
EXPECT_FALSE
(
m1
.
Matches
(
"dogs"
));
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>
m2
=
abs
l
::
s
tring
_v
iew
(
"cats"
);
Matcher
<
const
interna
l
::
S
tring
V
iew
&>
m2
=
interna
l
::
S
tring
V
iew
(
"cats"
);
EXPECT_TRUE
(
m2
.
Matches
(
"cats"
));
EXPECT_TRUE
(
m2
.
Matches
(
"cats"
));
EXPECT_FALSE
(
m2
.
Matches
(
"dogs"
));
EXPECT_FALSE
(
m2
.
Matches
(
"dogs"
));
}
}
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
// Tests that a std::reference_wrapper<std::string> object can be implicitly
// Tests that a std::reference_wrapper<std::string> object can be implicitly
// converted to a Matcher<std::string> or Matcher<const std::string&> via Eq().
// converted to a Matcher<std::string> or Matcher<const std::string&> via Eq().
...
@@ -1235,17 +1235,17 @@ TEST(StrEqTest, MatchesEqualString) {
...
@@ -1235,17 +1235,17 @@ TEST(StrEqTest, MatchesEqualString) {
EXPECT_TRUE
(
m2
.
Matches
(
"Hello"
));
EXPECT_TRUE
(
m2
.
Matches
(
"Hello"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hi"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hi"
));
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>
m3
=
StrEq
(
"Hello"
);
Matcher
<
const
interna
l
::
S
tring
V
iew
&>
m3
=
StrEq
(
"Hello"
);
EXPECT_TRUE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"Hello"
)));
EXPECT_TRUE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
"Hello"
)));
EXPECT_FALSE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"hello"
)));
EXPECT_FALSE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
"hello"
)));
EXPECT_FALSE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
()));
EXPECT_FALSE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
()));
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>
m_empty
=
StrEq
(
""
);
Matcher
<
const
interna
l
::
S
tring
V
iew
&>
m_empty
=
StrEq
(
""
);
EXPECT_TRUE
(
m_empty
.
Matches
(
abs
l
::
s
tring
_v
iew
(
""
)));
EXPECT_TRUE
(
m_empty
.
Matches
(
interna
l
::
S
tring
V
iew
(
""
)));
EXPECT_TRUE
(
m_empty
.
Matches
(
abs
l
::
s
tring
_v
iew
()));
EXPECT_TRUE
(
m_empty
.
Matches
(
interna
l
::
S
tring
V
iew
()));
EXPECT_FALSE
(
m_empty
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"hello"
)));
EXPECT_FALSE
(
m_empty
.
Matches
(
interna
l
::
S
tring
V
iew
(
"hello"
)));
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
}
}
TEST
(
StrEqTest
,
CanDescribeSelf
)
{
TEST
(
StrEqTest
,
CanDescribeSelf
)
{
...
@@ -1272,12 +1272,12 @@ TEST(StrNeTest, MatchesUnequalString) {
...
@@ -1272,12 +1272,12 @@ TEST(StrNeTest, MatchesUnequalString) {
EXPECT_TRUE
(
m2
.
Matches
(
"hello"
));
EXPECT_TRUE
(
m2
.
Matches
(
"hello"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hello"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hello"
));
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
Matcher
<
const
abs
l
::
s
tring
_v
iew
>
m3
=
StrNe
(
"Hello"
);
Matcher
<
const
interna
l
::
S
tring
V
iew
>
m3
=
StrNe
(
"Hello"
);
EXPECT_TRUE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
""
)));
EXPECT_TRUE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
""
)));
EXPECT_TRUE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
()));
EXPECT_TRUE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
()));
EXPECT_FALSE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"Hello"
)));
EXPECT_FALSE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
"Hello"
)));
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
}
}
TEST
(
StrNeTest
,
CanDescribeSelf
)
{
TEST
(
StrNeTest
,
CanDescribeSelf
)
{
...
@@ -1296,13 +1296,13 @@ TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) {
...
@@ -1296,13 +1296,13 @@ TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) {
EXPECT_TRUE
(
m2
.
Matches
(
"hello"
));
EXPECT_TRUE
(
m2
.
Matches
(
"hello"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hi"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hi"
));
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>
m3
=
StrCaseEq
(
std
::
string
(
"Hello"
));
Matcher
<
const
interna
l
::
S
tring
V
iew
&>
m3
=
StrCaseEq
(
std
::
string
(
"Hello"
));
EXPECT_TRUE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"Hello"
)));
EXPECT_TRUE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
"Hello"
)));
EXPECT_TRUE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"hello"
)));
EXPECT_TRUE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
"hello"
)));
EXPECT_FALSE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"Hi"
)));
EXPECT_FALSE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
"Hi"
)));
EXPECT_FALSE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
()));
EXPECT_FALSE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
()));
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
}
}
TEST
(
StrCaseEqTest
,
MatchesEqualStringWith0IgnoringCase
)
{
TEST
(
StrCaseEqTest
,
MatchesEqualStringWith0IgnoringCase
)
{
...
@@ -1346,13 +1346,13 @@ TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) {
...
@@ -1346,13 +1346,13 @@ TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) {
EXPECT_TRUE
(
m2
.
Matches
(
""
));
EXPECT_TRUE
(
m2
.
Matches
(
""
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hello"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hello"
));
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
Matcher
<
const
abs
l
::
s
tring
_v
iew
>
m3
=
StrCaseNe
(
"Hello"
);
Matcher
<
const
interna
l
::
S
tring
V
iew
>
m3
=
StrCaseNe
(
"Hello"
);
EXPECT_TRUE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"Hi"
)));
EXPECT_TRUE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
"Hi"
)));
EXPECT_TRUE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
()));
EXPECT_TRUE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
()));
EXPECT_FALSE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"Hello"
)));
EXPECT_FALSE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
"Hello"
)));
EXPECT_FALSE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"hello"
)));
EXPECT_FALSE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
"hello"
)));
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
}
}
TEST
(
StrCaseNeTest
,
CanDescribeSelf
)
{
TEST
(
StrCaseNeTest
,
CanDescribeSelf
)
{
...
@@ -1393,25 +1393,25 @@ TEST(HasSubstrTest, WorksForCStrings) {
...
@@ -1393,25 +1393,25 @@ TEST(HasSubstrTest, WorksForCStrings) {
EXPECT_FALSE
(
m_empty
.
Matches
(
nullptr
));
EXPECT_FALSE
(
m_empty
.
Matches
(
nullptr
));
}
}
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
// Tests that HasSubstr() works for matching
absl::s
tring
_v
iew-typed values.
// Tests that HasSubstr() works for matching
S
tring
V
iew-typed values.
TEST
(
HasSubstrTest
,
WorksForStringViewClasses
)
{
TEST
(
HasSubstrTest
,
WorksForStringViewClasses
)
{
const
Matcher
<
abs
l
::
s
tring
_v
iew
>
m1
=
HasSubstr
(
"foo"
);
const
Matcher
<
interna
l
::
S
tring
V
iew
>
m1
=
HasSubstr
(
"foo"
);
EXPECT_TRUE
(
m1
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"I love food."
)));
EXPECT_TRUE
(
m1
.
Matches
(
interna
l
::
S
tring
V
iew
(
"I love food."
)));
EXPECT_FALSE
(
m1
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"tofo"
)));
EXPECT_FALSE
(
m1
.
Matches
(
interna
l
::
S
tring
V
iew
(
"tofo"
)));
EXPECT_FALSE
(
m1
.
Matches
(
abs
l
::
s
tring
_v
iew
()));
EXPECT_FALSE
(
m1
.
Matches
(
interna
l
::
S
tring
V
iew
()));
const
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>
m2
=
HasSubstr
(
"foo"
);
const
Matcher
<
const
interna
l
::
S
tring
V
iew
&>
m2
=
HasSubstr
(
"foo"
);
EXPECT_TRUE
(
m2
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"I love food."
)));
EXPECT_TRUE
(
m2
.
Matches
(
interna
l
::
S
tring
V
iew
(
"I love food."
)));
EXPECT_FALSE
(
m2
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"tofo"
)));
EXPECT_FALSE
(
m2
.
Matches
(
interna
l
::
S
tring
V
iew
(
"tofo"
)));
EXPECT_FALSE
(
m2
.
Matches
(
abs
l
::
s
tring
_v
iew
()));
EXPECT_FALSE
(
m2
.
Matches
(
interna
l
::
S
tring
V
iew
()));
const
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>
m3
=
HasSubstr
(
""
);
const
Matcher
<
const
interna
l
::
S
tring
V
iew
&>
m3
=
HasSubstr
(
""
);
EXPECT_TRUE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"foo"
)));
EXPECT_TRUE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
"foo"
)));
EXPECT_TRUE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
""
)));
EXPECT_TRUE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
""
)));
EXPECT_TRUE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
()));
EXPECT_TRUE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
()));
}
}
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
// Tests that HasSubstr(s) describes itself properly.
// Tests that HasSubstr(s) describes itself properly.
TEST
(
HasSubstrTest
,
CanDescribeSelf
)
{
TEST
(
HasSubstrTest
,
CanDescribeSelf
)
{
...
@@ -1648,12 +1648,12 @@ TEST(StartsWithTest, MatchesStringWithGivenPrefix) {
...
@@ -1648,12 +1648,12 @@ TEST(StartsWithTest, MatchesStringWithGivenPrefix) {
EXPECT_FALSE
(
m2
.
Matches
(
"H"
));
EXPECT_FALSE
(
m2
.
Matches
(
"H"
));
EXPECT_FALSE
(
m2
.
Matches
(
" Hi"
));
EXPECT_FALSE
(
m2
.
Matches
(
" Hi"
));
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
const
Matcher
<
abs
l
::
s
tring
_v
iew
>
m_empty
=
StartsWith
(
""
);
const
Matcher
<
interna
l
::
S
tring
V
iew
>
m_empty
=
StartsWith
(
""
);
EXPECT_TRUE
(
m_empty
.
Matches
(
abs
l
::
s
tring
_v
iew
()));
EXPECT_TRUE
(
m_empty
.
Matches
(
interna
l
::
S
tring
V
iew
()));
EXPECT_TRUE
(
m_empty
.
Matches
(
abs
l
::
s
tring
_v
iew
(
""
)));
EXPECT_TRUE
(
m_empty
.
Matches
(
interna
l
::
S
tring
V
iew
(
""
)));
EXPECT_TRUE
(
m_empty
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"not empty"
)));
EXPECT_TRUE
(
m_empty
.
Matches
(
interna
l
::
S
tring
V
iew
(
"not empty"
)));
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
}
}
TEST
(
StartsWithTest
,
CanDescribeSelf
)
{
TEST
(
StartsWithTest
,
CanDescribeSelf
)
{
...
@@ -1676,13 +1676,13 @@ TEST(EndsWithTest, MatchesStringWithGivenSuffix) {
...
@@ -1676,13 +1676,13 @@ TEST(EndsWithTest, MatchesStringWithGivenSuffix) {
EXPECT_FALSE
(
m2
.
Matches
(
"i"
));
EXPECT_FALSE
(
m2
.
Matches
(
"i"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hi "
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hi "
));
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
const
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>
m4
=
EndsWith
(
""
);
const
Matcher
<
const
interna
l
::
S
tring
V
iew
&>
m4
=
EndsWith
(
""
);
EXPECT_TRUE
(
m4
.
Matches
(
"Hi"
));
EXPECT_TRUE
(
m4
.
Matches
(
"Hi"
));
EXPECT_TRUE
(
m4
.
Matches
(
""
));
EXPECT_TRUE
(
m4
.
Matches
(
""
));
EXPECT_TRUE
(
m4
.
Matches
(
abs
l
::
s
tring
_v
iew
()));
EXPECT_TRUE
(
m4
.
Matches
(
interna
l
::
S
tring
V
iew
()));
EXPECT_TRUE
(
m4
.
Matches
(
abs
l
::
s
tring
_v
iew
(
""
)));
EXPECT_TRUE
(
m4
.
Matches
(
interna
l
::
S
tring
V
iew
(
""
)));
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
}
}
TEST
(
EndsWithTest
,
CanDescribeSelf
)
{
TEST
(
EndsWithTest
,
CanDescribeSelf
)
{
...
@@ -1703,16 +1703,16 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) {
...
@@ -1703,16 +1703,16 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) {
EXPECT_FALSE
(
m2
.
Matches
(
"az1"
));
EXPECT_FALSE
(
m2
.
Matches
(
"az1"
));
EXPECT_FALSE
(
m2
.
Matches
(
"1az"
));
EXPECT_FALSE
(
m2
.
Matches
(
"1az"
));
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
const
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>
m3
=
MatchesRegex
(
"a.*z"
);
const
Matcher
<
const
interna
l
::
S
tring
V
iew
&>
m3
=
MatchesRegex
(
"a.*z"
);
EXPECT_TRUE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"az"
)));
EXPECT_TRUE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
"az"
)));
EXPECT_TRUE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"abcz"
)));
EXPECT_TRUE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
"abcz"
)));
EXPECT_FALSE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
(
"1az"
)));
EXPECT_FALSE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
(
"1az"
)));
EXPECT_FALSE
(
m3
.
Matches
(
abs
l
::
s
tring
_v
iew
()));
EXPECT_FALSE
(
m3
.
Matches
(
interna
l
::
S
tring
V
iew
()));
const
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>
m4
=
MatchesRegex
(
""
);
const
Matcher
<
const
interna
l
::
S
tring
V
iew
&>
m4
=
MatchesRegex
(
""
);
EXPECT_TRUE
(
m4
.
Matches
(
abs
l
::
s
tring
_v
iew
(
""
)));
EXPECT_TRUE
(
m4
.
Matches
(
interna
l
::
S
tring
V
iew
(
""
)));
EXPECT_TRUE
(
m4
.
Matches
(
abs
l
::
s
tring
_v
iew
()));
EXPECT_TRUE
(
m4
.
Matches
(
interna
l
::
S
tring
V
iew
()));
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
}
}
TEST
(
MatchesRegexTest
,
CanDescribeSelf
)
{
TEST
(
MatchesRegexTest
,
CanDescribeSelf
)
{
...
@@ -1722,10 +1722,10 @@ TEST(MatchesRegexTest, CanDescribeSelf) {
...
@@ -1722,10 +1722,10 @@ TEST(MatchesRegexTest, CanDescribeSelf) {
Matcher
<
const
char
*>
m2
=
MatchesRegex
(
new
RE
(
"a.*"
));
Matcher
<
const
char
*>
m2
=
MatchesRegex
(
new
RE
(
"a.*"
));
EXPECT_EQ
(
"matches regular expression
\"
a.*
\"
"
,
Describe
(
m2
));
EXPECT_EQ
(
"matches regular expression
\"
a.*
\"
"
,
Describe
(
m2
));
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
Matcher
<
const
abs
l
::
s
tring
_v
iew
>
m3
=
MatchesRegex
(
new
RE
(
"0.*"
));
Matcher
<
const
interna
l
::
S
tring
V
iew
>
m3
=
MatchesRegex
(
new
RE
(
"0.*"
));
EXPECT_EQ
(
"matches regular expression
\"
0.*
\"
"
,
Describe
(
m3
));
EXPECT_EQ
(
"matches regular expression
\"
0.*
\"
"
,
Describe
(
m3
));
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
}
}
// Tests ContainsRegex().
// Tests ContainsRegex().
...
@@ -1741,16 +1741,17 @@ TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) {
...
@@ -1741,16 +1741,17 @@ TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) {
EXPECT_TRUE
(
m2
.
Matches
(
"az1"
));
EXPECT_TRUE
(
m2
.
Matches
(
"az1"
));
EXPECT_FALSE
(
m2
.
Matches
(
"1a"
));
EXPECT_FALSE
(
m2
.
Matches
(
"1a"
));
#if GTEST_HAS_ABSL
#if GTEST_INTERNAL_HAS_STRING_VIEW
const
Matcher
<
const
absl
::
string_view
&>
m3
=
ContainsRegex
(
new
RE
(
"a.*z"
));
const
Matcher
<
const
internal
::
StringView
&>
m3
=
EXPECT_TRUE
(
m3
.
Matches
(
absl
::
string_view
(
"azbz"
)));
ContainsRegex
(
new
RE
(
"a.*z"
));
EXPECT_TRUE
(
m3
.
Matches
(
absl
::
string_view
(
"az1"
)));
EXPECT_TRUE
(
m3
.
Matches
(
internal
::
StringView
(
"azbz"
)));
EXPECT_FALSE
(
m3
.
Matches
(
absl
::
string_view
(
"1a"
)));
EXPECT_TRUE
(
m3
.
Matches
(
internal
::
StringView
(
"az1"
)));
EXPECT_FALSE
(
m3
.
Matches
(
absl
::
string_view
()));
EXPECT_FALSE
(
m3
.
Matches
(
internal
::
StringView
(
"1a"
)));
const
Matcher
<
const
absl
::
string_view
&>
m4
=
ContainsRegex
(
""
);
EXPECT_FALSE
(
m3
.
Matches
(
internal
::
StringView
()));
EXPECT_TRUE
(
m4
.
Matches
(
absl
::
string_view
(
""
)));
const
Matcher
<
const
internal
::
StringView
&>
m4
=
ContainsRegex
(
""
);
EXPECT_TRUE
(
m4
.
Matches
(
absl
::
string_view
()));
EXPECT_TRUE
(
m4
.
Matches
(
internal
::
StringView
(
""
)));
#endif // GTEST_HAS_ABSL
EXPECT_TRUE
(
m4
.
Matches
(
internal
::
StringView
()));
#endif // GTEST_INTERNAL_HAS_STRING_VIEW
}
}
TEST
(
ContainsRegexTest
,
CanDescribeSelf
)
{
TEST
(
ContainsRegexTest
,
CanDescribeSelf
)
{
...
@@ -1760,10 +1761,10 @@ TEST(ContainsRegexTest, CanDescribeSelf) {
...
@@ -1760,10 +1761,10 @@ TEST(ContainsRegexTest, CanDescribeSelf) {
Matcher
<
const
char
*>
m2
=
ContainsRegex
(
new
RE
(
"a.*"
));
Matcher
<
const
char
*>
m2
=
ContainsRegex
(
new
RE
(
"a.*"
));
EXPECT_EQ
(
"contains regular expression
\"
a.*
\"
"
,
Describe
(
m2
));
EXPECT_EQ
(
"contains regular expression
\"
a.*
\"
"
,
Describe
(
m2
));
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
Matcher
<
const
abs
l
::
s
tring
_v
iew
>
m3
=
ContainsRegex
(
new
RE
(
"0.*"
));
Matcher
<
const
interna
l
::
S
tring
V
iew
>
m3
=
ContainsRegex
(
new
RE
(
"0.*"
));
EXPECT_EQ
(
"contains regular expression
\"
0.*
\"
"
,
Describe
(
m3
));
EXPECT_EQ
(
"contains regular expression
\"
0.*
\"
"
,
Describe
(
m3
));
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
}
}
// Tests for wide strings.
// Tests for wide strings.
...
...
googletest/include/gtest/gtest-matchers.h
View file @
6f5fd0d7
...
@@ -384,18 +384,18 @@ class GTEST_API_ Matcher<std::string>
...
@@ -384,18 +384,18 @@ class GTEST_API_ Matcher<std::string>
Matcher
(
const
char
*
s
);
// NOLINT
Matcher
(
const
char
*
s
);
// NOLINT
};
};
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
// The following two specializations allow the user to write str
// The following two specializations allow the user to write str
// instead of Eq(str) and "foo" instead of Eq("foo") when a absl::string_view
// instead of Eq(str) and "foo" instead of Eq("foo") when a absl::string_view
// matcher is expected.
// matcher is expected.
template
<
>
template
<
>
class
GTEST_API_
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>
class
GTEST_API_
Matcher
<
const
interna
l
::
S
tring
V
iew
&>
:
public
internal
::
MatcherBase
<
const
abs
l
::
s
tring
_v
iew
&>
{
:
public
internal
::
MatcherBase
<
const
interna
l
::
S
tring
V
iew
&>
{
public:
public:
Matcher
()
{}
Matcher
()
{}
explicit
Matcher
(
const
MatcherInterface
<
const
abs
l
::
s
tring
_v
iew
&>*
impl
)
explicit
Matcher
(
const
MatcherInterface
<
const
interna
l
::
S
tring
V
iew
&>*
impl
)
:
internal
::
MatcherBase
<
const
abs
l
::
s
tring
_v
iew
&>
(
impl
)
{}
:
internal
::
MatcherBase
<
const
interna
l
::
S
tring
V
iew
&>
(
impl
)
{}
// Allows the user to write str instead of Eq(str) sometimes, where
// Allows the user to write str instead of Eq(str) sometimes, where
// str is a std::string object.
// str is a std::string object.
...
@@ -404,20 +404,20 @@ class GTEST_API_ Matcher<const absl::string_view&>
...
@@ -404,20 +404,20 @@ class GTEST_API_ Matcher<const absl::string_view&>
// Allows the user to write "foo" instead of Eq("foo") sometimes.
// Allows the user to write "foo" instead of Eq("foo") sometimes.
Matcher
(
const
char
*
s
);
// NOLINT
Matcher
(
const
char
*
s
);
// NOLINT
// Allows the user to pass absl::string_views directly.
// Allows the user to pass absl::string_views
or std::string_views
directly.
Matcher
(
abs
l
::
s
tring
_v
iew
s
);
// NOLINT
Matcher
(
interna
l
::
S
tring
V
iew
s
);
// NOLINT
};
};
template
<
>
template
<
>
class
GTEST_API_
Matcher
<
abs
l
::
s
tring
_v
iew
>
class
GTEST_API_
Matcher
<
interna
l
::
S
tring
V
iew
>
:
public
internal
::
MatcherBase
<
abs
l
::
s
tring
_v
iew
>
{
:
public
internal
::
MatcherBase
<
interna
l
::
S
tring
V
iew
>
{
public:
public:
Matcher
()
{}
Matcher
()
{}
explicit
Matcher
(
const
MatcherInterface
<
const
abs
l
::
s
tring
_v
iew
&>*
impl
)
explicit
Matcher
(
const
MatcherInterface
<
const
interna
l
::
S
tring
V
iew
&>*
impl
)
:
internal
::
MatcherBase
<
abs
l
::
s
tring
_v
iew
>
(
impl
)
{}
:
internal
::
MatcherBase
<
interna
l
::
S
tring
V
iew
>
(
impl
)
{}
explicit
Matcher
(
const
MatcherInterface
<
abs
l
::
s
tring
_v
iew
>*
impl
)
explicit
Matcher
(
const
MatcherInterface
<
interna
l
::
S
tring
V
iew
>*
impl
)
:
internal
::
MatcherBase
<
abs
l
::
s
tring
_v
iew
>
(
impl
)
{}
:
internal
::
MatcherBase
<
interna
l
::
S
tring
V
iew
>
(
impl
)
{}
// Allows the user to write str instead of Eq(str) sometimes, where
// Allows the user to write str instead of Eq(str) sometimes, where
// str is a std::string object.
// str is a std::string object.
...
@@ -426,10 +426,10 @@ class GTEST_API_ Matcher<absl::string_view>
...
@@ -426,10 +426,10 @@ class GTEST_API_ Matcher<absl::string_view>
// Allows the user to write "foo" instead of Eq("foo") sometimes.
// Allows the user to write "foo" instead of Eq("foo") sometimes.
Matcher
(
const
char
*
s
);
// NOLINT
Matcher
(
const
char
*
s
);
// NOLINT
// Allows the user to pass absl::string_views directly.
// Allows the user to pass absl::string_views
or std::string_views
directly.
Matcher
(
abs
l
::
s
tring
_v
iew
s
);
// NOLINT
Matcher
(
interna
l
::
S
tring
V
iew
s
);
// NOLINT
};
};
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
// Prints a matcher in a human-readable format.
// Prints a matcher in a human-readable format.
template
<
typename
T
>
template
<
typename
T
>
...
@@ -620,12 +620,12 @@ class MatchesRegexMatcher {
...
@@ -620,12 +620,12 @@ class MatchesRegexMatcher {
MatchesRegexMatcher
(
const
RE
*
regex
,
bool
full_match
)
MatchesRegexMatcher
(
const
RE
*
regex
,
bool
full_match
)
:
regex_
(
regex
),
full_match_
(
full_match
)
{}
:
regex_
(
regex
),
full_match_
(
full_match
)
{}
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
bool
MatchAndExplain
(
const
abs
l
::
s
tring
_v
iew
&
s
,
bool
MatchAndExplain
(
const
interna
l
::
S
tring
V
iew
&
s
,
MatchResultListener
*
listener
)
const
{
MatchResultListener
*
listener
)
const
{
return
MatchAndExplain
(
std
::
string
(
s
),
listener
);
return
MatchAndExplain
(
std
::
string
(
s
),
listener
);
}
}
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
// Accepts pointer types, particularly:
// Accepts pointer types, particularly:
// const char*
// const char*
...
...
googletest/include/gtest/gtest-printers.h
View file @
6f5fd0d7
...
@@ -135,9 +135,9 @@ enum TypeKind {
...
@@ -135,9 +135,9 @@ enum TypeKind {
kProtobuf
,
// a protobuf type
kProtobuf
,
// a protobuf type
kConvertibleToInteger
,
// a type implicitly convertible to BiggestInt
kConvertibleToInteger
,
// a type implicitly convertible to BiggestInt
// (e.g. a named or unnamed enum type)
// (e.g. a named or unnamed enum type)
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
kConvertibleToStringView
,
// a type implicitly convertible to
kConvertibleToStringView
,
// a type implicitly convertible to
// absl::string_view
// absl::string_view
or std::string_view
#endif
#endif
kOtherType
// anything else
kOtherType
// anything else
};
};
...
@@ -191,12 +191,13 @@ class TypeWithoutFormatter<T, kConvertibleToInteger> {
...
@@ -191,12 +191,13 @@ class TypeWithoutFormatter<T, kConvertibleToInteger> {
}
}
};
};
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
template
<
typename
T
>
template
<
typename
T
>
class
TypeWithoutFormatter
<
T
,
kConvertibleToStringView
>
{
class
TypeWithoutFormatter
<
T
,
kConvertibleToStringView
>
{
public:
public:
// Since T has neither operator<< nor PrintTo() but can be implicitly
// Since T has neither operator<< nor PrintTo() but can be implicitly
// converted to absl::string_view, we print it as a absl::string_view.
// converted to absl::string_view, we print it as a absl::string_view
// (or std::string_view).
//
//
// Note: the implementation is further below, as it depends on
// Note: the implementation is further below, as it depends on
// internal::PrintTo symbol which is defined later in the file.
// internal::PrintTo symbol which is defined later in the file.
...
@@ -237,9 +238,9 @@ template <typename Char, typename CharTraits, typename T>
...
@@ -237,9 +238,9 @@ template <typename Char, typename CharTraits, typename T>
const
T
&
,
internal
::
BiggestInt
>::
value
const
T
&
,
internal
::
BiggestInt
>::
value
?
kConvertibleToInteger
?
kConvertibleToInteger
:
:
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
std
::
is_convertible
<
std
::
is_convertible
<
const
T
&
,
abs
l
::
s
tring
_v
iew
>::
value
const
T
&
,
interna
l
::
S
tring
V
iew
>::
value
?
kConvertibleToStringView
?
kConvertibleToStringView
:
:
#endif
#endif
...
@@ -601,12 +602,12 @@ inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
...
@@ -601,12 +602,12 @@ inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
}
}
#endif // GTEST_HAS_STD_WSTRING
#endif // GTEST_HAS_STD_WSTRING
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
// Overload for
abs
l::
s
tring
_v
iew.
// Overload for
interna
l::
S
tring
V
iew.
inline
void
PrintTo
(
abs
l
::
s
tring
_v
iew
sp
,
::
std
::
ostream
*
os
)
{
inline
void
PrintTo
(
interna
l
::
S
tring
V
iew
sp
,
::
std
::
ostream
*
os
)
{
PrintTo
(
::
std
::
string
(
sp
),
os
);
PrintTo
(
::
std
::
string
(
sp
),
os
);
}
}
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
inline
void
PrintTo
(
std
::
nullptr_t
,
::
std
::
ostream
*
os
)
{
*
os
<<
"(nullptr)"
;
}
inline
void
PrintTo
(
std
::
nullptr_t
,
::
std
::
ostream
*
os
)
{
*
os
<<
"(nullptr)"
;
}
...
@@ -899,12 +900,12 @@ Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
...
@@ -899,12 +900,12 @@ Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
}
// namespace internal
}
// namespace internal
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
namespace
internal2
{
namespace
internal2
{
template
<
typename
T
>
template
<
typename
T
>
void
TypeWithoutFormatter
<
T
,
kConvertibleToStringView
>::
PrintValue
(
void
TypeWithoutFormatter
<
T
,
kConvertibleToStringView
>::
PrintValue
(
const
T
&
value
,
::
std
::
ostream
*
os
)
{
const
T
&
value
,
::
std
::
ostream
*
os
)
{
internal
::
PrintTo
(
abs
l
::
s
tring
_v
iew
(
value
),
os
);
internal
::
PrintTo
(
interna
l
::
S
tring
V
iew
(
value
),
os
);
}
}
}
// namespace internal2
}
// namespace internal2
#endif
#endif
...
...
googletest/include/gtest/internal/gtest-port.h
View file @
6f5fd0d7
...
@@ -199,6 +199,9 @@
...
@@ -199,6 +199,9 @@
// suppressed (constant conditional).
// suppressed (constant conditional).
// GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127
// GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127
// is suppressed.
// is suppressed.
// GTEST_INTERNAL_HAS_STRING_VIEW - for enabling Matcher<std::string_view> or
// Matcher<absl::string_view>
// specializations.
//
//
// Synchronization:
// Synchronization:
// Mutex, MutexLock, ThreadLocal, GetThreadCount()
// Mutex, MutexLock, ThreadLocal, GetThreadCount()
...
@@ -2220,4 +2223,32 @@ const char* StringFromGTestEnv(const char* flag, const char* default_val);
...
@@ -2220,4 +2223,32 @@ const char* StringFromGTestEnv(const char* flag, const char* default_val);
#endif // !defined(GTEST_INTERNAL_DEPRECATED)
#endif // !defined(GTEST_INTERNAL_DEPRECATED)
#if GTEST_HAS_ABSL
// Always use absl::string_view for Matcher<> specializations if googletest
// is built with absl support.
# define GTEST_INTERNAL_HAS_STRING_VIEW 1
#include "absl/strings/string_view.h"
namespace
testing
{
namespace
internal
{
using
StringView
=
::
absl
::
string_view
;
}
// namespace internal
}
// namespace testing
#else
# ifdef __has_include
# if __has_include(<string_view>) && __cplusplus >= 201703L
// Otherwise for C++17 and higher use std::string_view for Matcher<>
// specializations.
# define GTEST_INTERNAL_HAS_STRING_VIEW 1
#include <string_view>
namespace
testing
{
namespace
internal
{
using
StringView
=
::
std
::
string_view
;
}
// namespace internal
}
// namespace testing
// The case where absl is configured NOT to alias std::string_view is not
// supported.
# endif // __has_include(<string_view>) && __cplusplus >= 201703L
# endif // __has_include
#endif // GTEST_HAS_ABSL
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
googletest/src/gtest-matchers.cc
View file @
6f5fd0d7
...
@@ -58,40 +58,40 @@ Matcher<std::string>::Matcher(const std::string& s) { *this = Eq(s); }
...
@@ -58,40 +58,40 @@ Matcher<std::string>::Matcher(const std::string& s) { *this = Eq(s); }
// s.
// s.
Matcher
<
std
::
string
>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
std
::
string
(
s
));
}
Matcher
<
std
::
string
>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
std
::
string
(
s
));
}
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
// Constructs a matcher that matches a const
absl::s
tring
_v
iew& whose value is
// Constructs a matcher that matches a const
S
tring
V
iew& whose value is
// equal to s.
// equal to s.
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>::
Matcher
(
const
std
::
string
&
s
)
{
Matcher
<
const
interna
l
::
S
tring
V
iew
&>::
Matcher
(
const
std
::
string
&
s
)
{
*
this
=
Eq
(
s
);
*
this
=
Eq
(
s
);
}
}
// Constructs a matcher that matches a const
absl::s
tring
_v
iew& whose value is
// Constructs a matcher that matches a const
S
tring
V
iew& whose value is
// equal to s.
// equal to s.
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>::
Matcher
(
const
char
*
s
)
{
Matcher
<
const
interna
l
::
S
tring
V
iew
&>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
std
::
string
(
s
));
*
this
=
Eq
(
std
::
string
(
s
));
}
}
// Constructs a matcher that matches a const
absl::s
tring
_v
iew& whose value is
// Constructs a matcher that matches a const
S
tring
V
iew& whose value is
// equal to s.
// equal to s.
Matcher
<
const
abs
l
::
s
tring
_v
iew
&>::
Matcher
(
abs
l
::
s
tring
_v
iew
s
)
{
Matcher
<
const
interna
l
::
S
tring
V
iew
&>::
Matcher
(
interna
l
::
S
tring
V
iew
s
)
{
*
this
=
Eq
(
std
::
string
(
s
));
*
this
=
Eq
(
std
::
string
(
s
));
}
}
// Constructs a matcher that matches a
absl::s
tring
_v
iew whose value is equal to
// Constructs a matcher that matches a
S
tring
V
iew whose value is equal to
// s.
// s.
Matcher
<
abs
l
::
s
tring
_v
iew
>::
Matcher
(
const
std
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
Matcher
<
interna
l
::
S
tring
V
iew
>::
Matcher
(
const
std
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
// Constructs a matcher that matches a
absl::s
tring
_v
iew whose value is equal to
// Constructs a matcher that matches a
S
tring
V
iew whose value is equal to
// s.
// s.
Matcher
<
abs
l
::
s
tring
_v
iew
>::
Matcher
(
const
char
*
s
)
{
Matcher
<
interna
l
::
S
tring
V
iew
>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
std
::
string
(
s
));
*
this
=
Eq
(
std
::
string
(
s
));
}
}
// Constructs a matcher that matches a
absl::s
tring
_v
iew whose value is equal to
// Constructs a matcher that matches a
S
tring
V
iew whose value is equal to
// s.
// s.
Matcher
<
abs
l
::
s
tring
_v
iew
>::
Matcher
(
abs
l
::
s
tring
_v
iew
s
)
{
Matcher
<
interna
l
::
S
tring
V
iew
>::
Matcher
(
interna
l
::
S
tring
V
iew
s
)
{
*
this
=
Eq
(
std
::
string
(
s
));
*
this
=
Eq
(
std
::
string
(
s
));
}
}
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
}
// namespace testing
}
// namespace testing
googletest/test/googletest-printers-test.cc
View file @
6f5fd0d7
...
@@ -760,22 +760,22 @@ TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
...
@@ -760,22 +760,22 @@ TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
EXPECT_EQ
(
"AllowsGenericStreamingAndImplicitConversionTemplate"
,
Print
(
a
));
EXPECT_EQ
(
"AllowsGenericStreamingAndImplicitConversionTemplate"
,
Print
(
a
));
}
}
#if GTEST_
HAS_ABSL
#if GTEST_
INTERNAL_HAS_STRING_VIEW
// Tests printing
::abs
l::
s
tring
_v
iew.
// Tests printing
interna
l::
S
tring
V
iew.
TEST
(
PrintStringViewTest
,
SimpleStringView
)
{
TEST
(
PrintStringViewTest
,
SimpleStringView
)
{
const
::
abs
l
::
s
tring
_v
iew
sp
=
"Hello"
;
const
interna
l
::
S
tring
V
iew
sp
=
"Hello"
;
EXPECT_EQ
(
"
\"
Hello
\"
"
,
Print
(
sp
));
EXPECT_EQ
(
"
\"
Hello
\"
"
,
Print
(
sp
));
}
}
TEST
(
PrintStringViewTest
,
UnprintableCharacters
)
{
TEST
(
PrintStringViewTest
,
UnprintableCharacters
)
{
const
char
str
[]
=
"NUL (
\0
) and
\r\t
"
;
const
char
str
[]
=
"NUL (
\0
) and
\r\t
"
;
const
::
abs
l
::
s
tring
_v
iew
sp
(
str
,
sizeof
(
str
)
-
1
);
const
interna
l
::
S
tring
V
iew
sp
(
str
,
sizeof
(
str
)
-
1
);
EXPECT_EQ
(
"
\"
NUL (
\\
0) and
\\
r
\\
t
\"
"
,
Print
(
sp
));
EXPECT_EQ
(
"
\"
NUL (
\\
0) and
\\
r
\\
t
\"
"
,
Print
(
sp
));
}
}
#endif // GTEST_
HAS_ABSL
#endif // GTEST_
INTERNAL_HAS_STRING_VIEW
// Tests printing STL containers.
// Tests printing STL containers.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment