]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.core/src/test/java/org/argeo/slc/diff/LineTokenizerTest.java
Restructure deployment
[gpl/argeo-slc.git] / org.argeo.slc.core / src / test / java / org / argeo / slc / diff / LineTokenizerTest.java
1 package org.argeo.slc.diff;
2
3 import java.util.List;
4
5 import junit.framework.TestCase;
6
7 public class LineTokenizerTest extends TestCase {
8 public void testSimple() throws Exception {
9 testAndAssert("a,b,c", new String[] { "a", "b", "c" });
10 testAndAssert("hello,bonjour,hallo,priviet", new String[] { "hello",
11 "bonjour", "hallo", "priviet" });
12 }
13
14 public void testTricky() throws Exception {
15 testAndAssert("alone", new String[] { "alone" });
16 testAndAssert("", new String[] { "" });
17
18 testAndAssert(",hello,bonjour,hallo,priviet", new String[] { "",
19 "hello", "bonjour", "hallo", "priviet" });
20 testAndAssert("hello,bonjour,,hallo,priviet", new String[] { "hello",
21 "bonjour", "", "hallo", "priviet" });
22 testAndAssert("hello,bonjour,hallo,priviet,", new String[] { "hello",
23 "bonjour", "hallo", "priviet", "" });
24 testAndAssert(",hello,,bonjour,hallo,,,,priviet,", new String[] { "",
25 "hello", "", "bonjour", "hallo", "", "", "", "priviet", "" });
26
27 testAndAssert(",,,", new String[] { "", "", "", "" });
28 }
29
30 public void testComplex() throws Exception {
31 testAndAssert("a#b#c", '#', "", new String[] { "a", "b", "c" });
32 testAndAssert("hello!bonjour!hallo!priviet", '!', "", new String[] {
33 "hello", "bonjour", "hallo", "priviet" });
34
35 testAndAssert("hello,,bonjour,,hallo,priviet", ',', "<EMPTY>",
36 new String[] { "hello", "<EMPTY>", "bonjour", "<EMPTY>",
37 "hallo", "priviet" });
38 }
39
40 private void testAndAssert(String str, String[] expected) {
41 testAndAssert(str, ',', "", expected);
42 }
43
44 private void testAndAssert(String str, Character sep, String noValueStr,
45 String[] expected) {
46 List<String> res = LineTokenizer.tokenize(str, sep, noValueStr);
47 assertEquals("Size", expected.length, res.size());
48 for (int i = 0; i < res.size(); i++) {
49 String token = res.get(i);
50 assertEquals("Value@" + i, expected[i], token);
51 }
52 }
53 }