A CSV parsing library in Zig.

Acceptance-criterion coverage matrix #

This file maps every numbered requirement in requirements.md to the test(s) that exercise it. Generated as part of Task 21.

All test names below are exact test "<name>" strings; grep the source tree to locate them.

Stories — acceptance criteria #

Story 1 — FieldIterator (streaming, no allocation) #

# Criterion Test(s)
1 No heap allocation All FieldIterator tests pass without an allocator parameter. Construction signature init(reader, field_buf, dialect) enforces this.
2 Returns field / sentinel / error Covered by every expectFields and expectParseError call.
3 Borrowed-slice lifetime documented Result.data doc comment + verified by parseAll test helper that dupes on each iteration.
4 FieldTooLong on buffer overflow FieldIterator: field one byte too large => FieldTooLong; FieldIterator: FieldTooLong inside quoted field
5 No @panic / unreachable reached on bad input Verified manually (Task 22) and by sticky-error test

Story 2 — Row iterators (streaming) #

# Criterion Test(s)
1 No heap allocation (for Bounded / FixedBuffer) BoundedRowIterator/FixedBufferRowIterator tests use no allocator parameter
2 Yields row / sentinel / error All row iterators: ... shared-corpus tests
3 RowTooWide on overflow BoundedRowIterator(4) returns RowTooWide on a 5-field row; FixedBufferRowIterator returns RowTooWide when row_buf overflows
4 Lifetime documented Row.fields doc comment; verified by collect test helper that copies each cell

Story 3 — HeaderIterator #

# Criterion Test(s)
1 Consumes first row as headers; retains copies HeaderIterator: captures header row and yields data rows
2 Allocator only for header storage Inspection: init uses allocator only for dupe calls and the wrapped RowIterator's row-slot list
3 Row supports positional + name lookup captures header row..., HeaderRow.at exercised throughout
4 get(name) returns matching field captures header row and yields data rows
5 Unknown name returns null HeaderIterator: get returns null for unknown header name
6 Short row returns null for missing column HeaderIterator: get returns null when row is shorter than header column
7 Duplicate headers → first-wins HeaderIterator: duplicate headers resolve first-wins
8 deinit releases bytes HeaderIterator: deinit releases header copies (testing.allocator leak check)
9 strict_width option HeaderIterator: strict_width=false accepts ragged rows; HeaderIterator: strict_width=true returns RowWidthMismatch (sticky)

Story 4 — Table #

# Criterion Test(s)
1 parse returns owned 2-D + deinit Table: round-trip a simple CSV
2 deinit frees everything All Table: tests use testing.allocator; leaks would fail
3 Mid-parse error leaves no leaks Table: mid-parse error leaks nothing (UnterminatedQuotedField); Table: mid-parse error from invalid dialect
4 Empty input → 0 rows Table: empty input yields zero rows

Story 5 — HeaderTable #

# Criterion Test(s)
1 Header row + data rows owned HeaderTable: happy path with columnIndex and get
2 columnIndex for known / unknown Same test
3 get(row, name) returns cell or null Same test
4 DuplicatePolicy 3 variants HeaderTable: DuplicatePolicy.err..., ...first_wins..., ...last_wins...
5 Default duplicate policy = strict (err) DuplicatePolicy.err test omits on_duplicate; default is checked by the type's declaration
6 WidthPolicy 2 variants HeaderTable: WidthPolicy.permissive...; ...strict returns RowWidthMismatch...
7 Default width policy = permissive WidthPolicy.permissive test omits width; default checked by type declaration

Story 6 — Dialect #

# Criterion Test(s)
1 Delimiter and quote honoured FieldIterator: tab dialect, semicolon dialect, alternative quote character (apostrophe)
2 Default behaves per RFC 4180 Every test using .{} dialect
3 Single-byte structural chars Enforced by Dialect's u8 field types
4 Same delimiter & quote → InvalidDialect at init Dialect: delimiter == quote_char rejected; FieldIterator: invalid dialect rejected by init
5 BOM stripping when enabled FieldIterator: BOM stripping on (default) consumes leading BOM

