diff options
author | Abseil Team <absl-team@google.com> | 2023-03-24 11:49:57 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-03-24 11:50:58 -0700 |
commit | 700e786e607788fb514a9021375191e47484fcb1 (patch) | |
tree | 15c6dc44e75f4b4a0c8b046b0fc417165d8764c7 /absl/hash/hash_test.cc | |
parent | 7b9f660fc35321c53f421e8e8948fa6e2042a4e1 (diff) |
Hash support for std::wstring_view/u16string_view/u32string_view
PiperOrigin-RevId: 519200954
Change-Id: I349023cacab0ac4cbefb8505efd29a5eda1e9067
Diffstat (limited to 'absl/hash/hash_test.cc')
-rw-r--r-- | absl/hash/hash_test.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/absl/hash/hash_test.cc b/absl/hash/hash_test.cc index 4ed6e50a..6727dafa 100644 --- a/absl/hash/hash_test.cc +++ b/absl/hash/hash_test.cc @@ -53,6 +53,10 @@ #include "absl/numeric/int128.h" #include "absl/strings/cord_test_helpers.h" +#ifdef ABSL_HAVE_STD_STRING_VIEW +#include <string_view> +#endif + namespace { // Utility wrapper of T for the purposes of testing the `AbslHash` type erasure @@ -488,6 +492,47 @@ TEST(HashValueTest, U32String) { std::u32string(U"Iñtërnâtiônàlizætiøn")))); } +TEST(HashValueTest, WStringView) { +#ifndef ABSL_HAVE_STD_STRING_VIEW + GTEST_SKIP(); +#else + EXPECT_TRUE((is_hashable<std::wstring_view>::value)); + + EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(std::make_tuple( + std::wstring_view(), std::wstring_view(L"ABC"), std::wstring_view(L"ABC"), + std::wstring_view(L"Some other different string_view"), + std::wstring_view(L"Iñtërnâtiônàlizætiøn")))); +#endif +} + +TEST(HashValueTest, U16StringView) { +#ifndef ABSL_HAVE_STD_STRING_VIEW + GTEST_SKIP(); +#else + EXPECT_TRUE((is_hashable<std::u16string_view>::value)); + + EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly( + std::make_tuple(std::u16string_view(), std::u16string_view(u"ABC"), + std::u16string_view(u"ABC"), + std::u16string_view(u"Some other different string_view"), + std::u16string_view(u"Iñtërnâtiônàlizætiøn")))); +#endif +} + +TEST(HashValueTest, U32StringView) { +#ifndef ABSL_HAVE_STD_STRING_VIEW + GTEST_SKIP(); +#else + EXPECT_TRUE((is_hashable<std::u32string_view>::value)); + + EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly( + std::make_tuple(std::u32string_view(), std::u32string_view(U"ABC"), + std::u32string_view(U"ABC"), + std::u32string_view(U"Some other different string_view"), + std::u32string_view(U"Iñtërnâtiônàlizætiøn")))); +#endif +} + TEST(HashValueTest, StdArray) { EXPECT_TRUE((is_hashable<std::array<int, 3>>::value)); |