-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace hand-written CSV parser with Apache Commons CSV
- Loading branch information
1 parent
b74d9b4
commit fae6c7c
Showing
6 changed files
with
51 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 18 additions & 21 deletions
39
src/main/java/org/javarosa/core/model/instance/CsvExternalInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 23 additions & 8 deletions
31
src/test/java/org/javarosa/core/model/instance/CsvExternalInstanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,39 @@ | ||
package org.javarosa.core.model.instance; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.javarosa.test.utils.ResourcePathHelper.r; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.IOException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class CsvExternalInstanceTest { | ||
private TreeElement root; | ||
|
||
@Before | ||
public void setUp() throws IOException { | ||
root = CsvExternalInstance.parse("id", r("non_trivial.csv").toString()); | ||
} | ||
|
||
@Test | ||
public void heading_has_no_extra_quotes() throws IOException { | ||
TreeElement root = CsvExternalInstance.parse("id", r("non_trivial.csv").toString()); | ||
public void heading_has_no_extra_quotes() { | ||
assertEquals("label", root.getChildAt(0).getChildAt(0).getName()); | ||
} | ||
|
||
@Test | ||
public void value_has_no_extra_quotes() throws IOException { | ||
TreeElement root = CsvExternalInstance.parse("id", r("non_trivial.csv").toString()); | ||
public void value_has_no_extra_quotes() { | ||
assertEquals("A", root.getChildAt(0).getChildAt(0).getValue().getValue()); | ||
} | ||
|
||
@Test | ||
public void quoted_string_with_comma() { | ||
assertEquals("121 Main St, NE", root.getChildAt(6).getChildAt(0).getValue().getValue()); | ||
} | ||
|
||
@Test | ||
public void missing_fields_replaced_with_spaces() { | ||
for (int fieldIndex = 1; fieldIndex < 2; fieldIndex++) { | ||
assertEquals("", root.getChildAt(5).getChildAt(fieldIndex).getValue().getValue()); | ||
} | ||
} | ||
} |
11 changes: 3 additions & 8 deletions
11
src/test/resources/org/javarosa/core/model/instance/non_trivial.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
"label","name","first" | ||
"A","a", | ||
B,b, | ||
C,c, | ||
C,c | ||
AA,aa,a | ||
AB,ab,a | ||
AC,ac,a | ||
BA,ba,b | ||
BB,bb,b | ||
BC,bc,b | ||
CA,ca,c | ||
CB,cb,c | ||
CC,cc,c | ||
AC | ||
"121 Main St, NE", main, m |