]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/diff/LineTokenizerTest.java
6d59aa662ea06df0956c123119a9b1319f63cc0e
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.slc
.diff
;
19 import java
.util
.List
;
21 import junit
.framework
.TestCase
;
23 public class LineTokenizerTest
extends TestCase
{
24 public void testSimple() throws Exception
{
25 testAndAssert("a,b,c", new String
[] { "a", "b", "c" });
26 testAndAssert("hello,bonjour,hallo,priviet", new String
[] { "hello",
27 "bonjour", "hallo", "priviet" });
30 public void testTricky() throws Exception
{
31 testAndAssert("alone", new String
[] { "alone" });
32 testAndAssert("", new String
[] { "" });
34 testAndAssert(",hello,bonjour,hallo,priviet", new String
[] { "",
35 "hello", "bonjour", "hallo", "priviet" });
36 testAndAssert("hello,bonjour,,hallo,priviet", new String
[] { "hello",
37 "bonjour", "", "hallo", "priviet" });
38 testAndAssert("hello,bonjour,hallo,priviet,", new String
[] { "hello",
39 "bonjour", "hallo", "priviet", "" });
40 testAndAssert(",hello,,bonjour,hallo,,,,priviet,", new String
[] { "",
41 "hello", "", "bonjour", "hallo", "", "", "", "priviet", "" });
43 testAndAssert(",,,", new String
[] { "", "", "", "" });
46 public void testComplex() throws Exception
{
47 testAndAssert("a#b#c", '#', "", new String
[] { "a", "b", "c" });
48 testAndAssert("hello!bonjour!hallo!priviet", '!', "", new String
[] {
49 "hello", "bonjour", "hallo", "priviet" });
51 testAndAssert("hello,,bonjour,,hallo,priviet", ',', "<EMPTY>",
52 new String
[] { "hello", "<EMPTY>", "bonjour", "<EMPTY>",
53 "hallo", "priviet" });
56 private void testAndAssert(String str
, String
[] expected
) {
57 testAndAssert(str
, ',', "", expected
);
60 private void testAndAssert(String str
, Character sep
, String noValueStr
,
62 List
<String
> res
= LineTokenizer
.tokenize(str
, sep
, noValueStr
);
63 assertEquals("Size", expected
.length
, res
.size());
64 for (int i
= 0; i
< res
.size(); i
++) {
65 String token
= res
.get(i
);
66 assertEquals("Value@" + i
, expected
[i
], token
);