comments tidied in TsvCsvImporterTests and ImporterUtilities

git-svn-id: http://google-refine.googlecode.com/svn/trunk@789 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Iain Sproat 2010-05-17 05:40:46 +00:00
parent 68fbd3320b
commit 6f74bcaa26
2 changed files with 4 additions and 41 deletions

View File

@ -15,9 +15,7 @@ public class ImporterUtilities {
static public Serializable parseCellValue(String text) { static public Serializable parseCellValue(String text) {
if (text.length() > 0) { if (text.length() > 0) {
if (text.length() > 1 && text.startsWith("\"") && text.endsWith("\"")) { if (text.length() > 1 && text.startsWith("\"") && text.endsWith("\"")) {
return text.substring(1, text.length() - 1); // FIXME is this a good assumption? return text.substring(1, text.length() - 1);
// what about the following string: '"To be" is almost always followed by "or not to be"'.
// This would be emitted as: 'To be" is almost always followed by "or not to be'
} }
try { try {

View File

@ -32,16 +32,19 @@ public class TsvCsvImporterTests {
//System Under Test //System Under Test
TsvCsvImporter SUT = null; TsvCsvImporter SUT = null;
RowParser parser = null;
//mock dependencies //mock dependencies
Project project = null; Project project = null;
Properties properties = null; Properties properties = null;
@BeforeMethod @BeforeMethod
public void SetUp(){ public void SetUp(){
SUT = new TsvCsvImporter(); SUT = new TsvCsvImporter();
project = new Project(); //FIXME - should we try and use mock(Project.class); - seems unnecessary complexity project = new Project(); //FIXME - should we try and use mock(Project.class); - seems unnecessary complexity
properties = mock(Properties.class); properties = mock(Properties.class);
parser = new CSVRowParser();
} }
@AfterMethod @AfterMethod
@ -54,12 +57,9 @@ public class TsvCsvImporterTests {
@Test @Test
public void readJustColumns(){ public void readJustColumns(){
String input = "col1,col2,col3"; String input = "col1,col2,col3";
//CSVReader reader = new CSVReader(new StringReader(input));
RowParser parser = new CSVRowParser();
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
//SUT.read(reader, project, -1, 0, 0, 1, false);
SUT.read(parser, lnReader, project, ",", -1, 0, 0, 1, false, true); SUT.read(parser, lnReader, project, ",", -1, 0, 0, 1, false, true);
} catch (IOException e) { } catch (IOException e) {
Assert.fail(); Assert.fail();
@ -74,11 +74,8 @@ public class TsvCsvImporterTests {
public void readSimpleData_CSV_1Header_1Row(){ public void readSimpleData_CSV_1Header_1Row(){
String input = "col1,col2,col3\n" + String input = "col1,col2,col3\n" +
"data1,data2,data3"; "data1,data2,data3";
//CSVReader reader = new CSVReader(new StringReader(input));
RowParser parser = new CSVRowParser();
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
//SUT.read(reader, project, -1, 0, 0, 1, false);
SUT.read(parser, lnReader, project, ",", -1, 0, 0, 1, false, true); SUT.read(parser, lnReader, project, ",", -1, 0, 0, 1, false, true);
} catch (IOException e) { } catch (IOException e) {
Assert.fail(); Assert.fail();
@ -94,14 +91,12 @@ public class TsvCsvImporterTests {
Assert.assertEquals(project.rows.get(0).cells.get(2).value, "data3"); Assert.assertEquals(project.rows.get(0).cells.get(2).value, "data3");
} }
// dfhuynh
@Test @Test
public void readSimpleData_TSV_1Header_1Row(){ public void readSimpleData_TSV_1Header_1Row(){
String input = "col1\tcol2\tcol3\n" + String input = "col1\tcol2\tcol3\n" +
"data1\tdata2\tdata3"; "data1\tdata2\tdata3";
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
//SUT.read(reader, project, -1, 0, 0, 1, false);
SUT.read(null, lnReader, project, "\t", -1, 0, 0, 1, false, true); SUT.read(null, lnReader, project, "\t", -1, 0, 0, 1, false, true);
} catch (IOException e) { } catch (IOException e) {
Assert.fail(); Assert.fail();
@ -120,11 +115,8 @@ public class TsvCsvImporterTests {
@Test @Test
public void readSimpleData_0Header_1Row(){ public void readSimpleData_0Header_1Row(){
String input = "data1,data2,data3"; String input = "data1,data2,data3";
//CSVReader reader = new CSVReader(new StringReader(input));
RowParser parser = new CSVRowParser();
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
//SUT.read(reader, project, -1, 0, 0, 0, false);
SUT.read(parser, lnReader, project, ",", -1, 0, 0, 0, false, true); SUT.read(parser, lnReader, project, ",", -1, 0, 0, 0, false, true);
} catch (IOException e) { } catch (IOException e) {
Assert.fail(); Assert.fail();
@ -143,11 +135,8 @@ public class TsvCsvImporterTests {
@Test @Test
public void readDoesNotTrimLeadingTrailingWhitespaceWhenNotGuessingValue(){ public void readDoesNotTrimLeadingTrailingWhitespaceWhenNotGuessingValue(){
String input = " data1, data2, data3"; String input = " data1, data2, data3";
//CSVReader reader = new CSVReader(new StringReader(input));
RowParser parser = new CSVRowParser();
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
//SUT.read(reader, project, -1, 0, 0, 0, false);
SUT.read(parser, lnReader, project, ",", -1, 0, 0, 0, false, true); SUT.read(parser, lnReader, project, ",", -1, 0, 0, 0, false, true);
} catch (IOException e) { } catch (IOException e) {
Assert.fail(); Assert.fail();
@ -163,11 +152,8 @@ public class TsvCsvImporterTests {
@Test @Test
public void readTrimsLeadingTrailingWhitespace(){ public void readTrimsLeadingTrailingWhitespace(){
String input = " data1, data2, data3"; String input = " data1, data2, data3";
//CSVReader reader = new CSVReader(new StringReader(input));
RowParser parser = new CSVRowParser();
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
//SUT.read(reader, project, -1, 0, 0, 0, true);
SUT.read(parser, lnReader, project, ",", -1, 0, 0, 0, true, true); SUT.read(parser, lnReader, project, ",", -1, 0, 0, 0, true, true);
} catch (IOException e) { } catch (IOException e) {
Assert.fail(); Assert.fail();
@ -183,11 +169,8 @@ public class TsvCsvImporterTests {
@Test @Test
public void readCanAddNull(){ public void readCanAddNull(){
String input = " data1, , data3"; String input = " data1, , data3";
//CSVReader reader = new CSVReader(new StringReader(input));
RowParser parser = new CSVRowParser();
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
//SUT.read(reader, project, -1, 0, 0, 0, true);
SUT.read(parser, lnReader, project, ",", -1, 0, 0, 0, true, true); SUT.read(parser, lnReader, project, ",", -1, 0, 0, 0, true, true);
} catch (IOException e) { } catch (IOException e) {
Assert.fail(); Assert.fail();
@ -205,11 +188,8 @@ public class TsvCsvImporterTests {
String input = "col1,col2,col3\n" + String input = "col1,col2,col3\n" +
"sub1,sub2,sub3\n" + "sub1,sub2,sub3\n" +
"data1,data2,data3"; "data1,data2,data3";
//CSVReader reader = new CSVReader(new StringReader(input));
RowParser parser = new CSVRowParser();
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
//SUT.read(reader, project, -1, 0, 0, 2, false);
SUT.read(parser, lnReader, project, ",", -1, 0, 0, 2, false, true); SUT.read(parser, lnReader, project, ",", -1, 0, 0, 2, false, true);
} catch (IOException e) { } catch (IOException e) {
Assert.fail(); Assert.fail();
@ -229,11 +209,8 @@ public class TsvCsvImporterTests {
public void readSimpleData_RowLongerThanHeader(){ public void readSimpleData_RowLongerThanHeader(){
String input = "col1,col2,col3\n" + String input = "col1,col2,col3\n" +
"data1,data2,data3,data4,data5,data6"; "data1,data2,data3,data4,data5,data6";
//CSVReader reader = new CSVReader(new StringReader(input));
RowParser parser = new CSVRowParser();
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
//SUT.read(reader, project, -1, 0, 0, 1, false);
SUT.read(parser, lnReader, project, ",", -1, 0, 0, 1, false, true); SUT.read(parser, lnReader, project, ",", -1, 0, 0, 1, false, true);
} catch (IOException e) { } catch (IOException e) {
Assert.fail(); Assert.fail();
@ -259,7 +236,6 @@ public class TsvCsvImporterTests {
public void readQuotedData(){ public void readQuotedData(){
String input = "col1,col2,col3\n" + String input = "col1,col2,col3\n" +
"\"\"\"To Be\"\" is often followed by \"\"or not To Be\"\"\",data2"; "\"\"\"To Be\"\" is often followed by \"\"or not To Be\"\"\",data2";
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
SUT.read(null, lnReader, project, ",", -1, 0, 0, 1, false, true); SUT.read(null, lnReader, project, ",", -1, 0, 0, 1, false, true);
@ -281,11 +257,8 @@ public class TsvCsvImporterTests {
String input = "ignore1\n" + String input = "ignore1\n" +
"col1,col2,col3\n" + "col1,col2,col3\n" +
"data1,data2,data3"; "data1,data2,data3";
//CSVReader reader = new CSVReader(new StringReader(input));
RowParser parser = new CSVRowParser();
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
//SUT.read(reader, project, -1, 0, 1, 1, false);
SUT.read(parser, lnReader, project, ",", -1, 0, 1, 1, false, true); SUT.read(parser, lnReader, project, ",", -1, 0, 1, 1, false, true);
} catch (IOException e) { } catch (IOException e) {
Assert.fail(); Assert.fail();
@ -306,11 +279,8 @@ public class TsvCsvImporterTests {
String input = "col1,col2,col3\n" + String input = "col1,col2,col3\n" +
"skip1\n" + "skip1\n" +
"data1,data2,data3"; "data1,data2,data3";
//CSVReader reader = new CSVReader(new StringReader(input));
RowParser parser = new CSVRowParser();
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
//SUT.read(reader, project, -1, 1, 0, 1, false);
SUT.read(parser, lnReader, project, ",", -1, 1, 0, 1, false, true); SUT.read(parser, lnReader, project, ",", -1, 1, 0, 1, false, true);
} catch (IOException e) { } catch (IOException e) {
Assert.fail(); Assert.fail();
@ -335,11 +305,8 @@ public class TsvCsvImporterTests {
"sub1,sub2,sub3\n" + "sub1,sub2,sub3\n" +
"skip1\n" + "skip1\n" +
"data1,data2,data3"; "data1,data2,data3";
//CSVReader reader = new CSVReader(new StringReader(input));
RowParser parser = new CSVRowParser();
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
//SUT.read(reader, project, -1, 1, 3, 2, false);
SUT.read(parser, lnReader, project, ",", -1, 1, 3, 2, false, true); SUT.read(parser, lnReader, project, ",", -1, 1, 3, 2, false, true);
} catch (IOException e) { } catch (IOException e) {
Assert.fail(); Assert.fail();
@ -367,7 +334,6 @@ public class TsvCsvImporterTests {
"data-row1-cell1,data-row1-cell2,data-row1-cell3\n" + "data-row1-cell1,data-row1-cell2,data-row1-cell3\n" +
"data-row2-cell1,data-row2-cell2,\n" + //missing last data point of this row on purpose "data-row2-cell1,data-row2-cell2,\n" + //missing last data point of this row on purpose
"data-row3-cell1,data-row3-cell2,data-row1-cell3"; "data-row3-cell1,data-row3-cell2,data-row1-cell3";
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
SUT.read(null, lnReader, project, ",", 2, 2, 3, 2, false, true); SUT.read(null, lnReader, project, ",", 2, 2, 3, 2, false, true);
@ -392,7 +358,6 @@ public class TsvCsvImporterTests {
public void readWithMultiLinedQuotedData(){ public void readWithMultiLinedQuotedData(){
String input = "col1,col2,col3\n" + String input = "col1,col2,col3\n" +
"\"\"\"To\n Be\"\" is often followed by \"\"or not To\n Be\"\"\",data2"; "\"\"\"To\n Be\"\" is often followed by \"\"or not To\n Be\"\"\",data2";
LineNumberReader lnReader = new LineNumberReader(new StringReader(input)); LineNumberReader lnReader = new LineNumberReader(new StringReader(input));
try { try {
SUT.read(null, lnReader, project, ",", -1, 0, 0, 1, false, true); SUT.read(null, lnReader, project, ",", -1, 0, 0, 1, false, true);