Ejemplo n.º 1
0
 @Test
 public void writeQuotes() {
   StringWriter writer = new StringWriter();
   CSVPrint csvPrint = CSVUtil.createCSVPrint(writer);
   csvPrint.print("hello \"world\"");
   assertThat(writer.toString(), is("\"hello \"\"world\"\"\""));
 }
Ejemplo n.º 2
0
 @Ignore("reading with unix style csv for now")
 @Test
 public void readQuotes() throws IOException {
   LabeledCSVParser csvParser =
       CSVUtil.createLabeledCSVParser(IOUtils.toInputStream("name\n\"hello \"\"world\"\"\""));
   csvParser.getLine();
   assertThat(csvParser.getValueByLabel("name"), is("hello \"world\""));
 }
Ejemplo n.º 3
0
 private void subtestQuoteCSVValue(String[] inputs, String[] outputs, String sep) {
   assertEquals("Input and output test case have same size", inputs.length, outputs.length);
   for (int i = 0; i < inputs.length; i++) {
     String input = inputs[i];
     String output = outputs[i];
     String actualOutput = CSVUtil.quoteCSVValue(input, sep);
     assertEquals("Quoting of test value with index " + i + "\" is correct", output, actualOutput);
   }
 }
Ejemplo n.º 4
0
  @Test
  public void parseSomeMore() throws IOException {
    String csvString =
        "\"Obs\",\"spcode\", \"sizecl\", \"cruise\", \"stcode\", \"numstom\", \"numfood\", \"pctfull\", \"predator famcode\", \"prey\", \"number\", \"season\", \"depth\", \"transect\", \"alphcode\", \"taxord\", \"station\", \"long\", \"lat\", \"time\", \"sizeclass\", \"predator\"\n";
    csvString +=
        "1, 1, 16, 3, 2, 6, 6, 205.5, 1, \"Ampelisca sp. (abdita complex)\", 1, \"Summer\", 60, \"Chandeleur Islands\", \"aabd\", 47.11, \"C2\", 348078.84, 3257617.25, 313, \"201-300\", \"Rhynchoconger flavus\"\n";
    csvString +=
        "2, 11, 2, 1, 1, 20, 15, 592.5, 6, \"Ampelisca sp. (abdita complex)\", 1, \"Summer\", 20, \"Chandeleur Islands\", \"aabd\", 47.11, \"C1\", 344445.31, 3323087.25, 144, \"26-50\", \"Halieutichthys aculeatus\"\n";

    LabeledCSVParser parser = CSVUtil.createLabeledCSVParser(new StringReader(csvString));
    parser.getLine();
    assertThat(parser.getValueByLabel("prey"), is("Ampelisca sp. (abdita complex)"));
  }
Ejemplo n.º 5
0
 private void subtestMakeCSVRow(String[] input, String[] output, String sep) {
   String row = CSVUtil.makeCSVRow(GENERAL_VALUES_INPUT, sep, false);
   assertRowValues(row, GENERAL_VALUES_OUTPUT, sep);
 }
Ejemplo n.º 6
0
 public void testMakeCSVRowWithNulls() {
   String sep = ICSVDataExtractionOption.SEPARATOR_COMMA;
   String row = CSVUtil.makeCSVRow(new String[] {null, null, "a", null}, sep, false);
   assertRowValues(row, new String[] {"", "", "a", ""}, sep);
 }
Ejemplo n.º 7
0
 public void testMakeCSVRowOneColumn() {
   String sep = ICSVDataExtractionOption.SEPARATOR_COMMA;
   String[] values = {"one column only"};
   String row = CSVUtil.makeCSVRow(values, sep, false);
   assertRowValues(row, values, sep);
 }
Ejemplo n.º 8
0
 @Test
 public void readQuotesAgain() throws IOException {
   CSVParse csvParser = CSVUtil.createCSVParse(IOUtils.toInputStream("\"hello \"\"world\"\"\""));
   assertThat(csvParser.nextValue(), is("hello \"world\""));
 }