diff options
author | eeight <[email protected]> | 2022-04-07 11:33:15 +0300 |
---|---|---|
committer | eeight <[email protected]> | 2022-04-07 11:33:15 +0300 |
commit | a67b2a41b1807eb5d6c9eb77acbba297711cd0b2 (patch) | |
tree | 93d1ad678e114926c0a2beacfa8b70a86624a094 /util/generic/hash_ut.cpp | |
parent | 4d5dc0e55df42e1f407c2809485f9742e10e5509 (diff) |
Fix computation of hashes for string constants
ref:75452b050cafabe119c50e518c3db644d8d9404f
Diffstat (limited to 'util/generic/hash_ut.cpp')
-rw-r--r-- | util/generic/hash_ut.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/util/generic/hash_ut.cpp b/util/generic/hash_ut.cpp index 0551d587708..68dd9d9d78d 100644 --- a/util/generic/hash_ut.cpp +++ b/util/generic/hash_ut.cpp @@ -59,6 +59,7 @@ class THashTest: public TTestBase { UNIT_TEST(TestHMSetInitializerList); UNIT_TEST(TestHSetInsertInitializerList); UNIT_TEST(TestTupleHash); + UNIT_TEST(TestStringHash); UNIT_TEST_SUITE_END(); using hmset = THashMultiSet<char, hash<char>, TEqualTo<char>>; @@ -110,6 +111,7 @@ protected: void TestHMSetInitializerList(); void TestHSetInsertInitializerList(); void TestTupleHash(); + void TestStringHash(); }; UNIT_TEST_SUITE_REGISTRATION(THashTest); @@ -1269,3 +1271,12 @@ void THashTest::TestTupleHash() { } }; } + +void THashTest::TestStringHash() { + // Make sure that different THash<> variants behave in the same way + const size_t expected = ComputeHash(TString("hehe")); + UNIT_ASSERT_VALUES_EQUAL(ComputeHash("hehe"), expected); // char[5] + UNIT_ASSERT_VALUES_EQUAL(ComputeHash("hehe"sv), expected); // std::string_view + UNIT_ASSERT_VALUES_EQUAL(ComputeHash(TStringBuf("hehe")), expected); // TStringBuf + UNIT_ASSERT_VALUES_EQUAL(ComputeHash<const char*>("hehe"), expected); // const char* +} |