mass elimination of reliance on automatic iterator dereferencing
[oota-llvm.git] / unittests / ADT / StringRefTest.cpp
index 3c0cc58ad2d5c3a110376e3ccdd0fe06f738d963..887ba5d1f9e6e3d26b18938b278c827806f28b84 100644 (file)
@@ -9,10 +9,11 @@
 
 #include "gtest/gtest.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
-namespace {
+namespace llvm {
 
 std::ostream &operator<<(std::ostream &OS, const StringRef &S) {
   OS << S;
@@ -25,6 +26,9 @@ std::ostream &operator<<(std::ostream &OS,
   return OS;
 }
 
+}
+
+namespace {
 TEST(StringRefTest, Construction) {
   EXPECT_EQ("", StringRef());
   EXPECT_EQ("hello", StringRef("hello"));
@@ -49,6 +53,17 @@ TEST(StringRefTest, StringOps) {
   EXPECT_EQ( 1, StringRef("aab").compare("aaa"));
   EXPECT_EQ(-1, StringRef("aab").compare("aabb"));
   EXPECT_EQ( 1, StringRef("aab").compare("aa"));
+
+  EXPECT_EQ(-1, StringRef("aab").compare_numeric("aad"));
+  EXPECT_EQ( 0, StringRef("aab").compare_numeric("aab"));
+  EXPECT_EQ( 1, StringRef("aab").compare_numeric("aaa"));
+  EXPECT_EQ(-1, StringRef("aab").compare_numeric("aabb"));
+  EXPECT_EQ( 1, StringRef("aab").compare_numeric("aa"));
+  EXPECT_EQ(-1, StringRef("1").compare_numeric("10"));
+  EXPECT_EQ( 0, StringRef("10").compare_numeric("10"));
+  EXPECT_EQ( 0, StringRef("10a").compare_numeric("10a"));
+  EXPECT_EQ( 1, StringRef("2").compare_numeric("1"));
+  EXPECT_EQ( 0, StringRef("llvm_v1i64_ty").compare_numeric("llvm_v1i64_ty"));
 }
 
 TEST(StringRefTest, Operators) {
@@ -111,8 +126,8 @@ TEST(StringRefTest, Split) {
 }
 
 TEST(StringRefTest, Split2) {
-  std::vector<StringRef> parts;
-  std::vector<StringRef> expected;
+  SmallVector<StringRef, 5> parts;
+  SmallVector<StringRef, 5> expected;
 
   expected.push_back("ab"); expected.push_back("c");
   StringRef(",ab,,c,").split(parts, ",", -1, false);
@@ -142,6 +157,11 @@ TEST(StringRefTest, Split2) {
   StringRef(",").split(parts, ",", -1, true);
   EXPECT_TRUE(parts == expected);
 
+  expected.clear(); parts.clear();
+  expected.push_back("a"); expected.push_back("b");
+  StringRef("a,b").split(parts, ",", -1, true);
+  EXPECT_TRUE(parts == expected);
+
   // Test MaxSplit
   expected.clear(); parts.clear();
   expected.push_back("a,,b,c");
@@ -192,6 +212,14 @@ TEST(StringRefTest, StartsWith) {
   EXPECT_FALSE(Str.startswith("hi"));
 }
 
+TEST(StringRefTest, EndsWith) {
+  StringRef Str("hello");
+  EXPECT_TRUE(Str.endswith("lo"));
+  EXPECT_FALSE(Str.endswith("helloworld"));
+  EXPECT_FALSE(Str.endswith("worldhello"));
+  EXPECT_FALSE(Str.endswith("so"));
+}
+
 TEST(StringRefTest, Find) {
   StringRef Str("hello");
   EXPECT_EQ(2U, Str.find('l'));
@@ -230,6 +258,11 @@ TEST(StringRefTest, Count) {
   EXPECT_EQ(0U, Str.count("zz"));
 }
 
+TEST(StringRefTest, EditDistance) {
+  StringRef Str("hello");
+  EXPECT_EQ(2U, Str.edit_distance("hill"));
+}
+
 TEST(StringRefTest, Misc) {
   std::string Storage;
   raw_string_ostream OS(Storage);