diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2012-03-04 10:55:27 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2012-03-04 10:55:27 +0000 |
commit | 528f0bbe19553dfadedca040df13a389daa7593d (patch) | |
tree | 77a3d2c6552856db2c37e33ceb865c4ac18adda0 /unittests/ADT | |
parent | e3e394d982a2bd2bc37edb1f8c3492d0382e37a9 (diff) | |
download | external_llvm-528f0bbe19553dfadedca040df13a389daa7593d.zip external_llvm-528f0bbe19553dfadedca040df13a389daa7593d.tar.gz external_llvm-528f0bbe19553dfadedca040df13a389daa7593d.tar.bz2 |
Add generic support for hashing StringRef objects using the new hashing library.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152003 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ADT')
-rw-r--r-- | unittests/ADT/StringRefTest.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index d910843..b2f6fdc 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -9,6 +9,7 @@ #include "gtest/gtest.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Hashing.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -291,4 +292,22 @@ TEST(StringRefTest, Misc) { EXPECT_EQ("hello", OS.str()); } +TEST(StringRefTest, Hashing) { + EXPECT_EQ(hash_value(std::string()), hash_value(StringRef())); + EXPECT_EQ(hash_value(std::string()), hash_value(StringRef(""))); + std::string S = "hello world"; + hash_code H = hash_value(S); + EXPECT_EQ(H, hash_value(StringRef("hello world"))); + EXPECT_EQ(H, hash_value(StringRef(S))); + EXPECT_NE(H, hash_value(StringRef("hello worl"))); + EXPECT_EQ(hash_value(std::string("hello worl")), + hash_value(StringRef("hello worl"))); + EXPECT_NE(H, hash_value(StringRef("hello world "))); + EXPECT_EQ(hash_value(std::string("hello world ")), + hash_value(StringRef("hello world "))); + EXPECT_EQ(H, hash_value(StringRef("hello world\0"))); + EXPECT_NE(hash_value(std::string("ello worl")), + hash_value(StringRef("hello world").slice(1, -1))); +} + } // end anonymous namespace |