X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=unittests%2FADT%2FStringRefTest.cpp;h=6cf2e6a0454dcba5802721e5f5a1b72b70be6ebc;hp=b240a87ef7544a483dc7d2340f76be45c63e9cda;hb=f41971f6e7f9e5ba0c590c7e35e2c1af0cd38c69;hpb=bad91954cf7c2caae19728bed33729a390d88725 diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index b240a87ef75..6cf2e6a0454 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -9,8 +9,10 @@ #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; @@ -223,6 +225,59 @@ TEST(StringRefTest, Split2) { 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) { @@ -531,22 +586,18 @@ TEST(StringRefTest, joinStrings) { 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