public void SplitAcceptsWhitespaceDelimiters() { string testString = "a\nb\tc d"; string[] result = StringUtils.Split(testString, "\n\t ", true, false, null); Assert.AreEqual(new string[] { "a", "b", "c", "d" }, result); }
public void SplitAddsEmptyStrings() { string testString = ","; string[] result = StringUtils.Split(testString, ",", true, false, null); Assert.AreEqual(new string[] { "", "" }, result); }
public void SplitWithQuotedStrings() { string[] expectedParts = new string[] { "a", "[test,<,>>[]]]", "asdf<,<,>,>aa" }; string testString = string.Join(",", expectedParts); string[] result = StringUtils.Split(testString, ",", false, false, "[]<>"); Assert.AreEqual(expectedParts, result); }
public void SplitTests() { string testString = " a,b,, c ,d\n:e "; string delim = ",\n"; string[] res; string[] res1 = new string[] { " a", "b", "", " c ", "d", ":e " }; string[] res2 = new string[] { " a", "b", " c ", "d", ":e " }; string[] res3 = new string[] { "a", "b", "", "c", "d", ":e" }; string[] res4 = new string[] { "a", "b", "c", "d", ":e" }; Assert.AreEqual(0, StringUtils.Split(null, null, false, false).Length); Assert.AreEqual(testString, StringUtils.Split(testString, null, false, false)[0]); Assert.IsTrue(ArrayUtils.AreEqual(res1, res = StringUtils.Split(testString, delim, false, false)), "Received '" + String.Join(",", res) + "'"); Assert.IsTrue(ArrayUtils.AreEqual(res2, res = StringUtils.Split(testString, delim, false, true)), "Received '" + String.Join(",", res) + "'"); Assert.IsTrue(ArrayUtils.AreEqual(res3, res = StringUtils.Split(testString, delim, true, false)), "Received '" + String.Join(",", res) + "'"); Assert.IsTrue(ArrayUtils.AreEqual(res4, res = StringUtils.Split(testString, delim, true, true)), "Received '" + String.Join(",", res) + "'"); Assert.IsTrue(ArrayUtils.AreEqual(new string[] { "one" }, res = StringUtils.Split("one", delim, true, true)), "Received '" + String.Join(",", res) + "'"); }