public virtual void test_of_simple_with_header() { using (CsvIterator csvFile = CsvIterator.of(CharSource.wrap(CSV1), true)) { ImmutableList <string> headers = csvFile.headers(); assertEquals(headers.size(), 2); assertEquals(csvFile.containsHeader("h1"), true); assertEquals(csvFile.containsHeader("h2"), true); assertEquals(csvFile.containsHeader("a"), false); assertEquals(csvFile.containsHeader(Pattern.compile("h.")), true); assertEquals(csvFile.containsHeader(Pattern.compile("a")), false); assertEquals(headers.get(0), "h1"); assertEquals(headers.get(1), "h2"); CsvRow peeked = csvFile.peek(); CsvRow row0 = csvFile.next(); assertEquals(row0, peeked); assertEquals(row0.headers(), headers); assertEquals(row0.lineNumber(), 2); assertEquals(row0.fieldCount(), 2); assertEquals(row0.field(0), "r11"); assertEquals(row0.field(1), "r12"); CsvRow row1 = csvFile.next(); assertEquals(row1.headers(), headers); assertEquals(row1.lineNumber(), 3); assertEquals(row1.fieldCount(), 2); assertEquals(row1.field(0), "r21"); assertEquals(row1.field(1), "r22"); assertEquals(csvFile.hasNext(), false); assertThrows(() => csvFile.peek(), typeof(NoSuchElementException)); assertThrows(() => csvFile.peek(), typeof(NoSuchElementException)); assertThrows(() => csvFile.next(), typeof(NoSuchElementException)); assertThrows(() => csvFile.next(), typeof(NoSuchElementException)); assertThrows(() => csvFile.remove(), typeof(System.NotSupportedException)); } }
public virtual void test_of_empty_no_header() { using (CsvIterator csvFile = CsvIterator.of(CharSource.wrap(""), false)) { assertEquals(csvFile.headers().size(), 0); assertEquals(csvFile.containsHeader("a"), false); assertEquals(csvFile.hasNext(), false); assertEquals(csvFile.hasNext(), false); assertThrows(() => csvFile.peek(), typeof(NoSuchElementException)); assertThrows(() => csvFile.next(), typeof(NoSuchElementException)); assertThrows(() => csvFile.next(), typeof(NoSuchElementException)); assertThrows(() => csvFile.remove(), typeof(System.NotSupportedException)); } }