Skip to content

Commit

Permalink
fixed issue #416
Browse files Browse the repository at this point in the history
  • Loading branch information
jbax committed Oct 12, 2020
1 parent e09114c commit 91e2c7f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 54,9 @@ public String[] headers() {
}

public String[] selectedHeaders() {
if(headers == null) {
headers();
}
int[] extractedFieldIndexes = extractedFieldIndexes();
if (extractedFieldIndexes != null) {
String[] extractedFields = new String[extractedFieldIndexes.length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 41,7 @@ public void detectedFormatTest() {
StringReader stringReader = new StringReader(lines);

CsvParserSettings parserSettings = new CsvParserSettings();
parserSettings.getFormat().setLineSeparator("\n");
parserSettings.setDelimiterDetectionEnabled(true, '|', '\t');

CsvParser csvParser = new CsvParser(parserSettings);
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/com/univocity/parsers/issues/github/Github_416.java
Original file line number Diff line number Diff line change
@@ -0,0 1,30 @@
package com.univocity.parsers.issues.github;

import com.univocity.parsers.csv.*;
import org.testng.annotations.*;

import java.io.*;

import static org.testng.Assert.*;


/**
* From: https://github.com/univocity/univocity-parsers/issues/416
*
* @author Univocity Software Pty Ltd - <a href="mailto:[email protected]">[email protected]</a>
*/
public class Github_416 {
@Test
public void testSelectedHeaders() {
CsvParserSettings s = new CsvParserSettings();
s.getFormat().setLineSeparator("\n");
s.setHeaderExtractionEnabled(true);
s.selectFields("a", "c", "e");

CsvParser p = new CsvParser(s);
p.beginParsing(new StringReader("a,b,c,d,e\n1,2,3,4,5"));
assertEquals(p.getContext().selectedHeaders(), new String[]{"a", "c", "e"});
assertEquals(p.getContext().parsedHeaders(), new String[]{"a", "b", "c", "d", "e"});
assertEquals(p.parseNext(), new String[]{"1", "3", "5"});
}
}

0 comments on commit 91e2c7f

Please sign in to comment.