//-------------------------------------------------------------------------
 public virtual void test_of_ioException()
 {
     assertThrows(() => CsvFile.of(Files.asCharSource(new File("src/test/resources"), StandardCharsets.UTF_8), false), typeof(UncheckedIOException));
 }
 public virtual void test_of_empty_with_header()
 {
     assertThrowsIllegalArg(() => CsvFile.of(CharSource.wrap(""), true));
 }
        public virtual void test_of_simple_with_header()
        {
            CsvFile csvFile = CsvFile.of(CharSource.wrap(CSV1), true);

            assertEquals(csvFile.containsHeader("Foo"), false);
            assertEquals(csvFile.containsHeader("h1"), true);
            assertEquals(csvFile.containsHeader(Pattern.compile("Foo")), false);
            assertEquals(csvFile.containsHeader(Pattern.compile("h[0-9]")), true);
            ImmutableList <string> headers = csvFile.headers();

            assertEquals(headers.size(), 2);
            assertEquals(headers.get(0), "h1");
            assertEquals(headers.get(1), "h2");
            assertEquals(csvFile.rowCount(), 3);
            assertEquals(csvFile.row(0).lineNumber(), 2);
            assertEquals(csvFile.row(1).lineNumber(), 3);
            assertEquals(csvFile.row(2).lineNumber(), 4);

            assertEquals(csvFile.row(0).headers(), headers);
            assertEquals(csvFile.row(0).fieldCount(), 2);
            assertEquals(csvFile.row(0).field(0), "r11");
            assertEquals(csvFile.row(0).field(1), "r12");
            assertEquals(csvFile.row(1).headers(), headers);
            assertEquals(csvFile.row(1).fieldCount(), 2);
            assertEquals(csvFile.row(1).field(0), "r21");
            assertEquals(csvFile.row(1).field(1), "r22");

            assertEquals(csvFile.row(0).getField("h1"), "r11");
            assertEquals(csvFile.row(0).getField("h2"), "r12");
            assertEquals(csvFile.row(1).getField("h1"), "r21");
            assertEquals(csvFile.row(1).getField("h2"), "r22");
            assertThrowsIllegalArg(() => csvFile.row(0).getField("zzz"));

            assertEquals(csvFile.row(0).getValue("h1"), "r11");
            assertEquals(csvFile.row(0).getValue("h2"), "r12");
            assertEquals(csvFile.row(1).getValue("h1"), "r21");
            assertEquals(csvFile.row(1).getValue("h2"), "r22");
            assertThrowsIllegalArg(() => csvFile.row(0).getValue("zzz"));
            assertThrowsIllegalArg(() => csvFile.row(2).getValue("h2"));

            assertEquals(csvFile.row(0).findField("h1"), ("r11"));
            assertEquals(csvFile.row(0).findField("h2"), ("r12"));
            assertEquals(csvFile.row(1).findField("h1"), ("r21"));
            assertEquals(csvFile.row(1).findField("h2"), ("r22"));
            assertEquals(csvFile.row(0).findField("zzz"), null);

            assertEquals(csvFile.row(0).findValue("h1"), ("r11"));
            assertEquals(csvFile.row(0).findValue("h2"), ("r12"));
            assertEquals(csvFile.row(1).findValue("h1"), ("r21"));
            assertEquals(csvFile.row(1).findValue("h2"), ("r22"));
            assertEquals(csvFile.row(0).findValue("zzz"), null);
            assertEquals(csvFile.row(2).findValue("h2"), null);

            assertEquals(csvFile.row(0).getField(Pattern.compile("h[13]")), "r11");
            assertEquals(csvFile.row(0).getField(Pattern.compile("h[24]")), "r12");
            assertThrowsIllegalArg(() => csvFile.row(0).getField(Pattern.compile("zzz")));

            assertEquals(csvFile.row(0).getValue(Pattern.compile("h[13]")), "r11");
            assertEquals(csvFile.row(0).getValue(Pattern.compile("h[24]")), "r12");
            assertThrowsIllegalArg(() => csvFile.row(0).getValue(Pattern.compile("zzz")));
            assertThrowsIllegalArg(() => csvFile.row(2).getValue(Pattern.compile("h2")));

            assertEquals(csvFile.row(0).findField(Pattern.compile("h[13]")), ("r11"));
            assertEquals(csvFile.row(0).findField(Pattern.compile("h[24]")), ("r12"));
            assertEquals(csvFile.row(0).findField(Pattern.compile("zzz")), null);

            assertEquals(csvFile.row(0).findValue(Pattern.compile("h[13]")), ("r11"));
            assertEquals(csvFile.row(0).findValue(Pattern.compile("h[24]")), ("r12"));
            assertEquals(csvFile.row(0).findValue(Pattern.compile("zzz")), null);
            assertEquals(csvFile.row(2).findValue(Pattern.compile("h2")), null);

            assertEquals(csvFile.row(0).subRow(0).fieldCount(), 2);
            assertEquals(csvFile.row(0).subRow(1).fieldCount(), 1);
            assertEquals(csvFile.row(0).subRow(2).fieldCount(), 0);

            assertEquals(csvFile.row(0).subRow(0, 0).fieldCount(), 0);
            assertEquals(csvFile.row(0).subRow(0, 1).fieldCount(), 1);
            assertEquals(csvFile.row(0).subRow(2, 2).fieldCount(), 0);
        }