]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.support/ext/test/org/argeo/slc/diff/LineTokenizerTest.java
2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.diff
;
18 import java
.util
.List
;
20 import junit
.framework
.TestCase
;
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" });
29 public void testTricky() throws Exception
{
30 testAndAssert("alone", new String
[] { "alone" });
31 testAndAssert("", new String
[] { "" });
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", "" });
42 testAndAssert(",,,", new String
[] { "", "", "", "" });
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" });
50 testAndAssert("hello,,bonjour,,hallo,priviet", ',', "<EMPTY>",
51 new String
[] { "hello", "<EMPTY>", "bonjour", "<EMPTY>",
52 "hallo", "priviet" });
55 private void testAndAssert(String str
, String
[] expected
) {
56 testAndAssert(str
, ',', "", expected
);
59 private void testAndAssert(String str
, Character sep
, String noValueStr
,
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
);