Parsing-correctness requirements #

# Requirement Test(s)
1 RFC 4180 inputs accepted Most FieldIterator: tests use RFC 4180 inputs
2 \n and \r\n as row terminators two-row CSV with LF terminators; two-row CSV with CRLF terminators
3 Bare \r as row terminator FieldIterator: bare CR is a row terminator (correctness #3); FieldIterator: mixed line endings
4 Quoted field preserves structurals quoted field with embedded delimiter, embedded LF, embedded CR and CRLF
5 Doubled quote collapses to literal quote doubled quote inside quoted field is literal quote (correctness #5)
6 Empty vs missing fields trailing delimiter produces empty trailing field (correctness #6); line of N delimiters produces N+1 empty fields (correctness #6)
7 Empty input → 0 rows empty input yields zero rows (correctness #7)
8 Lone LF/CR/CRLF → 1 empty row lone LF/CR/CRLF yields one empty field (correctness #8)
9 Trailing newline ignored trailing newline does not produce phantom row (correctness #9)
10 No silent byte discard Implicit: every byte either lands in a field, is structural punctuation, or surfaces an error (UnexpectedQuote/UnexpectedByteAfterQuote/UnterminatedQuotedField cover the error branches; all other tests verify content preservation)
11 UnexpectedQuote quote in middle of unquoted field => UnexpectedQuote (correctness #11)
12 UnexpectedByteAfterQuote trailing byte after closing quote => UnexpectedByteAfterQuote (correctness #12)
13 UnterminatedQuotedField unterminated quoted field => UnterminatedQuotedField (correctness #13)
14 Sticky failure FieldIterator: malformed-input error is sticky (correctness #14); also HeaderIterator: strict_width=true returns RowWidthMismatch (sticky)
15 Ragged rows accepted by default row iterators: ragged rows are accepted; Table: ragged rows are preserved; HeaderTable: WidthPolicy.permissive (default) accepts ragged rows
16 RowWidthMismatch under strict HeaderIterator: strict_width=true...; HeaderTable: WidthPolicy.strict returns RowWidthMismatch on ragged row
17 UTF-8 transparency FieldIterator: UTF-8 multibyte content passes through unmodified (correctness #17); ...inside quoted field passes through...
18 No Unicode dependencies Inspection: no std.unicode / std.ascii casefolding imports
19 BOM stripping default on, optional off BOM stripping on (default)...; BOM stripping off preserves BOM...; BOM-only input yields zero rows; shorter-than-BOM input...

Non-functional requirements #

# Requirement Verification
N-1 Streaming peak memory O(largest field) Architectural: FieldIterator accumulates one row's worth of bytes into field_buf between resetBuffer() calls; streaming row iterators call resetBuffer() between rows. (Note: actual bound is O(largest row), not O(largest field), because all of a row's fields coexist in the buffer at once. This is a small relaxation of N-1 chosen for API ergonomics.)
N-2 No undisclosed allocator use All allocating tests use std.testing.allocator; unexpected allocations would either fail (no allocator) or leak (caught by leak checker)
N-3 Field buffer caller-controlled; overflow → recoverable error FieldTooLong tests
N-4 No @panic etc. on caller-attributable conditions Task 22 manual review
N-5 Unified Error set src/error.zig declares one set; every parser function returns Error!T
N-6 Error includes all listed variants Inspection of src/error.zig
N-7 No super-linear time Inspection: every state-machine transition consumes a bounded number of bytes
N-8 Avoid per-byte call overhead Deferred (Task 4 optional, not executed)
N-9 Zig 0.16+, no external deps build.zig.zon has no dependencies; tested with Zig 0.16.0
N-10 zig build test runs everything root.zig test block pulls in all submodules; verified by zig build test --summary all showing 84 tests
N-11 Doc comments on every pub decl Task 19
N-12 One example per parser tier Task 20: six test "example: ..." blocks in root.zig
N-13 One passing test per acceptance criterion This document
N-14 Specific coverage list All items in N-14 are present in the matrix above
N-15 Fuzz/golden/throughput out of scope Not implemented