[ 
https://issues.apache.org/jira/browse/CSV-265?focusedWorklogId=623041&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-623041
 ]

ASF GitHub Bot logged work on CSV-265:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 15/Jul/21 13:17
            Start Date: 15/Jul/21 13:17
    Worklog Time Spent: 10m 
      Work Description: garydgregory commented on a change in pull request #120:
URL: https://github.com/apache/commons-csv/pull/120#discussion_r670451842



##########
File path: src/test/java/org/apache/commons/csv/issues/JiraCsv265Test.java
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.jupiter.api.Assertions.assertEquals;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Iterator;
+
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVParser;
+import org.apache.commons.csv.CSVRecord;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests [CSV-265] {@link CSVRecord#getCharacterPosition()} returns the 
correct position after encountering a comment.
+ */
+public class JiraCsv265Test {
+
+    @Test
+    public void testJiraCsv265Test() throws IOException {
+        // @formatter:off
+        final String csv = "# Comment1\n"
+                         + "Header1,Header2\n"
+                         + "# Comment2\n"
+                         + "Value1,Value2\n"
+                         + "# Comment3\n"
+                         + "Value3,Value4\n"
+                         + "# Comment4\n";
+        final CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
+            .setCommentMarker('#')
+            .setHeader()
+            .setSkipHeaderRecord(true)
+            .build();
+        // @formatter:on
+        try (final CSVParser parser = csvFormat.parse(new StringReader(csv))) {
+            final Iterator<CSVRecord> itr = parser.iterator();
+            final CSVRecord record1 = itr.next();
+            assertEquals(csv.indexOf("# Comment2"), 
record1.getCharacterPosition());
+            final CSVRecord record2 = itr.next();
+            assertEquals(csv.indexOf("# Comment3"), 
record2.getCharacterPosition());
+        }

Review comment:
       I'm trying to better understand what you are trying to do here... may 
you please add a test with comments that span multiple lines; for example, 
input like:
   ```
   # one
   # two
   data,data,data
   # three
   # foor
   data,data,data
   ```
   
   TY.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 623041)
    Time Spent: 1h 40m  (was: 1.5h)

> CSV comments break CSVRecord#getCharacterPosition
> -------------------------------------------------
>
>                 Key: CSV-265
>                 URL: https://issues.apache.org/jira/browse/CSV-265
>             Project: Commons CSV
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.8
>            Reporter: Tyler King
>            Priority: Major
>          Time Spent: 1h 40m
>  Remaining Estimate: 0h
>
> The CSVRecord#getCharacterPosition method returns an incorrect value after 
> the CSVParser has encountered a comment in the CSV file.
> Example:
>  
> {code:java}
> String csv = "# Comment\n"
>            + "Headers,Header2\n"
>            + "Value1,Value2\n";
> CSVFormat format = 
> CSVFormat.EXCEL.withCommentMarker('#').withFirstRecordAsHeader();
> CSVParser parser = new CSVParser(new StringReader(csv), format);
> long expectedPosition = csv.indexOf("Value1");
> long actualPosition = parser.iterator().next().getCharacterPosition();
> assertEquals(expectedPosition, actualPosition);{code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to