aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/StringRefTest.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-03-04 10:55:27 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-03-04 10:55:27 +0000
commitca99ad3f0dfd67d8c3f0873e90afc27ff11c8545 (patch)
tree76415a3e10929fa0978a20b8ea9056c35474ad19 /llvm/unittests/ADT/StringRefTest.cpp
parent97b935962308680e9f18bba06bcbdd05fdd7b4db (diff)
downloadllvm-ca99ad3f0dfd67d8c3f0873e90afc27ff11c8545.zip
llvm-ca99ad3f0dfd67d8c3f0873e90afc27ff11c8545.tar.gz
llvm-ca99ad3f0dfd67d8c3f0873e90afc27ff11c8545.tar.bz2
Add generic support for hashing StringRef objects using the new hashing library.
llvm-svn: 152003
Diffstat (limited to 'llvm/unittests/ADT/StringRefTest.cpp')
-rw-r--r--llvm/unittests/ADT/StringRefTest.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp
index d910843..b2f6fdc 100644
--- a/llvm/unittests/ADT/StringRefTest.cpp
+++ b/llvm/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