Skip to main content

Crate tabnas_support

Crate tabnas_support 

Source
Expand description

Shared test-support utilities for the tabnas parser system.

Every tabnas package ships a canonical TypeScript implementation and ports of it, and proves they agree by running one set of TSV fixtures from test/spec/ in every runtime. This crate is the machinery that reads those fixtures in Rust, so there is one loader with one set of rules instead of a copy per repository quietly drifting from its TypeScript and Go twins.

The TypeScript half is @tabnas/support and the Go half is github.com/tabnas/support/go. The three are written to behave identically: same escape codec, same comment and blank-line handling, same ERROR:<code> contract, same value comparison. Where a difference is unavoidable it is documented at the point it appears, and collected in doc/reference.md.

A typical suite is a few lines:

use tabnas_support::{find_spec_dir, Failure, Runner, Value};

let dir = find_spec_dir(None).expect("a test/spec directory above the crate");
Runner::new(|input| {
    // Parse with your grammar, then hand back a `Value` or a `Failure`
    // carrying the error code the fixture pins.
    let _ = input;
    Err(Failure::new("unexpected"))
})
.dir(dir.join("happy"));

This crate has no required dependencies, and never will: every tabnas Rust crate would take it as a dev-dependency, so anything it required would land in all of them. The adder grammar that exercises it end to end therefore lives in the separate adder/ crate, which may depend on the engine.

Structs§

CatalogueDiff
What compare_catalogues found. All three lists are sorted.
CensusOptions
Which column holds the expectation. The default is each row’s last column (the ordinary two-column input/expected fixture needs no selection at all), but a wider fixture can keep the expectation anywhere, which is why the selection exists.
CoverageReport
What coverage found. Both lists are sorted.
Error
A defect in a fixture, a suite or a runner: an unreadable file, a malformed expectation, a runner built without a parser. Carries the same sentence the TypeScript and Go halves raise for the same condition, so a failure reads the same whichever runtime reported it.
ErrorExpect
An error expectation, split into the parts a runner checks separately.
Failure
A parse that failed, as the runner sees it: the code the fixture pins, the position it may pin, and the message a failure report quotes.
Register
A fixture of recorded divergences, run by every port.
Row
One data row of a fixture file.
Runner
Drives fixture rows through one parser. Reuse it across files.
SpecFile
A loaded fixture file.
SpecOptions
How to interpret a fixture file. The defaults are the tabnas convention; override them only for a fixture that genuinely differs.

Enums§

Column
A column selector: a position, or a header name.
Value
A parsed value in the fixture data model. See the module notes.

Constants§

ERROR_PREFIX
The prefix marking an expected-failure cell.
VERSION
The release version, kept in step with ts/package.json. See tests/version_test.rs, which fails the build when they drift.

Functions§

codes_in_spec_dir
Collect every code named by a code-style expectation cell under a fixture directory: sorted, unique. Message-style expectations and bare ERROR cells assert a rejection without naming a code, so they are not collected; a value row is not an expectation at all.
compare_catalogues
Diff two {code: template} catalogues: message catalogues, hint catalogues, or one runtime’s against the other’s. Templates compare byte for byte: two templates that merely “mean the same” have still drifted, and the byte diff is what a maintainer has to reconcile.
coverage
Compare the codes a package declares against the codes its fixtures exercise (typically codes_in_spec_dir’s answer). Whether inherited base codes count as declared is the caller’s choice: pass them in or leave them out.
equal_value
Compare a parse result against an expected value with JSON semantics: structural, key-order independent, NaN equal to itself, and -0 NOT equal to 0. Those last two are the two halves of ADR-15, and they go opposite ways on purpose. See Value’s equality.
equal_value_with
equal_value with a normalize hook, applied to every node on both sides, outermost first. This is where a runtime-specific container, an insertion-ordered map or a reference wrapper unwrapped into a plain value, is folded into the plain value the fixture’s JSON describes.
error_code
The code from an error expectation: ERROR:unexpected gives unexpected, and a bare ERROR gives "" (meaning “any code”). A trailing @<row>:<col> is a position expectation and is NOT part of the code; see error_expect. An error when handed a cell that is not an error expectation at all.
error_expect
Read an error expectation.
escape
Encode a string into the fixture escape set, the inverse of unescape. The backslash goes first so an already-escaped sequence is not double-decoded on the way back: unescape(escape(s)) == s for every s.
find_spec_dir
Walk up from from (the working directory when None) looking for a test/spec directory, and return it.
format_value
Render a value for a failure message: JSON where possible, so the text lines up with how the fixture wrote it, with -0 spelt -0 and the values JSON cannot spell written as JavaScript names them.
is_error_expect
Is this expected cell an error expectation?
load_spec
Load one fixture file by path.
load_spec_dir
Load every *.tsv in a directory, sorted by name so every runtime and every run visits them in the same order. Discovery by listing is deliberate: adding a fixture then runs it without editing a runner.
lone_surrogate_at
The position of the first UNPAIRED \uXXXX surrogate escape in an expected cell, counted in CODE POINTS, or None.
lone_surrogate_message
The message the runner uses when a shared cell holds an unpaired surrogate escape. Exported so every runtime says the same thing, and so a caller building its own runner can reuse it.
no_divergences
Declare that a repo records no divergences at all.
parse_expect
Parse an expected cell as JSON. An empty cell is Value::Undefined, the fixture convention for “no value”, as in a utility whose result is nothing at all.
parse_spec
Parse fixture text that is already in memory. load_spec is this plus a file read; tests of the loader itself use this form.
report
Panic with every failure at once, naming file and line, rather than stopping at the first; do nothing when there is nothing to report.
unescape
Decode the fixture escape set: \n, \r, \t and \\. Any other backslash sequence, and a trailing lone backslash, are left as they are.

Type Aliases§

Result
The result type every fallible function here returns.