#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Allocator.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
using namespace llvm;
expected.push_back("a"); expected.push_back("b"); expected.push_back("c");
StringRef("a,,b,c").split(parts, ",", 3, false);
EXPECT_TRUE(parts == expected);
+
+ expected.clear(); parts.clear();
+ expected.push_back("a"); expected.push_back("b"); expected.push_back("c");
+ StringRef("a,,b,c").split(parts, ',', 3, false);
+ EXPECT_TRUE(parts == expected);
+
+ expected.clear(); parts.clear();
+ expected.push_back("");
+ StringRef().split(parts, ",", 0, true);
+ EXPECT_TRUE(parts == expected);
+
+ expected.clear(); parts.clear();
+ expected.push_back(StringRef());
+ StringRef("").split(parts, ",", 0, true);
+ EXPECT_TRUE(parts == expected);
+
+ expected.clear(); parts.clear();
+ StringRef("").split(parts, ",", 0, false);
+ EXPECT_TRUE(parts == expected);
+ StringRef().split(parts, ",", 0, false);
+ EXPECT_TRUE(parts == expected);
+
+ expected.clear(); parts.clear();
+ expected.push_back("a");
+ expected.push_back("");
+ expected.push_back("b");
+ expected.push_back("c,d");
+ StringRef("a,,b,c,d").split(parts, ",", 3, true);
+ EXPECT_TRUE(parts == expected);
+
+ expected.clear(); parts.clear();
+ expected.push_back("");
+ StringRef().split(parts, ',', 0, true);
+ EXPECT_TRUE(parts == expected);
+
+ expected.clear(); parts.clear();
+ expected.push_back(StringRef());
+ StringRef("").split(parts, ',', 0, true);
+ EXPECT_TRUE(parts == expected);
+
+ expected.clear(); parts.clear();
+ StringRef("").split(parts, ',', 0, false);
+ EXPECT_TRUE(parts == expected);
+ StringRef().split(parts, ',', 0, false);
+ EXPECT_TRUE(parts == expected);
+
+ expected.clear(); parts.clear();
+ expected.push_back("a");
+ expected.push_back("");
+ expected.push_back("b");
+ expected.push_back("c,d");
+ StringRef("a,,b,c,d").split(parts, ',', 3, true);
+ EXPECT_TRUE(parts == expected);
}
TEST(StringRefTest, Trim) {
EXPECT_TRUE(v2_join3);
}
-static void fn_stringref(StringRef str) {
- EXPECT_TRUE(str == "hello");
-}
-static void fn_conststringref(ConstStringRef str) {
- fn_stringref(str);
-}
-TEST(StringRefTest, constStringRef) {
- LLVM_CONSTEXPR ConstStringRef csr("hello");
-#if __has_feature(cxx_constexpr) || defined(__GXX_EXPERIMENTAL_CXX0X__)
- LLVM_STATIC_ASSERT(csr[0] != csr[1], "");
- LLVM_STATIC_ASSERT(csr[2] == csr[3], "");
- LLVM_STATIC_ASSERT(csr.size() == 5, "");
-#endif
- llvm_expect(csr[2] == csr[3]);
- fn_conststringref(csr);
+TEST(StringRefTest, AllocatorCopy) {
+ BumpPtrAllocator Alloc;
+ StringRef Str1 = "hello";
+ StringRef Str2 = "bye";
+ StringRef Str1c = Str1.copy(Alloc);
+ StringRef Str2c = Str2.copy(Alloc);
+ EXPECT_TRUE(Str1.equals(Str1c));
+ EXPECT_NE(Str1.data(), Str1c.data());
+ EXPECT_TRUE(Str2.equals(Str2c));
+ EXPECT_NE(Str2.data(), Str2c.data());
}
+
} // end anonymous namespace