1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.csv.issues;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22
23 import org.apache.commons.csv.CSVFormat;
24 import org.apache.commons.csv.QuoteMode;
25 import org.junit.jupiter.api.Test;
26
27 public class JiraCsv148Test {
28
29 @Test
30 public void testWithIgnoreSurroundingSpacesEmpty() {
31
32 final CSVFormat format = CSVFormat.DEFAULT.builder()
33 .setQuoteMode(QuoteMode.ALL)
34 .setIgnoreSurroundingSpaces(true)
35 .get();
36
37 assertEquals(
38 "\"\",\" \",\" Single space on the left\",\"Single space on the right \"," +
39 "\" Single spaces on both sides \",\" Multiple spaces on the left\"," +
40 "\"Multiple spaces on the right \",\" Multiple spaces on both sides \"",
41 format.format("", " ", " Single space on the left", "Single space on the right ", " Single spaces on both sides ",
42 " Multiple spaces on the left", "Multiple spaces on the right ", " Multiple spaces on both sides "));
43 }
44
45
46
47
48
49 @Test
50 public void testWithTrimEmpty() {
51
52 final CSVFormat format = CSVFormat.DEFAULT.builder()
53 .setQuoteMode(QuoteMode.ALL)
54 .setTrim(true)
55 .get();
56
57 assertEquals(
58 "\"\",\"\",\"Single space on the left\",\"Single space on the right\"," + "\"Single spaces on both sides\",\"Multiple spaces on the left\"," +
59 "\"Multiple spaces on the right\",\"Multiple spaces on both sides\"",
60 format.format("", " ", " Single space on the left", "Single space on the right ", " Single spaces on both sides ",
61 " Multiple spaces on the left", "Multiple spaces on the right ", " Multiple spaces on both sides "));
62 }
63 }