assertEquals("a{}b",
StringUtils.replaceDelimited(null, "{", "}", r, "a{}b"));
}
public void testLineSplit() {
ArrayList answer = new ArrayList();
answer.add("");
List split = StringUtils.splitIntoLines("");
assertEquals(answer.size(), split.size());
assertEquals(answer, split);
// The three flavors of line endings
String[] endings = { "\n", "\r", "\r\n" };
// We want to see an array with one empty string (the text before the
// newline). There is no string after the newline.
for (int i = 0; i < endings.length; ++i) {
split = StringUtils.splitIntoLines(endings[i]);
assertEquals(answer.size(), split.size());
assertEquals(answer, split);
}
answer.add("x");
for (int i = 0; i < endings.length; ++i) {
split = StringUtils.splitIntoLines(endings[i] + "x");
assertEquals(answer.size(), split.size());
assertEquals(answer, split);
}
answer = new ArrayList();
answer.add("line one");
answer.add("part deux");
answer.add("three's a crowd, eh?");
answer.add("");
split = StringUtils.splitIntoLines("line one\npart deux\nthree's a crowd, eh?"
+ "\n\n");
assertEquals(answer.size(), split.size());
assertEquals(answer, split);
// Test two newlines in a row
answer = new ArrayList();
answer.add("two newlines after this line");
answer.add("");
answer.add("part deux");
answer.add("three's a crowd, eh?");
answer.add("");
split = StringUtils.splitIntoLines("two newlines after this line\n\npart deux\nthree's a crowd, eh?"
+ "\n\n");
assertEquals(answer.size(), split.size());
assertEquals(answer, split);
split = StringUtils.splitIntoLines("two newlines after this line\r\n\r\npart deux\r\nthree's a crowd, eh?"
+ "\n\n");
assertEquals(answer.size(), split.size());
assertEquals(answer, split);
split = StringUtils.splitIntoLines("two newlines after this line\r\rpart deux\rthree's a crowd, eh?"
+ "\r\r");
assertEquals(answer.size(), split.size());
assertEquals(answer, split);
}