Return-Path: X-Original-To: apmail-commons-notifications-archive@minotaur.apache.org Delivered-To: apmail-commons-notifications-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BBFFA17E7D for ; Sun, 19 Apr 2015 16:02:32 +0000 (UTC) Received: (qmail 94523 invoked by uid 500); 19 Apr 2015 16:02:32 -0000 Delivered-To: apmail-commons-notifications-archive@commons.apache.org Received: (qmail 94485 invoked by uid 500); 19 Apr 2015 16:02:32 -0000 Mailing-List: contact notifications-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list notifications@commons.apache.org Received: (qmail 94138 invoked by uid 99); 19 Apr 2015 16:02:32 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Apr 2015 16:02:32 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 356BFAC0E7A for ; Sun, 19 Apr 2015 16:02:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r948234 [32/39] - in /websites/production/commons/content/proper/commons-csv: ./ apidocs/ apidocs/org/apache/commons/csv/ apidocs/org/apache/commons/csv/class-use/ apidocs/resources/ apidocs/src-html/org/apache/commons/csv/ cobertura/ css/ ... Date: Sun, 19 Apr 2015 16:02:28 -0000 To: notifications@commons.apache.org From: britter@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150419160232.356BFAC0E7A@hades.apache.org> Modified: websites/production/commons/content/proper/commons-csv/xref-test/org/apache/commons/csv/CSVParserTest.html ============================================================================== --- websites/production/commons/content/proper/commons-csv/xref-test/org/apache/commons/csv/CSVParserTest.html (original) +++ websites/production/commons/content/proper/commons-csv/xref-test/org/apache/commons/csv/CSVParserTest.html Sun Apr 19 16:02:26 2015 @@ -1,989 +1,989 @@ - - - -CSVParserTest xref - - - -
-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  
-18  package org.apache.commons.csv;
-19  
-20  import static org.apache.commons.csv.Constants.CR;
-21  import static org.apache.commons.csv.Constants.CRLF;
-22  import static org.apache.commons.csv.Constants.LF;
-23  import static org.junit.Assert.assertArrayEquals;
-24  import static org.junit.Assert.assertEquals;
-25  import static org.junit.Assert.assertFalse;
-26  import static org.junit.Assert.assertNotNull;
-27  import static org.junit.Assert.assertNull;
-28  import static org.junit.Assert.assertTrue;
-29  import static org.junit.Assert.fail;
-30  
-31  import java.io.File;
-32  import java.io.IOException;
-33  import java.io.InputStreamReader;
-34  import java.io.PipedReader;
-35  import java.io.PipedWriter;
-36  import java.io.Reader;
-37  import java.io.StringReader;
-38  import java.io.StringWriter;
-39  import java.net.URL;
-40  import java.nio.charset.Charset;
-41  import java.util.ArrayList;
-42  import java.util.Iterator;
-43  import java.util.List;
-44  import java.util.Map;
-45  import java.util.NoSuchElementException;
-46  
-47  import org.apache.commons.io.input.BOMInputStream;
-48  import org.junit.Assert;
-49  import org.junit.Ignore;
-50  import org.junit.Test;
-51  
-52  /**
-53   * CSVParserTest
-54   *
-55   * The test are organized in three different sections: The 'setter/getter' section, the lexer section and finally the
-56   * parser section. In case a test fails, you should follow a top-down approach for fixing a potential bug (its likely
-57   * that the parser itself fails if the lexer has problems...).
-58   *
-59   * @version $Id: CSVParserTest.java 1635129 2014-10-29 13:33:04Z ggregory $
-60   */
-61  public class CSVParserTest {
-62  
-63      private static final String CSV_INPUT = "a,b,c,d\n" + " a , b , 1 2 \n" + "\"foo baar\", b,\n"
-64      // + "   \"foo\n,,\n\"\",,\n\\\"\",d,e\n";
-65              + "   \"foo\n,,\n\"\",,\n\"\"\",d,e\n"; // changed to use standard CSV escaping
-66  
-67      private static final String CSV_INPUT_1 = "a,b,c,d";
-68  
-69      private static final String CSV_INPUT_2 = "a,b,1 2";
-70  
-71      private static final String[][] RESULT = { { "a", "b", "c", "d" }, { "a", "b", "1 2" }, { "foo baar", "b", "" },
-72              { "foo\n,,\n\",,\n\"", "d", "e" } };
-73  
-74      @Test
-75      public void testBackslashEscaping() throws IOException {
-76  
-77          // To avoid confusion over the need for escaping chars in java code,
-78          // We will test with a forward slash as the escape char, and a single
-79          // quote as the encapsulator.
-80  
-81          final String code = "one,two,three\n" // 0
-82                  + "'',''\n" // 1) empty encapsulators
-83                  + "/',/'\n" // 2) single encapsulators
-84                  + "'/'','/''\n" // 3) single encapsulators encapsulated via escape
-85                  + "'''',''''\n" // 4) single encapsulators encapsulated via doubling
-86                  + "/,,/,\n" // 5) separator escaped
-87                  + "//,//\n" // 6) escape escaped
-88                  + "'//','//'\n" // 7) escape escaped in encapsulation
-89                  + "   8   ,   \"quoted \"\" /\" // string\"   \n" // don't eat spaces
-90                  + "9,   /\n   \n" // escaped newline
-91                  + "";
-92          final String[][] res = { { "one", "two", "three" }, // 0
-93                  { "", "" }, // 1
-94                  { "'", "'" }, // 2
-95                  { "'", "'" }, // 3
-96                  { "'", "'" }, // 4
-97                  { ",", "," }, // 5
-98                  { "/", "/" }, // 6
-99                  { "/", "/" }, // 7
-100                 { "   8   ", "   \"quoted \"\" /\" / string\"   " }, { "9", "   \n   " }, };
-101 
-102         final CSVFormat format = CSVFormat.newFormat(',').withQuote('\'').withRecordSeparator(CRLF).withEscape('/')
-103                 .withIgnoreEmptyLines();
-104 
-105         final CSVParser parser = CSVParser.parse(code, format);
-106         final List<CSVRecord> records = parser.getRecords();
-107         assertTrue(records.size() > 0);
-108 
-109         Utils.compare("Records do not match expected result", res, records);
-110         parser.close();
-111     }
-112 
-113     @Test
-114     public void testBackslashEscaping2() throws IOException {
-115 
-116         // To avoid confusion over the need for escaping chars in java code,
-117         // We will test with a forward slash as the escape char, and a single
-118         // quote as the encapsulator.
-119 
-120         final String code = "" + " , , \n" // 1)
-121                 + " \t ,  , \n" // 2)
-122                 + " // , /, , /,\n" // 3)
-123                 + "";
-124         final String[][] res = { { " ", " ", " " }, // 1
-125                 { " \t ", "  ", " " }, // 2
-126                 { " / ", " , ", " ," }, // 3
-127         };
-128 
-129         final CSVFormat format = CSVFormat.newFormat(',').withRecordSeparator(CRLF).withEscape('/')
-130                 .withIgnoreEmptyLines();
-131 
-132         final CSVParser parser = CSVParser.parse(code, format);
-133         final List<CSVRecord> records = parser.getRecords();
-134         assertTrue(records.size() > 0);
-135 
-136         Utils.compare("", res, records);
-137         parser.close();
-138     }
-139 
-140     @Test
-141     @Ignore
-142     public void testBackslashEscapingOld() throws IOException {
-143         final String code = "one,two,three\n" + "on\\\"e,two\n" + "on\"e,two\n" + "one,\"tw\\\"o\"\n"
-144                 + "one,\"t\\,wo\"\n" + "one,two,\"th,ree\"\n" + "\"a\\\\\"\n" + "a\\,b\n" + "\"a\\\\,b\"";
-145         final String[][] res = { { "one", "two", "three" }, { "on\\\"e", "two" }, { "on\"e", "two" },
-146                 { "one", "tw\"o" }, { "one", "t\\,wo" }, // backslash in quotes only escapes a delimiter (",")
-147                 { "one", "two", "th,ree" }, { "a\\\\" }, // backslash in quotes only escapes a delimiter (",")
-148                 { "a\\", "b" }, // a backslash must be returnd
-149                 { "a\\\\,b" } // backslash in quotes only escapes a delimiter (",")
-150         };
-151         final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
-152         final List<CSVRecord> records = parser.getRecords();
-153         assertEquals(res.length, records.size());
-154         assertTrue(records.size() > 0);
-155         for (int i = 0; i < res.length; i++) {
-156             assertArrayEquals(res[i], records.get(i).values());
-157         }
-158         parser.close();
-159     }
-160 
-161     @Test
-162     @Ignore("CSV-107")
-163     public void testBOM() throws IOException {
-164         final URL url = ClassLoader.getSystemClassLoader().getResource("CSVFileParser/bom.csv");
-165         final CSVParser parser = CSVParser.parse(url, Charset.forName("UTF-8"), CSVFormat.EXCEL.withHeader());
-166         try {
-167             for (final CSVRecord record : parser) {
-168                 final String string = record.get("Date");
-169                 Assert.assertNotNull(string);
-170                 // System.out.println("date: " + record.get("Date"));
-171             }
-172         } finally {
-173             parser.close();
-174         }
-175     }
-176 
-177     @Test
-178     public void testBOMInputStream() throws IOException {
-179         final URL url = ClassLoader.getSystemClassLoader().getResource("CSVFileParser/bom.csv");
-180         final Reader reader = new InputStreamReader(new BOMInputStream(url.openStream()), "UTF-8");
-181         final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
-182         try {
-183             for (final CSVRecord record : parser) {
-184                 final String string = record.get("Date");
-185                 Assert.assertNotNull(string);
-186                 // System.out.println("date: " + record.get("Date"));
-187             }
-188         } finally {
-189             parser.close();
-190             reader.close();
-191         }
-192     }
-193 
-194     @Test
-195     public void testCarriageReturnEndings() throws IOException {
-196         final String code = "foo\rbaar,\rhello,world\r,kanu";
-197         final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
-198         final List<CSVRecord> records = parser.getRecords();
-199         assertEquals(4, records.size());
-200         parser.close();
-201     }
-202 
-203     @Test
-204     public void testCarriageReturnLineFeedEndings() throws IOException {
-205         final String code = "foo\r\nbaar,\r\nhello,world\r\n,kanu";
-206         final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
-207         final List<CSVRecord> records = parser.getRecords();
-208         assertEquals(4, records.size());
-209         parser.close();
-210     }
-211 
-212     @Test(expected = NoSuchElementException.class)
-213     public void testClose() throws Exception {
-214         final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");
-215         final CSVParser parser = CSVFormat.DEFAULT.withCommentMarker('#').withHeader().parse(in);
-216         final Iterator<CSVRecord> records = parser.iterator();
-217         assertTrue(records.hasNext());
-218         parser.close();
-219         assertFalse(records.hasNext());
-220         records.next();
-221     }
-222 
-223     @Test
-224     public void testCSV57() throws Exception {
-225         final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT);
-226         final List<CSVRecord> list = parser.getRecords();
-227         assertNotNull(list);
-228         assertEquals(0, list.size());
-229         parser.close();
-230     }
-231 
-232     @Test
-233     public void testDefaultFormat() throws IOException {
-234         final String code = "" + "a,b#\n" // 1)
-235                 + "\"\n\",\" \",#\n" // 2)
-236                 + "#,\"\"\n" // 3)
-237                 + "# Final comment\n"// 4)
-238         ;
-239         final String[][] res = { { "a", "b#" }, { "\n", " ", "#" }, { "#", "" }, { "# Final comment" } };
-240 
-241         CSVFormat format = CSVFormat.DEFAULT;
-242         assertFalse(format.isCommentMarkerSet());
-243 
-244         CSVParser parser = CSVParser.parse(code, format);
-245         List<CSVRecord> records = parser.getRecords();
-246         assertTrue(records.size() > 0);
-247 
-248         Utils.compare("Failed to parse without comments", res, records);
-249 
-250         final String[][] res_comments = { { "a", "b#" }, { "\n", " ", "#" }, };
-251 
-252         format = CSVFormat.DEFAULT.withCommentMarker('#');
-253         parser.close();
-254         parser = CSVParser.parse(code, format);
-255         records = parser.getRecords();
-256 
-257         Utils.compare("Failed to parse with comments", res_comments, records);
-258         parser.close();
-259     }
-260 
-261     @Test
-262     public void testEmptyFile() throws Exception {
-263         final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT);
-264         assertNull(parser.nextRecord());
-265         parser.close();
-266     }
-267 
-268     @Test
-269     public void testEmptyLineBehaviourCSV() throws Exception {
-270         final String[] codes = { "hello,\r\n\r\n\r\n", "hello,\n\n\n", "hello,\"\"\r\n\r\n\r\n", "hello,\"\"\n\n\n" };
-271         final String[][] res = { { "hello", "" } // CSV format ignores empty lines
-272         };
-273         for (final String code : codes) {
-274             final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
-275             final List<CSVRecord> records = parser.getRecords();
-276             assertEquals(res.length, records.size());
-277             assertTrue(records.size() > 0);
-278             for (int i = 0; i < res.length; i++) {
-279                 assertArrayEquals(res[i], records.get(i).values());
-280             }
-281             parser.close();
-282         }
-283     }
-284 
-285     @Test
-286     public void testEmptyLineBehaviourExcel() throws Exception {
-287         final String[] codes = { "hello,\r\n\r\n\r\n", "hello,\n\n\n", "hello,\"\"\r\n\r\n\r\n", "hello,\"\"\n\n\n" };
-288         final String[][] res = { { "hello", "" }, { "" }, // Excel format does not ignore empty lines
-289                 { "" } };
-290         for (final String code : codes) {
-291             final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL);
-292             final List<CSVRecord> records = parser.getRecords();
-293             assertEquals(res.length, records.size());
-294             assertTrue(records.size() > 0);
-295             for (int i = 0; i < res.length; i++) {
-296                 assertArrayEquals(res[i], records.get(i).values());
-297             }
-298             parser.close();
-299         }
-300     }
-301 
-302     @Test
-303     @Ignore
-304     public void testStartWithEmptyLinesThenHeaders() throws Exception {
-305         final String[] codes = {"\r\n\r\n\r\nhello,\r\n\r\n\r\n", "hello,\n\n\n", "hello,\"\"\r\n\r\n\r\n",
-306                 "hello,\"\"\n\n\n"};
-307         final String[][] res = {{"hello", ""}, {""}, // Excel format does not ignore empty lines
-308                 {""}};
-309         for (final String code : codes) {
-310             final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL);
-311             final List<CSVRecord> records = parser.getRecords();
-312             assertEquals(res.length, records.size());
-313             assertTrue(records.size() > 0);
-314             for (int i = 0; i < res.length; i++) {
-315                 assertArrayEquals(res[i], records.get(i).values());
-316             }
-317             parser.close();
-318         }
-319     }
-320 
-321     @Test
-322     public void testEndOfFileBehaviorCSV() throws Exception {
-323         final String[] codes = { "hello,\r\n\r\nworld,\r\n", "hello,\r\n\r\nworld,", "hello,\r\n\r\nworld,\"\"\r\n",
-324                 "hello,\r\n\r\nworld,\"\"", "hello,\r\n\r\nworld,\n", "hello,\r\n\r\nworld,",
-325                 "hello,\r\n\r\nworld,\"\"\n", "hello,\r\n\r\nworld,\"\"" };
-326         final String[][] res = { { "hello", "" }, // CSV format ignores empty lines
-327                 { "world", "" } };
-328         for (final String code : codes) {
-329             final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
-330             final List<CSVRecord> records = parser.getRecords();
-331             assertEquals(res.length, records.size());
-332             assertTrue(records.size() > 0);
-333             for (int i = 0; i < res.length; i++) {
-334                 assertArrayEquals(res[i], records.get(i).values());
-335             }
-336             parser.close();
-337         }
-338     }
-339 
-340     @Test
-341     public void testEndOfFileBehaviourExcel() throws Exception {
-342         final String[] codes = { "hello,\r\n\r\nworld,\r\n", "hello,\r\n\r\nworld,", "hello,\r\n\r\nworld,\"\"\r\n",
-343                 "hello,\r\n\r\nworld,\"\"", "hello,\r\n\r\nworld,\n", "hello,\r\n\r\nworld,",
-344                 "hello,\r\n\r\nworld,\"\"\n", "hello,\r\n\r\nworld,\"\"" };
-345         final String[][] res = { { "hello", "" }, { "" }, // Excel format does not ignore empty lines
-346                 { "world", "" } };
-347 
-348         for (final String code : codes) {
-349             final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL);
-350             final List<CSVRecord> records = parser.getRecords();
-351             assertEquals(res.length, records.size());
-352             assertTrue(records.size() > 0);
-353             for (int i = 0; i < res.length; i++) {
-354                 assertArrayEquals(res[i], records.get(i).values());
-355             }
-356             parser.close();
-357         }
-358     }
-359 
-360     @Test
-361     public void testExcelFormat1() throws IOException {
-362         final String code = "value1,value2,value3,value4\r\na,b,c,d\r\n  x,,,"
-363                 + "\r\n\r\n\"\"\"hello\"\"\",\"  \"\"world\"\"\",\"abc\ndef\",\r\n";
-364         final String[][] res = { { "value1", "value2", "value3", "value4" }, { "a", "b", "c", "d" },
-365                 { "  x", "", "", "" }, { "" }, { "\"hello\"", "  \"world\"", "abc\ndef", "" } };
-366         final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL);
-367         final List<CSVRecord> records = parser.getRecords();
-368         assertEquals(res.length, records.size());
-369         assertTrue(records.size() > 0);
-370         for (int i = 0; i < res.length; i++) {
-371             assertArrayEquals(res[i], records.get(i).values());
-372         }
-373         parser.close();
-374     }
-375 
-376     @Test
-377     public void testExcelFormat2() throws Exception {
-378         final String code = "foo,baar\r\n\r\nhello,\r\n\r\nworld,\r\n";
-379         final String[][] res = { { "foo", "baar" }, { "" }, { "hello", "" }, { "" }, { "world", "" } };
-380         final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL);
-381         final List<CSVRecord> records = parser.getRecords();
-382         assertEquals(res.length, records.size());
-383         assertTrue(records.size() > 0);
-384         for (int i = 0; i < res.length; i++) {
-385             assertArrayEquals(res[i], records.get(i).values());
-386         }
-387         parser.close();
-388     }
-389 
-390     /**
-391      * Tests an exported Excel worksheet with a header row and rows that have more columns than the headers
-392      */
-393     @Test
-394     public void testExcelHeaderCountLessThanData() throws Exception {
-395         final String code = "A,B,C,,\r\na,b,c,d,e\r\n";
-396         final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL.withHeader());
-397         try {
-398             for (CSVRecord record : parser.getRecords()) {
-399                 Assert.assertEquals("a", record.get("A"));
-400                 Assert.assertEquals("b", record.get("B"));
-401                 Assert.assertEquals("c", record.get("C"));
-402             }
-403         } finally {
-404             parser.close();
-405         }
-406     }
-407 
-408     @Test
-409     public void testForEach() throws Exception {
-410         final List<CSVRecord> records = new ArrayList<CSVRecord>();
-411 
-412         final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
-413 
-414         for (final CSVRecord record : CSVFormat.DEFAULT.parse(in)) {
-415             records.add(record);
-416         }
-417 
-418         assertEquals(3, records.size());
-419         assertArrayEquals(new String[] { "a", "b", "c" }, records.get(0).values());
-420         assertArrayEquals(new String[] { "1", "2", "3" }, records.get(1).values());
-421         assertArrayEquals(new String[] { "x", "y", "z" }, records.get(2).values());
-422     }
-423 
-424     @Test
-425     public void testGetHeaderMap() throws Exception {
-426         final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader("A", "B", "C"));
-427         final Map<String, Integer> headerMap = parser.getHeaderMap();
-428         final Iterator<String> columnNames = headerMap.keySet().iterator();
-429         // Headers are iterated in column order.
-430         Assert.assertEquals("A", columnNames.next());
-431         Assert.assertEquals("B", columnNames.next());
-432         Assert.assertEquals("C", columnNames.next());
-433         final Iterator<CSVRecord> records = parser.iterator();
-434 
-435         // Parse to make sure getHeaderMap did not have a side-effect.
-436         for (int i = 0; i < 3; i++) {
-437             assertTrue(records.hasNext());
-438             final CSVRecord record = records.next();
-439             assertEquals(record.get(0), record.get("A"));
-440             assertEquals(record.get(1), record.get("B"));
-441             assertEquals(record.get(2), record.get("C"));
-442         }
-443 
-444         assertFalse(records.hasNext());
-445         parser.close();
-446     }
-447 
-448     @Test(expected = IllegalArgumentException.class)
-449     public void testDuplicateHeaders() throws Exception {
-450         CSVParser.parse("a,b,a\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader(new String[] {}));
-451     }
-452 
-453     @Test
-454     public void testGetLine() throws IOException {
-455         final CSVParser parser = CSVParser.parse(CSV_INPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces());
-456         for (final String[] re : RESULT) {
-457             assertArrayEquals(re, parser.nextRecord().values());
-458         }
-459 
-460         assertNull(parser.nextRecord());
-461         parser.close();
-462     }
-463 
-464     @Test
-465     public void testGetLineNumberWithCR() throws Exception {
-466         this.validateLineNumbers(String.valueOf(CR));
-467     }
-468 
-469     @Test
-470     public void testGetLineNumberWithCRLF() throws Exception {
-471         this.validateLineNumbers(CRLF);
-472     }
-473 
-474     @Test
-475     public void testGetLineNumberWithLF() throws Exception {
-476         this.validateLineNumbers(String.valueOf(LF));
-477     }
-478 
-479     @Test
-480     public void testGetRecordPositionWithCRLF() throws Exception {
-481         this.validateRecordPosition(CRLF);
-482     }
-483 
-484     @Test
-485     public void testGetRecordPositionWithLF() throws Exception {
-486         this.validateRecordPosition(String.valueOf(LF));
-487     }
-488 
-489     @Test
-490     public void testGetOneLine() throws IOException {
-491         final CSVParser parser = CSVParser.parse(CSV_INPUT_1, CSVFormat.DEFAULT);
-492         final CSVRecord record = parser.getRecords().get(0);
-493         assertArrayEquals(RESULT[0], record.values());
-494         parser.close();
-495     }
-496 
-497     /**
-498      * Tests reusing a parser to process new string records one at a time as they are being discovered. See [CSV-110].
-499      *
-500      * @throws IOException
-501      */
-502     @Test
-503     public void testGetOneLineOneParser() throws IOException {
-504         final PipedWriter writer = new PipedWriter();
-505         final PipedReader reader = new PipedReader(writer);
-506         final CSVFormat format = CSVFormat.DEFAULT;
-507         final CSVParser parser = new CSVParser(reader, format);
-508         try {
-509             writer.append(CSV_INPUT_1);
-510             writer.append(format.getRecordSeparator());
-511             final CSVRecord record1 = parser.nextRecord();
-512             assertArrayEquals(RESULT[0], record1.values());
-513             writer.append(CSV_INPUT_2);
-514             writer.append(format.getRecordSeparator());
-515             final CSVRecord record2 = parser.nextRecord();
-516             assertArrayEquals(RESULT[1], record2.values());
-517         } finally {
-518             parser.close();
-519         }
-520     }
-521 
-522     @Test
-523     public void testGetRecordNumberWithCR() throws Exception {
-524         this.validateRecordNumbers(String.valueOf(CR));
-525     }
-526 
-527     @Test
-528     public void testGetRecordNumberWithCRLF() throws Exception {
-529         this.validateRecordNumbers(CRLF);
-530     }
-531 
-532     @Test
-533     public void testGetRecordNumberWithLF() throws Exception {
-534         this.validateRecordNumbers(String.valueOf(LF));
-535     }
-536 
-537     @Test
-538     public void testGetRecords() throws IOException {
-539         final CSVParser parser = CSVParser.parse(CSV_INPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces());
-540         final List<CSVRecord> records = parser.getRecords();
-541         assertEquals(RESULT.length, records.size());
-542         assertTrue(records.size() > 0);
-543         for (int i = 0; i < RESULT.length; i++) {
-544             assertArrayEquals(RESULT[i], records.get(i).values());
-545         }
-546         parser.close();
-547     }
-548 
-549     @Test
-550     public void testGetRecordWithMultiLineValues() throws Exception {
-551         final CSVParser parser = CSVParser.parse("\"a\r\n1\",\"a\r\n2\"" + CRLF + "\"b\r\n1\",\"b\r\n2\"" + CRLF +
-552                 "\"c\r\n1\",\"c\r\n2\"", CSVFormat.DEFAULT.withRecordSeparator(CRLF));
-553         CSVRecord record;
-554         assertEquals(0, parser.getRecordNumber());
-555         assertEquals(0, parser.getCurrentLineNumber());
-556         assertNotNull(record = parser.nextRecord());
-557         assertEquals(3, parser.getCurrentLineNumber());
-558         assertEquals(1, record.getRecordNumber());
-559         assertEquals(1, parser.getRecordNumber());
-560         assertNotNull(record = parser.nextRecord());
-561         assertEquals(6, parser.getCurrentLineNumber());
-562         assertEquals(2, record.getRecordNumber());
-563         assertEquals(2, parser.getRecordNumber());
-564         assertNotNull(record = parser.nextRecord());
-565         assertEquals(8, parser.getCurrentLineNumber());
-566         assertEquals(3, record.getRecordNumber());
-567         assertEquals(3, parser.getRecordNumber());
-568         assertNull(record = parser.nextRecord());
-569         assertEquals(8, parser.getCurrentLineNumber());
-570         assertEquals(3, parser.getRecordNumber());
-571         parser.close();
-572     }
-573 
-574     @Test
-575     public void testHeader() throws Exception {
-576         final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
-577 
-578         final Iterator<CSVRecord> records = CSVFormat.DEFAULT.withHeader().parse(in).iterator();
-579 
-580         for (int i = 0; i < 2; i++) {
-581             assertTrue(records.hasNext());
-582             final CSVRecord record = records.next();
-583             assertEquals(record.get(0), record.get("a"));
-584             assertEquals(record.get(1), record.get("b"));
-585             assertEquals(record.get(2), record.get("c"));
-586         }
-587 
-588         assertFalse(records.hasNext());
-589     }
-590 
-591     @Test
-592     public void testHeaderMissing() throws Exception {
-593         final Reader in = new StringReader("a,,c\n1,2,3\nx,y,z");
-594 
-595         final Iterator<CSVRecord> records = CSVFormat.DEFAULT.withHeader().parse(in).iterator();
-596 
-597         for (int i = 0; i < 2; i++) {
-598             assertTrue(records.hasNext());
-599             final CSVRecord record = records.next();
-600             assertEquals(record.get(0), record.get("a"));
-601             assertEquals(record.get(2), record.get("c"));
-602         }
-603 
-604         assertFalse(records.hasNext());
-605     }
-606 
-607     @Test(expected = IllegalArgumentException.class)
-608     public void testHeadersMissingException() throws Exception {
-609         final Reader in = new StringReader("a,,c,,d\n1,2,3,4\nx,y,z,zz");
-610         CSVFormat.DEFAULT.withHeader().parse(in).iterator();
-611     }
-612 
-613     @Test
-614     public void testHeadersMissing() throws Exception {
-615         final Reader in = new StringReader("a,,c,,d\n1,2,3,4\nx,y,z,zz");
-616         CSVFormat.DEFAULT.withHeader().withAllowMissingColumnNames().parse(in).iterator();
-617     }
-618 
-619     @Test
-620     public void testHeaderMissingWithNull() throws Exception {
-621         final Reader in = new StringReader("a,,c,,d\n1,2,3,4\nx,y,z,zz");
-622         CSVFormat.DEFAULT.withHeader().withNullString("").withAllowMissingColumnNames().parse(in).iterator();
-623     }
-624 
-625     @Test
-626     public void testHeaderComment() throws Exception {
-627         final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");
-628 
-629         final Iterator<CSVRecord> records = CSVFormat.DEFAULT.withCommentMarker('#').withHeader().parse(in).iterator();
-630 
-631         for (int i = 0; i < 2; i++) {
-632             assertTrue(records.hasNext());
-633             final CSVRecord record = records.next();
-634             assertEquals(record.get(0), record.get("a"));
-635             assertEquals(record.get(1), record.get("b"));
-636             assertEquals(record.get(2), record.get("c"));
-637         }

[... 1335 lines stripped ...]