Skip to content

feat: expand CSV reader/writer with config, delimiters, and tests#41

Merged
alvinreal merged 1 commit intomainfrom
fix/issue-11
Feb 21, 2026
Merged

feat: expand CSV reader/writer with config, delimiters, and tests#41
alvinreal merged 1 commit intomainfrom
fix/issue-11

Conversation

@alvinreal
Copy link
Owner

Summary

Closes #11 — CSV reader/writer.

Changes

New functionality:

  • CsvConfig struct: Configurable has_headers, delimiter, and flexible options
  • from_str_with_config() / from_reader_with_config(): Parse CSV with custom settings
  • to_string_with_config(): Serialize with custom delimiter and header options
  • No-header mode: Returns array of arrays instead of array of maps
  • Custom delimiters: Tab (TSV), pipe, semicolon, etc.
  • Flexible/ragged rows: Extra columns get auto-named (column_N), short rows have missing keys
  • Union headers: When serializing, all keys from all rows become columns
  • Array-of-arrays output: Write raw arrays without headers

New tests (45+):

  • Basic CSV parsing (single/multi row, many columns)
  • No-header mode (array of arrays)
  • Custom delimiters: TSV, pipe, semicolon (with roundtrip)
  • Quoted fields: commas, embedded quotes, newlines (with roundtrip)
  • Type inference: ints, floats, bools, negatives
  • Empty fields and all-empty rows
  • Cross-format roundtrips: CSV↔JSON (both directions)
  • Large CSV: 1000 rows
  • Unicode: Japanese headers/values, emoji roundtrip
  • Ragged rows: strict error + flexible mode
  • Union headers from heterogeneous rows
  • Error cases: non-array input, scalar input
  • Empty input/output edge cases
  • from_reader with default and custom config
  • Null serialization (empty field)
  • Bool roundtrip
  • Header order preservation
  • Whitespace in quoted fields
  • Array-of-arrays output and no-header roundtrip

All checks pass: cargo build, cargo test (246 tests), cargo fmt --check, cargo clippy -D warnings.

- Add CsvConfig struct for customizable headers, delimiter, and flexibility
- Add from_str_with_config() and from_reader_with_config() for custom parsing
- Add to_string_with_config() for custom serialization
- Support no-header mode (array of arrays)
- Support custom delimiters (tab, pipe, semicolon, etc.)
- Support flexible/ragged rows with extra column mapping
- Union headers from all rows when serializing
- Support writing array-of-arrays without headers
- Add 45+ tests covering: basic CSV, no-header mode, TSV/pipe/semicolon
  delimiters, quoted fields (commas/quotes/newlines), type inference,
  empty fields, cross-format roundtrips (CSV↔JSON), large CSV (1000 rows),
  unicode headers/values, ragged rows (strict + flexible), union headers,
  null serialization, bool roundtrip, header order, whitespace handling,
  array-of-arrays output, and no-header roundtrip

Fixes #11
@alvinreal alvinreal merged commit a005106 into main Feb 21, 2026
6 checks passed
@alvinreal alvinreal deleted the fix/issue-11 branch February 21, 2026 05:57
@github-actions github-actions bot mentioned this pull request Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSV reader/writer

1 participant