|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.commons.csv; |
| 18 | + |
| 19 | +import java.io.File; |
| 20 | +import java.io.IOException; |
| 21 | +import java.nio.charset.Charset; |
| 22 | + |
| 23 | +import org.junit.Assert; |
| 24 | +import org.junit.Ignore; |
| 25 | +import org.junit.Test; |
| 26 | + |
| 27 | +public class JiraCsv167Test { |
| 28 | + |
| 29 | + @Test |
| 30 | + @Ignore("Fails") |
| 31 | + public void parse() throws IOException { |
| 32 | + File csvData = new File("src/test/resources/csv-167/sample1.csv"); |
| 33 | + CSVFormat format = CSVFormat.DEFAULT; |
| 34 | + // |
| 35 | + format = format.withAllowMissingColumnNames(false); |
| 36 | + format = format.withCommentMarker('#'); |
| 37 | + format = format.withDelimiter(','); |
| 38 | + format = format.withEscape('\\'); |
| 39 | + format = format.withHeader("author", "title", "publishDate"); |
| 40 | + format = format.withHeaderComments("headerComment"); |
| 41 | + format = format.withNullString("NULL"); |
| 42 | + format = format.withIgnoreEmptyLines(true); |
| 43 | + format = format.withIgnoreSurroundingSpaces(true); |
| 44 | + format = format.withQuote('"'); |
| 45 | + format = format.withQuoteMode(QuoteMode.ALL); |
| 46 | + format = format.withRecordSeparator('\n'); |
| 47 | + format = format.withSkipHeaderRecord(false); |
| 48 | + // |
| 49 | + CSVParser parser = CSVParser.parse(csvData, Charset.defaultCharset(), format); |
| 50 | + int comments = 0; |
| 51 | + int records = 0; |
| 52 | + for (CSVRecord csvRecord : parser) { |
| 53 | + if (csvRecord.isComment()) { |
| 54 | + comments++; |
| 55 | + } else { |
| 56 | + records++; |
| 57 | + // System.out.println("[" + csvRecord.toString() + "]"); |
| 58 | + } |
| 59 | + } |
| 60 | + // Comment lines are concatenated, in this example 4 lines become 2 comments. |
| 61 | + Assert.assertEquals(2, comments); |
| 62 | + Assert.assertEquals(3, records); |
| 63 | + } |
| 64 | +} |
0 commit comments