Skip to main content

Crate csv_spectrum

Crate csv_spectrum 

Source
Expand description

CSV parser conformance test corpus.

This crate ships a fixed set of CSV files that exercise the tricky parts of CSV parsing, each paired with the JSON its parse result should equal. Feed every Sample::csv to your parser and assert the output matches Sample::json, except for location_coordinates, whose masked phone field and lone-object JSON cannot equal a correct parse. The crate parses nothing itself. It hands you the raw bytes.

The corpus covers quoting, commas inside quoted fields, escaped (doubled) quotes, embedded LF and CRLF inside fields, empty quoted fields, multibyte UTF-8, UTF-8 replacement bytes, and a JSON document stored in one cell.

§Bytes, not strings

Sample::csv and Sample::json are &[u8]. The bytes are returned exactly as stored. CRLF stays CRLF. The 0xEF 0xBF 0xBD replacement sequences in location_coordinates stay put. Trailing newlines are kept or omitted per file. No decoding, no normalization, no trimming.

§Example

let samples = csv_spectrum::spectrum();
assert_eq!(samples.len(), 12);
assert_eq!(samples[0].name, "comma_in_quotes");

// The first sample's quoted field holds a comma that must not split.
let csv = std::str::from_utf8(samples[0].csv).unwrap();
assert!(csv.contains("\"Anytown, WW\""));

Structs§

Sample
One corpus entry: a CSV input and the JSON its parse result should equal.

Constants§

SAMPLES
Every sample, in ascending order by name.

Functions§

spectrum
Returns all 12 samples, in ascending order by name.