summaryrefslogtreecommitdiff
path: root/unittests/ADT/HashingTest.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-03-04 10:23:15 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-03-04 10:23:15 +0000
commit9406da6e664a24c8e408cbba63daf162ca166ed9 (patch)
tree4f98485a81a21181813c819457cc02109c2927a9 /unittests/ADT/HashingTest.cpp
parent21d60d51618e03a970aa4c00a0d157abceedb3e7 (diff)
downloadllvm-9406da6e664a24c8e408cbba63daf162ca166ed9.tar.gz
llvm-9406da6e664a24c8e408cbba63daf162ca166ed9.tar.bz2
llvm-9406da6e664a24c8e408cbba63daf162ca166ed9.tar.xz
Teach the hashing facilities how to hash std::string objects.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152000 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ADT/HashingTest.cpp')
-rw-r--r--unittests/ADT/HashingTest.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/unittests/ADT/HashingTest.cpp b/unittests/ADT/HashingTest.cpp
index f00cac253f..f5d6aed5b9 100644
--- a/unittests/ADT/HashingTest.cpp
+++ b/unittests/ADT/HashingTest.cpp
@@ -97,6 +97,23 @@ TEST(HashingTest, HashValueStdPair) {
hash_value(std::make_pair(obj1, std::make_pair(obj2, obj3))));
}
+TEST(HashingTest, HashValueStdString) {
+ std::string s = "Hello World!";
+ EXPECT_EQ(hash_combine_range(s.c_str(), s.c_str() + s.size()), hash_value(s));
+ EXPECT_EQ(hash_combine_range(s.c_str(), s.c_str() + s.size() - 1),
+ hash_value(s.substr(0, s.size() - 1)));
+ EXPECT_EQ(hash_combine_range(s.c_str() + 1, s.c_str() + s.size() - 1),
+ hash_value(s.substr(1, s.size() - 2)));
+
+ std::wstring ws = L"Hello Wide World!";
+ EXPECT_EQ(hash_combine_range(ws.c_str(), ws.c_str() + ws.size()),
+ hash_value(ws));
+ EXPECT_EQ(hash_combine_range(ws.c_str(), ws.c_str() + ws.size() - 1),
+ hash_value(ws.substr(0, ws.size() - 1)));
+ EXPECT_EQ(hash_combine_range(ws.c_str() + 1, ws.c_str() + ws.size() - 1),
+ hash_value(ws.substr(1, ws.size() - 2)));
+}
+
template <typename T, size_t N> T *begin(T (&arr)[N]) { return arr; }
template <typename T, size_t N> T *end(T (&arr)[N]) { return arr + N; }