lib.rs
//! Parser and patcher for the testmark format: named data hunks embedded in markdown.
//!
//! Testmark lets a markdown document double as documentation and test fixture data.
//! A data hunk is a fenced code block immediately preceded by a comment line
//! of the form `[testmark]:# (hunk-name)`:
//!
//! ````markdown
//! Some prose explaining the scenario.
//!
//! [testmark]:# (scenario/input)
//! ```text
//! data goes here
//! ```
//! ````
//!
//! Everything else in the document is plain markdown and is ignored
//! (and preserved byte-for-byte by the patcher).
//! The format is specified upstream at <https://github.com/warpfork/go-testmark>.
//!
//! The crate is built in three layers, each usable without the ones above it:
//!
//! - [`Document`]: parse a document; look up hunks. Reads are borrow-only.
//! - [`PatchAccumulator`]: pending hunk rewrites, applied in one pure pass
//! by [`Document::patched_all`]. Still pure format manipulation:
//! any tool that runs hunks and writes results back can use these two layers.
//! This implementation fails closed where the input looks like testmark but isn't quite:
//! malformed annotations, annotations without a following fence, unclosed fences,
//! and duplicate hunk names are all errors rather than silently skipped hunks.
//! (A silently skipped hunk would mean a silently unexercised test.)
mod document;
mod patch;
pub use document::{Document, Hunk, HunkContent, NewContent, ParseError, ParsedTable};
pub use patch::{PatchAccumulator, PatchError};
crates/testmark/src/lib.rs · 1.5 KiB · 9049dd4f1c