Skip to content

Commit de441b8

Browse files
committed
[CSV-148] Add testcases about withIgnoreSurroundingSpaces() and withTrim()
1 parent 57c7734 commit de441b8

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.commons.csv.issues;
18+
19+
import org.apache.commons.csv.CSVFormat;
20+
import org.apache.commons.csv.QuoteMode;
21+
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
24+
import org.junit.jupiter.api.Test;
25+
26+
public class JiraCsv148Test {
27+
28+
/**
29+
* The difference between withTrim()and withIgnoreSurroundingSpace():
30+
* difference: withTrim() can remove the leading and trailing spaces and newlines in quotation marks,
31+
* while withIgnoreSurroundingSpace() cannot
32+
* The same point: you can remove the leading and trailing spaces,tabs and other symbols.
33+
*/
34+
@Test
35+
public void testWithTrimEmpty() throws Exception {
36+
final CSVFormat format = CSVFormat.DEFAULT.withQuoteMode(QuoteMode.ALL).withTrim();
37+
assertEquals("\"\",\"\",\"Single space on the left\",\"Single space on the right\"," +
38+
"\"Single spaces on both sides\",\"Multiple spaces on the left\"," +
39+
"\"Multiple spaces on the right\",\"Multiple spaces on both sides\"",
40+
format.format("", " ", " Single space on the left", "Single space on the right ",
41+
" Single spaces on both sides ", " Multiple spaces on the left",
42+
"Multiple spaces on the right ", " Multiple spaces on both sides "));
43+
}
44+
45+
@Test
46+
public void testWithIgnoreSurroundingSpacesEmpty() throws Exception {
47+
final CSVFormat format = CSVFormat.DEFAULT.withQuoteMode(QuoteMode.ALL).withIgnoreSurroundingSpaces();
48+
assertEquals("\"\",\" \",\" Single space on the left\",\"Single space on the right \"," +
49+
"\" Single spaces on both sides \",\" Multiple spaces on the left\"," +
50+
"\"Multiple spaces on the right \",\" Multiple spaces on both sides \"",
51+
format.format("", " ", " Single space on the left", "Single space on the right ",
52+
" Single spaces on both sides ", " Multiple spaces on the left",
53+
"Multiple spaces on the right ", " Multiple spaces on both sides "));
54+
}
55+
}

0 commit comments

Comments
 (0)