varar-core 0.7.0

Markdown-native BDD — pure functional core engine
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! Where a failure points in the `.md` — port of `failure-anchor.ts` /
//! `FailureAnchor.java`. A mismatch anchors at its first failing span; anything
//! else at the fallback (the step's match start). Crate-private, like Java's
//! package-private class.

use crate::error::StepError;
use crate::span::Span;

/// The failure's source anchor: first failing cell span / doc-string body span /
/// the `fallback`.
pub(crate) fn anchor(error: &StepError, fallback: Span) -> Span {
    match error {
        StepError::CellMismatch(cells) => cells.iter().find(|c| !c.ok).map_or(fallback, |c| c.span),
        _ => fallback,
    }
}