From 30a9b788f7b8d8a9110f8aacb377046c36723722 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 18 Apr 2024 21:04:49 -0500 Subject: [PATCH] feat(snap)!: Allow Harness users to specify DataFormat BREAKING CHANGE: `Case` requires a `format: Option` field Fixes #263 --- crates/snapbox/src/harness.rs | 8 +++++++- crates/snapbox/src/lib.rs | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/snapbox/src/harness.rs b/crates/snapbox/src/harness.rs index 506fd180..9e723992 100644 --- a/crates/snapbox/src/harness.rs +++ b/crates/snapbox/src/harness.rs @@ -22,6 +22,7 @@ //! name, //! fixture: input_path, //! expected, +//! format: None, //! } //! } //! @@ -125,7 +126,10 @@ where Trial::test(case.name.clone(), move || { let actual = (test)(&case.fixture)?; let actual = actual.to_string(); - let actual = crate::Data::text(actual).normalize(NormalizeNewlines); + let mut actual = crate::Data::text(actual).normalize(NormalizeNewlines); + if let Some(format) = case.format { + actual = actual.coerce_to(format); + } #[allow(deprecated)] let verify = Verifier::new() .palette(crate::report::Palette::auto()) @@ -229,4 +233,6 @@ pub struct Case { pub fixture: std::path::PathBuf, /// What the actual output should be compared against or updated pub expected: std::path::PathBuf, + /// Explicitly specify what format `expected` is stored in + pub format: Option, } diff --git a/crates/snapbox/src/lib.rs b/crates/snapbox/src/lib.rs index 561d2a0a..df638c8c 100644 --- a/crates/snapbox/src/lib.rs +++ b/crates/snapbox/src/lib.rs @@ -76,6 +76,7 @@ //! name, //! fixture: input_path, //! expected, +//! format: None, //! } //! } //!