Repository: commons-csv Updated Branches: refs/heads/master 18ed61621 -> 9afec3ed3
Rename test package org.apache.commons.csv.bugs to org.apache.commons.csv.issues. Project: http://git-wip-us.apache.org/repos/asf/commons-csv/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-csv/commit/9afec3ed Tree: http://git-wip-us.apache.org/repos/asf/commons-csv/tree/9afec3ed Diff: http://git-wip-us.apache.org/repos/asf/commons-csv/diff/9afec3ed Branch: refs/heads/master Commit: 9afec3ed39d954ae2ad927ee73445a9ee5163d07 Parents: 18ed616 Author: Gary Gregory <ggreg...@apache.org> Authored: Thu Dec 1 13:27:40 2016 -0800 Committer: Gary Gregory <ggreg...@apache.org> Committed: Thu Dec 1 13:27:40 2016 -0800 ---------------------------------------------------------------------- .../apache/commons/csv/bugs/JiraCsv164Test.java | 57 ------------- .../apache/commons/csv/bugs/JiraCsv167Test.java | 88 -------------------- .../apache/commons/csv/bugs/JiraCsv198Test.java | 47 ----------- .../commons/csv/issues/JiraCsv164Test.java | 57 +++++++++++++ .../commons/csv/issues/JiraCsv167Test.java | 88 ++++++++++++++++++++ .../commons/csv/issues/JiraCsv198Test.java | 47 +++++++++++ 6 files changed, 192 insertions(+), 192 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-csv/blob/9afec3ed/src/test/java/org/apache/commons/csv/bugs/JiraCsv164Test.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/csv/bugs/JiraCsv164Test.java b/src/test/java/org/apache/commons/csv/bugs/JiraCsv164Test.java deleted file mode 100644 index f8d6798..0000000 --- a/src/test/java/org/apache/commons/csv/bugs/JiraCsv164Test.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.csv.bugs; - -import static org.junit.Assert.assertTrue; - -import java.io.IOException; - -import org.apache.commons.csv.CSVFormat; -import org.apache.commons.csv.CSVPrinter; -import org.junit.Test; - -public class JiraCsv164Test { - - @Test - public void testJiraCsv154_withCommentMarker() throws IOException { - final String comment = "This is a header comment"; - final CSVFormat format = CSVFormat.EXCEL.withHeader("H1", "H2").withCommentMarker('#') - .withHeaderComments(comment); - final StringBuilder out = new StringBuilder(); - try (final CSVPrinter printer = format.print(out)) { - printer.print("A"); - printer.print("B"); - } - final String s = out.toString(); - assertTrue(s, s.contains(comment)); - } - - @Test - public void testJiraCsv154_withHeaderComments() throws IOException { - final String comment = "This is a header comment"; - final CSVFormat format = CSVFormat.EXCEL.withHeader("H1", "H2").withHeaderComments(comment) - .withCommentMarker('#'); - final StringBuilder out = new StringBuilder(); - try (final CSVPrinter printer = format.print(out)) { - printer.print("A"); - printer.print("B"); - } - final String s = out.toString(); - assertTrue(s, s.contains(comment)); - } - -} http://git-wip-us.apache.org/repos/asf/commons-csv/blob/9afec3ed/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java b/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java deleted file mode 100644 index 0592236..0000000 --- a/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.csv.bugs; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; - -import org.apache.commons.csv.CSVFormat; -import org.apache.commons.csv.CSVParser; -import org.apache.commons.csv.CSVRecord; -import org.apache.commons.csv.QuoteMode; -import org.junit.Assert; -import org.junit.Test; - -public class JiraCsv167Test { - - @Test - public void parse() throws IOException { - int totcomment = 0; - int totrecs = 0; - try (final BufferedReader br = new BufferedReader(getTestInput())) { - String s = null; - boolean lastWasComment = false; - while ((s = br.readLine()) != null) { - if (s.startsWith("#")) { - if (!lastWasComment) { // comments are merged - totcomment++; - } - lastWasComment = true; - } else { - totrecs++; - lastWasComment = false; - } - } - } - CSVFormat format = CSVFormat.DEFAULT; - // - format = format.withAllowMissingColumnNames(false); - format = format.withCommentMarker('#'); - format = format.withDelimiter(','); - format = format.withEscape('\\'); - format = format.withHeader("author", "title", "publishDate"); - format = format.withHeaderComments("headerComment"); - format = format.withNullString("NULL"); - format = format.withIgnoreEmptyLines(true); - format = format.withIgnoreSurroundingSpaces(true); - format = format.withQuote('"'); - format = format.withQuoteMode(QuoteMode.ALL); - format = format.withRecordSeparator('\n'); - format = format.withSkipHeaderRecord(false); - // - int comments = 0; - int records = 0; - try (final CSVParser parser = format.parse(getTestInput())) { - for (final CSVRecord csvRecord : parser) { - records++; - if (csvRecord.hasComment()) { - comments++; - } - } - } - // Comment lines are concatenated, in this example 4 lines become 2 comments. - Assert.assertEquals(totcomment, comments); - Assert.assertEquals(totrecs, records); // records includes the header - } - - private Reader getTestInput() { - final InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("csv-167/sample1.csv"); - return new InputStreamReader(is); - } -} http://git-wip-us.apache.org/repos/asf/commons-csv/blob/9afec3ed/src/test/java/org/apache/commons/csv/bugs/JiraCsv198Test.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/csv/bugs/JiraCsv198Test.java b/src/test/java/org/apache/commons/csv/bugs/JiraCsv198Test.java deleted file mode 100644 index 13126bd..0000000 --- a/src/test/java/org/apache/commons/csv/bugs/JiraCsv198Test.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.csv.bugs; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; - -import org.apache.commons.csv.CSVFormat; -import org.apache.commons.csv.CSVParser; -import org.apache.commons.csv.CSVRecord; -import org.junit.Assert; -import org.junit.Test; - -public class JiraCsv198Test { - - private static final CSVFormat CSV_FORMAT = CSVFormat.EXCEL.withDelimiter('^').withFirstRecordAsHeader(); - - @Test - public void test() throws UnsupportedEncodingException, IOException { - InputStream pointsOfReference = getClass().getResourceAsStream("/CSV-198/optd_por_public.csv"); - Assert.assertNotNull(pointsOfReference); - try (@SuppressWarnings("resource") - CSVParser parser = CSV_FORMAT.parse(new InputStreamReader(pointsOfReference, "UTF-8"))) { - for (CSVRecord record : parser) { - String locationType = record.get("location_type"); - Assert.assertNotNull(locationType); - } - } - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-csv/blob/9afec3ed/src/test/java/org/apache/commons/csv/issues/JiraCsv164Test.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv164Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv164Test.java new file mode 100644 index 0000000..07e8f94 --- /dev/null +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv164Test.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.csv.issues; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVPrinter; +import org.junit.Test; + +public class JiraCsv164Test { + + @Test + public void testJiraCsv154_withCommentMarker() throws IOException { + final String comment = "This is a header comment"; + final CSVFormat format = CSVFormat.EXCEL.withHeader("H1", "H2").withCommentMarker('#') + .withHeaderComments(comment); + final StringBuilder out = new StringBuilder(); + try (final CSVPrinter printer = format.print(out)) { + printer.print("A"); + printer.print("B"); + } + final String s = out.toString(); + assertTrue(s, s.contains(comment)); + } + + @Test + public void testJiraCsv154_withHeaderComments() throws IOException { + final String comment = "This is a header comment"; + final CSVFormat format = CSVFormat.EXCEL.withHeader("H1", "H2").withHeaderComments(comment) + .withCommentMarker('#'); + final StringBuilder out = new StringBuilder(); + try (final CSVPrinter printer = format.print(out)) { + printer.print("A"); + printer.print("B"); + } + final String s = out.toString(); + assertTrue(s, s.contains(comment)); + } + +} http://git-wip-us.apache.org/repos/asf/commons-csv/blob/9afec3ed/src/test/java/org/apache/commons/csv/issues/JiraCsv167Test.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv167Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv167Test.java new file mode 100644 index 0000000..d4c41aa --- /dev/null +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv167Test.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.csv.issues; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; + +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVParser; +import org.apache.commons.csv.CSVRecord; +import org.apache.commons.csv.QuoteMode; +import org.junit.Assert; +import org.junit.Test; + +public class JiraCsv167Test { + + @Test + public void parse() throws IOException { + int totcomment = 0; + int totrecs = 0; + try (final BufferedReader br = new BufferedReader(getTestInput())) { + String s = null; + boolean lastWasComment = false; + while ((s = br.readLine()) != null) { + if (s.startsWith("#")) { + if (!lastWasComment) { // comments are merged + totcomment++; + } + lastWasComment = true; + } else { + totrecs++; + lastWasComment = false; + } + } + } + CSVFormat format = CSVFormat.DEFAULT; + // + format = format.withAllowMissingColumnNames(false); + format = format.withCommentMarker('#'); + format = format.withDelimiter(','); + format = format.withEscape('\\'); + format = format.withHeader("author", "title", "publishDate"); + format = format.withHeaderComments("headerComment"); + format = format.withNullString("NULL"); + format = format.withIgnoreEmptyLines(true); + format = format.withIgnoreSurroundingSpaces(true); + format = format.withQuote('"'); + format = format.withQuoteMode(QuoteMode.ALL); + format = format.withRecordSeparator('\n'); + format = format.withSkipHeaderRecord(false); + // + int comments = 0; + int records = 0; + try (final CSVParser parser = format.parse(getTestInput())) { + for (final CSVRecord csvRecord : parser) { + records++; + if (csvRecord.hasComment()) { + comments++; + } + } + } + // Comment lines are concatenated, in this example 4 lines become 2 comments. + Assert.assertEquals(totcomment, comments); + Assert.assertEquals(totrecs, records); // records includes the header + } + + private Reader getTestInput() { + final InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("csv-167/sample1.csv"); + return new InputStreamReader(is); + } +} http://git-wip-us.apache.org/repos/asf/commons-csv/blob/9afec3ed/src/test/java/org/apache/commons/csv/issues/JiraCsv198Test.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv198Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv198Test.java new file mode 100644 index 0000000..c0c38b7 --- /dev/null +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv198Test.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.csv.issues; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; + +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVParser; +import org.apache.commons.csv.CSVRecord; +import org.junit.Assert; +import org.junit.Test; + +public class JiraCsv198Test { + + private static final CSVFormat CSV_FORMAT = CSVFormat.EXCEL.withDelimiter('^').withFirstRecordAsHeader(); + + @Test + public void test() throws UnsupportedEncodingException, IOException { + InputStream pointsOfReference = getClass().getResourceAsStream("/CSV-198/optd_por_public.csv"); + Assert.assertNotNull(pointsOfReference); + try (@SuppressWarnings("resource") + CSVParser parser = CSV_FORMAT.parse(new InputStreamReader(pointsOfReference, "UTF-8"))) { + for (CSVRecord record : parser) { + String locationType = record.get("location_type"); + Assert.assertNotNull(locationType); + } + } + } + +} \ No newline at end of file