diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2009-11-13 01:24:40 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2009-11-13 01:24:40 +0000 |
| commit | 76af158707679cc7764fa8b91f1924a0f3976114 (patch) | |
| tree | ee40658b6a24ab4b4cf1a96d3a6a4d02dc567a30 /unittests/ADT/StringRefTest.cpp | |
| parent | 08ca9519152539cb987a447473da7bffb0ddada1 (diff) | |
| download | external_llvm-76af158707679cc7764fa8b91f1924a0f3976114.zip external_llvm-76af158707679cc7764fa8b91f1924a0f3976114.tar.gz external_llvm-76af158707679cc7764fa8b91f1924a0f3976114.tar.bz2 | |
Add a new split method to StringRef that puts the substrings in a vector.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@87058 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ADT/StringRefTest.cpp')
| -rw-r--r-- | unittests/ADT/StringRefTest.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index 7828b5f..3c0cc58 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -110,6 +110,81 @@ TEST(StringRefTest, Split) { Str.rsplit('o')); } +TEST(StringRefTest, Split2) { + std::vector<StringRef> parts; + std::vector<StringRef> expected; + + expected.push_back("ab"); expected.push_back("c"); + StringRef(",ab,,c,").split(parts, ",", -1, false); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back(""); expected.push_back("ab"); expected.push_back(""); + expected.push_back("c"); expected.push_back(""); + StringRef(",ab,,c,").split(parts, ",", -1, true); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back(""); + StringRef("").split(parts, ",", -1, true); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + StringRef("").split(parts, ",", -1, false); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + StringRef(",").split(parts, ",", -1, false); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back(""); expected.push_back(""); + StringRef(",").split(parts, ",", -1, true); + EXPECT_TRUE(parts == expected); + + // Test MaxSplit + expected.clear(); parts.clear(); + expected.push_back("a,,b,c"); + StringRef("a,,b,c").split(parts, ",", 0, true); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a,,b,c"); + StringRef("a,,b,c").split(parts, ",", 0, false); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a"); expected.push_back(",b,c"); + StringRef("a,,b,c").split(parts, ",", 1, true); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a"); expected.push_back(",b,c"); + StringRef("a,,b,c").split(parts, ",", 1, false); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a"); expected.push_back(""); expected.push_back("b,c"); + StringRef("a,,b,c").split(parts, ",", 2, true); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a"); expected.push_back("b,c"); + StringRef("a,,b,c").split(parts, ",", 2, false); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a"); expected.push_back(""); expected.push_back("b"); + expected.push_back("c"); + StringRef("a,,b,c").split(parts, ",", 3, true); + 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); +} + TEST(StringRefTest, StartsWith) { StringRef Str("hello"); EXPECT_TRUE(Str.startswith("he")); |
