tabnas-support (Rust)
Shared test-support utilities for the tabnas
parser system: the TSV spec-fixture loader, the escape codec, the
expectation helpers, the cross-runtime test runner, the divergence
register and the error-code census. Crate tabnas-support, library
tabnas_support.
This is the Rust half. The canonical TypeScript half is
@tabnas/support, the Go half is
github.com/tabnas/support/go, and the three are written to
behave identically: same escape codec, same comment and blank-line
handling, same ERROR:<code> contract, same value comparison. That is
the point. Every tabnas package proves its runtimes agree by running
one set of TSV fixtures in all of them, and a loader that
disagreed with its twins would make those fixtures prove nothing.
This crate has no required dependencies, and never will. Every tabnas
Rust crate takes it as a dev-dependency, so anything it required would
land in all of them, the engine it is used to test included. The JSON it
reads and writes is handled in the crate. The adder grammar that
exercises it end to end therefore lives in the separate
adder crate, which may depend on the engine.
Use
use Path;
use ;
let dir = find_spec_dir.unwrap;
let parser = make;
new
.dir;
find_spec_dir walks up from where it is told to start until it finds a
test/spec directory. Runner::dir runs every .tsv in the named
directory and panics with every failing row at once, each line carrying
the fixture's own file name and line number.
The parse hook returns a Value (the fixture data model: JSON plus
Undefined, and numbers that may be infinite) or a Failure carrying
the error code the fixture pins and, when the error reports one, its
position. The serde_json feature adds From<serde_json::Value>, which
is what the engine's Value::to_json produces.
Install
The crate is not on crates.io. Take it as a path dependency on a sibling checkout, the standard tabnas development model:
[]
= { = "../../support/rs", = ["serde_json"] }
A dev-dependency never reaches a release artifact, which is the same
guarantee devDependencies gives the TypeScript half.
What is in it
- The escape codec.
unescapeandescape:\n,\r,\tand\\decoded; every other backslash sequence passed through untouched. - The fixture loader.
parse_spec,load_spec,load_spec_dir,find_spec_dir,SpecFile,Row,SpecOptions,Column. Header row, blank lines,#comment lines, CRLF, BOM, raw columns with explicit per-column decoding, physical line numbers, directory discovery. - The expectation helpers.
is_error_expect,error_code,error_expect,parse_expect,equal_value,equal_value_with,format_value,lone_surrogate_at,lone_surrogate_message, and theValuetype they work on. - The runner.
Runner,Failure,report. - The divergence register.
Registerandno_divergences. - The census.
codes_in_spec_dir,compare_catalogues,coverage.
Differences from the TypeScript and Go halves
The behaviour is the same; the shape differs where the language does.
- Failures are one report, not subtests. Rust's test harness has no
subtests, so a fixture's failing rows are collected and reported at
once, each prefixed
<file>:<line>. Therun_spec,run_fileandrun_dirmethods return the failures for a suite that reports its own way;spec,fileanddirpanic with them. - The parse hook returns a
Failure. This crate cannot name the engine's error type, so the suite converts at the boundary. That struct already carries the code and the position, so theerrorCodeanderrorPoshooks of the other halves do not exist here. Undefinedis aValuevariant. An empty expected cell reads asValue::Undefined, distinct fromValue::Nullas in TypeScript. Go cannot tell the two apart.resolvetakes aColumn. A position or a name, as an enum, where TypeScript takesnumber | string.- A lone
\uXXXXsurrogate in a cell decodes to U+FFFD, as in Go. The runner refuses such a cell in a shared expected column before it is compared, in every runtime. - Errors are values. Every fallible function returns
Result<_, tabnas_support::Error>, the Rust convention, with the same message text the other halves raise.
Build and test
The suite runs the shared ../test/spec/util, census and register
fixtures, the same files the TypeScript and Go suites run, plus the
crate's own failure-behaviour tests. register/divergent.tsv carries an
rs column alongside ts and go, and this suite reads it, so the
crate is a runtime of that register rather than a reader of someone
else's. The adder crate runs ../test/spec/adder through a
real grammar and needs a sibling checkout of tabnas/parser. From the
repository root, make test-rs runs both, and ci/rust/run.sh is the
full gate.
Hosted CI runs ci/rust/run.sh through
rust.yml, on a change under rs/,
the shared fixtures, ci/rust/ or ts/package.json, with
tabnas/parser main cloned beside this repository.
License
MIT.