aboutsummaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-07-21 07:28:51 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-07-21 07:28:51 +0000
commit43747827dd349142dcf8dd1377fdce5946745c8d (patch)
tree28f49f2604ed996dc231adc6548d424129abf429 /unittests
parent20d619a22d38458b52119bc33cc08baf7f75b141 (diff)
downloadexternal_llvm-43747827dd349142dcf8dd1377fdce5946745c8d.zip
external_llvm-43747827dd349142dcf8dd1377fdce5946745c8d.tar.gz
external_llvm-43747827dd349142dcf8dd1377fdce5946745c8d.tar.bz2
Add StringRef class, with fixes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76543 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/StringRefTest.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp
new file mode 100644
index 0000000..8a2c743
--- /dev/null
+++ b/unittests/ADT/StringRefTest.cpp
@@ -0,0 +1,59 @@
+//===- llvm/unittest/ADT/StringRefTest.cpp - StringRef unit tests ---------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/StringRef.h"
+using namespace llvm;
+
+namespace {
+
+TEST(StringRefTest, Construction) {
+ EXPECT_TRUE(StringRef() == "");
+ EXPECT_TRUE(StringRef("hello") == "hello");
+ EXPECT_TRUE(StringRef("hello world", 5) == "hello");
+ EXPECT_TRUE(StringRef(std::string("hello")) == "hello");
+}
+
+TEST(StringRefTest, Iteration) {
+ StringRef S("hello");
+ const char *p = "hello";
+ for (const char *it = S.begin(), *ie = S.end(); it != ie; ++it, ++p)
+ EXPECT_TRUE(*p == *it);
+}
+
+TEST(StringRefTest, StringOps) {
+ const char *p = "hello";
+ EXPECT_EQ(p, StringRef(p, 0).data());
+ EXPECT_TRUE(StringRef().empty());
+ EXPECT_EQ((size_t) 5, StringRef("hello").size());
+ EXPECT_EQ(-1, StringRef("aab").compare("aad"));
+ EXPECT_EQ( 0, StringRef("aab").compare("aab"));
+ EXPECT_EQ( 1, StringRef("aab").compare("aaa"));
+ EXPECT_EQ(-1, StringRef("aab").compare("aabb"));
+ EXPECT_EQ( 1, StringRef("aab").compare("aa"));
+}
+
+TEST(StringRefTest, Operators) {
+ EXPECT_TRUE(StringRef() == "");
+ EXPECT_TRUE(StringRef("aab") < StringRef("aad"));
+ EXPECT_FALSE(StringRef("aab") < StringRef("aab"));
+ EXPECT_TRUE(StringRef("aab") <= StringRef("aab"));
+ EXPECT_FALSE(StringRef("aab") <= StringRef("aaa"));
+ EXPECT_TRUE(StringRef("aad") > StringRef("aab"));
+ EXPECT_FALSE(StringRef("aab") > StringRef("aab"));
+ EXPECT_TRUE(StringRef("aab") >= StringRef("aab"));
+ EXPECT_FALSE(StringRef("aaa") >= StringRef("aab"));
+ EXPECT_TRUE(StringRef("aab") == StringRef("aab"));
+ EXPECT_FALSE(StringRef("aab") == StringRef("aac"));
+ EXPECT_FALSE(StringRef("aab") != StringRef("aab"));
+ EXPECT_TRUE(StringRef("aab") != StringRef("aac"));
+ EXPECT_EQ('a', StringRef("aab")[1]);
+}
+
+} // end anonymous namespace