blob: af7f9ff60fd548f545c945e78040090dcb3dc276 [file] [log] [blame]
/*
* 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 static org.junit.jupiter.api.Assertions.assertFalse;
import java.io.Reader;
import java.io.StringReader;
import java.util.Arrays;
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;
public class JiraCvs247Test {
@Test
public void testHeadersMissingOneColumn() throws Exception {
final Reader in = new StringReader("a,,c,d,e\n1,2,3,4,5\nv,w,x,y,z");
try (final CSVParser parser = CSVFormat.DEFAULT.withHeader().parse(in)) {
assertEquals(Arrays.asList("a", "", "c", "d", "e"), parser.getHeaderNames());
final Iterator<CSVRecord> iterator = parser.iterator();
CSVRecord record = iterator.next();
assertEquals("1", record.get(0));
assertEquals("2", record.get(1));
assertEquals("3", record.get(2));
assertEquals("4", record.get(3));
assertEquals("5", record.get(4));
record = iterator.next();
assertEquals("v", record.get(0));
assertEquals("w", record.get(1));
assertEquals("x", record.get(2));
assertEquals("y", record.get(3));
assertEquals("z", record.get(4));
assertFalse(iterator.hasNext());
}
}
@Test
public void testJiraDescription() throws Exception {
final Reader in = new StringReader("a,,c,d\n1,2,3,4\nx,y,z,zz");
try (final CSVParser parser = CSVFormat.DEFAULT.withHeader().parse(in)) {
parser.iterator();
}
}
}