]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.support/ext/test/org/argeo/slc/diff/LineTokenizerTest.java
Do not protect OPTIONS in runner servlet in order to enable CORS
[gpl/argeo-slc.git] / org.argeo.slc.support / ext / test / org / argeo / slc / diff / LineTokenizerTest.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.diff;
17
18 import java.util.List;
19
20 import junit.framework.TestCase;
21
22 public class LineTokenizerTest extends TestCase {
23 public void testSimple() throws Exception {
24 testAndAssert("a,b,c", new String[] { "a", "b", "c" });
25 testAndAssert("hello,bonjour,hallo,priviet", new String[] { "hello",
26 "bonjour", "hallo", "priviet" });
27 }
28
29 public void testTricky() throws Exception {
30 testAndAssert("alone", new String[] { "alone" });
31 testAndAssert("", new String[] { "" });
32
33 testAndAssert(",hello,bonjour,hallo,priviet", new String[] { "",
34 "hello", "bonjour", "hallo", "priviet" });
35 testAndAssert("hello,bonjour,,hallo,priviet", new String[] { "hello",
36 "bonjour", "", "hallo", "priviet" });
37 testAndAssert("hello,bonjour,hallo,priviet,", new String[] { "hello",
38 "bonjour", "hallo", "priviet", "" });
39 testAndAssert(",hello,,bonjour,hallo,,,,priviet,", new String[] { "",
40 "hello", "", "bonjour", "hallo", "", "", "", "priviet", "" });
41
42 testAndAssert(",,,", new String[] { "", "", "", "" });
43 }
44
45 public void testComplex() throws Exception {
46 testAndAssert("a#b#c", '#', "", new String[] { "a", "b", "c" });
47 testAndAssert("hello!bonjour!hallo!priviet", '!', "", new String[] {
48 "hello", "bonjour", "hallo", "priviet" });
49
50 testAndAssert("hello,,bonjour,,hallo,priviet", ',', "<EMPTY>",
51 new String[] { "hello", "<EMPTY>", "bonjour", "<EMPTY>",
52 "hallo", "priviet" });
53 }
54
55 private void testAndAssert(String str, String[] expected) {
56 testAndAssert(str, ',', "", expected);
57 }
58
59 private void testAndAssert(String str, Character sep, String noValueStr,
60 String[] expected) {
61 List<String> res = LineTokenizer.tokenize(str, sep, noValueStr);
62 assertEquals("Size", expected.length, res.size());
63 for (int i = 0; i < res.size(); i++) {
64 String token = res.get(i);
65 assertEquals("Value@" + i, expected[i], token);
66 }
67 }
68 }