diff --git a/crates/snapbox/src/data/mod.rs b/crates/snapbox/src/data/mod.rs index 56a5803d..20e9cca3 100644 --- a/crates/snapbox/src/data/mod.rs +++ b/crates/snapbox/src/data/mod.rs @@ -161,7 +161,8 @@ impl Data { pub fn read_from(path: &std::path::Path, data_format: Option) -> Self { match Self::try_read_from(path, data_format) { Ok(data) => data, - Err(err) => Self::error(err, data_format.unwrap_or_default()).with_path(path), + Err(err) => Self::error(err, data_format.unwrap_or_else(|| DataFormat::from(path))) + .with_path(path), } } diff --git a/crates/snapbox/src/data/normalize.rs b/crates/snapbox/src/data/normalize.rs index ca0455ca..afa3229e 100644 --- a/crates/snapbox/src/data/normalize.rs +++ b/crates/snapbox/src/data/normalize.rs @@ -79,10 +79,12 @@ impl Normalize for NormalizeMatches<'_> { DataInner::Error(err) => err.into(), DataInner::Binary(bin) => Data::binary(bin), DataInner::Text(text) => { - let lines = self - .substitutions - .normalize(&text, &self.pattern.render().unwrap()); - Data::text(lines) + if let Some(pattern) = self.pattern.render() { + let lines = self.substitutions.normalize(&text, &pattern); + Data::text(lines) + } else { + DataInner::Text(text).into() + } } #[cfg(feature = "json")] DataInner::Json(value) => { @@ -94,10 +96,12 @@ impl Normalize for NormalizeMatches<'_> { } #[cfg(feature = "term-svg")] DataInner::TermSvg(text) => { - let lines = self - .substitutions - .normalize(&text, &self.pattern.render().unwrap()); - DataInner::TermSvg(lines).into() + if let Some(pattern) = self.pattern.render() { + let lines = self.substitutions.normalize(&text, &pattern); + DataInner::TermSvg(lines).into() + } else { + DataInner::TermSvg(text).into() + } } }; new.source = data.source;