1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package bjc.utils.funcutils;
import java.io.StringReader;
import java.util.Scanner;
import org.junit.Test;
import static bjc.utils.funcutils.StringUtils.readLines;
import static bjc.utils.funcutils.TestUtils.assertIteratorEquals;
import static org.junit.Assert.assertEquals;
/**
* Tests of stuff in StringUtils.
*
* @author Ben Culkin
*/
public class StringUtilsTest {
@Test
public void testReadLines() {
assertReadLines("", "");
assertReadLines("hallo there", "hallo there");
assertReadLines("hallo there\na second line", "hallo there", "a second line");
assertReadLines("hallo there \\\na continued line", "hallo there a continued line");
assertReadLines("hallo there\\\\\na second line", "hallo there\\", "a second line");
assertReadLines("a\n\nb", "a", "", "b");
}
private static void assertReadLinesOpts(String inp, String... outp) {
StringReader sr = new StringReader(inp);
Scanner scn = new Scanner(sr);
assertIteratorEquals(readLines(scn), outp);
}
private static void assertReadLines(String inp, String... outp) {
StringReader sr = new StringReader(inp);
Scanner scn = new Scanner(sr);
assertIteratorEquals(readLines(scn), outp);
}
}
|