pub struct Mismatch { /* private fields */ }Expand description
The error returned by Snapshot::check when the snapshot does not match
the expected text.
A Mismatch owns the computed Diff. Its Display prints
a unified diff — - lines were expected, + lines were produced — suitable
for surfacing straight through a failing test’s panic message.
§Examples
use test_lang::Snapshot;
let err = Snapshot::new("actual").check("expected").unwrap_err();
// `-expected` was wanted; `+actual` is what the stage produced.
assert!(err.to_string().contains("-expected"));
assert!(err.to_string().contains("+actual"));Implementations§
Source§impl Mismatch
impl Mismatch
Sourcepub fn diff(&self) -> &Diff
pub fn diff(&self) -> &Diff
The line-level diff between the expected text and the snapshot.
Use this to inspect the mismatch programmatically instead of parsing the rendered string — for example, to count how many lines changed.
§Examples
use test_lang::{Change, Snapshot};
let err = Snapshot::new("a\nb").check("a\nB").unwrap_err();
let edits = err
.diff()
.changes()
.filter(|(c, _)| *c != Change::Equal)
.count();
assert_eq!(edits, 2); // one deletion, one insertionTrait Implementations§
impl Eq for Mismatch
Source§impl Error for Mismatch
impl Error for Mismatch
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
impl StructuralPartialEq for Mismatch
Auto Trait Implementations§
impl Freeze for Mismatch
impl RefUnwindSafe for Mismatch
impl Send for Mismatch
impl Sync for Mismatch
impl Unpin for Mismatch
impl UnsafeUnpin for Mismatch
impl UnwindSafe for Mismatch
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more