mirror of
https://github.com/google/googletest.git
synced 2025-04-04 21:15:03 +00:00
Support wstring_view for String comparison Macros
Using the feature test macro since there are combinations with Abseil which has an string_view equivalent but no wstring_view.
This commit is contained in:
parent
816b3ac0cc
commit
92c604f9f3
2 changed files with 26 additions and 0 deletions
|
@ -1517,6 +1517,22 @@ GTEST_ATTRIBUTE_UNUSED_ static inline AssertionResult CmpHelperSTRCASENE(
|
|||
}
|
||||
#endif // GTEST_INTERNAL_HAS_STRING_VIEW
|
||||
|
||||
#if __cpp_lib_string_view >= 201803L
|
||||
GTEST_ATTRIBUTE_UNUSED_ static inline AssertionResult CmpHelperSTREQ(
|
||||
const char* s1_expression, const char* s2_expression,
|
||||
const std::wstring_view& s1, const std::wstring_view& s2) {
|
||||
return CmpHelperSTREQ(s1_expression, s2_expression, std::wstring(s1).c_str(),
|
||||
std::wstring(s2).c_str());
|
||||
}
|
||||
|
||||
GTEST_ATTRIBUTE_UNUSED_ static inline AssertionResult CmpHelperSTRNE(
|
||||
const char* s1_expression, const char* s2_expression,
|
||||
const std::wstring_view& s1, const std::wstring_view& s2) {
|
||||
return CmpHelperSTRNE(s1_expression, s2_expression, std::wstring(s1).c_str(),
|
||||
std::wstring(s2).c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// IsSubstring() and IsNotSubstring() are intended to be used as the
|
||||
|
|
|
@ -2597,6 +2597,16 @@ TEST(StringAssertionTest, STRNE_Wide) {
|
|||
ASSERT_STRNE(L"abc\x8119", L"abc\x8120") << "This shouldn't happen";
|
||||
}
|
||||
|
||||
#if __cpp_lib_string_view >= 201803L
|
||||
// Tests correct mapping to the C-String functions
|
||||
TEST(StringAssertionTest, StringView_Wide) {
|
||||
using std::wstring_view;
|
||||
ASSERT_STREQ(wstring_view(L"hi"), wstring_view(L"hi"));
|
||||
ASSERT_STREQ(wstring_view(L"hi"), L"hi");
|
||||
ASSERT_STRNE(L"hi", wstring_view(L"hi2"));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Tests for ::testing::IsSubstring().
|
||||
|
||||
// Tests that IsSubstring() returns the correct result when the input
|
||||
|
|
Loading…
Add table
Reference in a new issue