From 9016d4d26dc2997d19558b5fb677af7db594f1af Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 23 May 2024 15:17:10 -0500 Subject: [PATCH] fix(filter): Rename Filters to have Filter prefix --- crates/snapbox/src/assert/mod.rs | 8 ++++---- crates/snapbox/src/data/normalize.rs | 4 ++-- crates/snapbox/src/dir/diff.rs | 12 ++++++------ crates/snapbox/src/filter/mod.rs | 22 ++++++++++++++++++++-- crates/snapbox/src/filter/test.rs | 16 ++++++++-------- crates/trycmd/src/runner.rs | 4 ++-- crates/trycmd/src/schema.rs | 10 +++++----- 7 files changed, 47 insertions(+), 29 deletions(-) diff --git a/crates/snapbox/src/assert/mod.rs b/crates/snapbox/src/assert/mod.rs index 570b0734..467ba554 100644 --- a/crates/snapbox/src/assert/mod.rs +++ b/crates/snapbox/src/assert/mod.rs @@ -8,7 +8,7 @@ use anstream::stderr; #[cfg(not(feature = "color"))] use std::io::stderr; -use crate::filter::{Filter as _, FilterRedactions, NormalizeNewlines, NormalizePaths}; +use crate::filter::{Filter as _, FilterNewlines, FilterPaths, FilterRedactions}; use crate::IntoData; pub use action::Action; @@ -175,7 +175,7 @@ impl Assert { mut expected: crate::Data, ) -> (crate::Data, crate::Data) { if expected.filters.is_newlines_set() { - expected = NormalizeNewlines.filter(expected); + expected = FilterNewlines.filter(expected); } // On `expected` being an error, make a best guess @@ -183,10 +183,10 @@ impl Assert { actual = actual.coerce_to(format); if self.normalize_paths && expected.filters.is_paths_set() { - actual = NormalizePaths.filter(actual); + actual = FilterPaths.filter(actual); } if expected.filters.is_newlines_set() { - actual = NormalizeNewlines.filter(actual); + actual = FilterNewlines.filter(actual); } if expected.filters.is_redaction_set() { actual = FilterRedactions::new(&self.substitutions, &expected).filter(actual); diff --git a/crates/snapbox/src/data/normalize.rs b/crates/snapbox/src/data/normalize.rs index d7add9e7..da79f8e0 100644 --- a/crates/snapbox/src/data/normalize.rs +++ b/crates/snapbox/src/data/normalize.rs @@ -4,7 +4,7 @@ use super::Data; pub use crate::filter::Filter as Normalize; -#[deprecated(since = "0.5.11", note = "Replaced with `filter::NormalizeNewlines")] +#[deprecated(since = "0.5.11", note = "Replaced with `filter::FilterNewlines")] pub struct NormalizeNewlines; impl Normalize for NormalizeNewlines { fn normalize(&self, data: Data) -> Data { @@ -12,7 +12,7 @@ impl Normalize for NormalizeNewlines { } } -#[deprecated(since = "0.5.11", note = "Replaced with `filter::NormalizePaths")] +#[deprecated(since = "0.5.11", note = "Replaced with `filter::FilterPaths")] pub struct NormalizePaths; impl Normalize for NormalizePaths { fn normalize(&self, data: Data) -> Data { diff --git a/crates/snapbox/src/dir/diff.rs b/crates/snapbox/src/dir/diff.rs index 34c379f0..dafc7860 100644 --- a/crates/snapbox/src/dir/diff.rs +++ b/crates/snapbox/src/dir/diff.rs @@ -1,5 +1,5 @@ #[cfg(feature = "dir")] -use crate::filter::{Filter as _, FilterRedactions, NormalizeNewlines, NormalizePaths}; +use crate::filter::{Filter as _, FilterNewlines, FilterPaths, FilterRedactions}; #[derive(Clone, Debug, PartialEq, Eq)] pub enum PathDiff { @@ -78,9 +78,9 @@ impl PathDiff { crate::Data::try_read_from(&actual_path, None).map_err(Self::Failure)?; let expected = - NormalizeNewlines.filter(crate::Data::read_from(&expected_path, None)); + FilterNewlines.filter(crate::Data::read_from(&expected_path, None)); - actual = NormalizeNewlines.filter(actual.coerce_to(expected.intended_format())); + actual = FilterNewlines.filter(actual.coerce_to(expected.intended_format())); if expected != actual { return Err(Self::ContentMismatch { @@ -154,14 +154,14 @@ impl PathDiff { crate::Data::try_read_from(&actual_path, None).map_err(Self::Failure)?; let expected = - NormalizeNewlines.filter(crate::Data::read_from(&expected_path, None)); + FilterNewlines.filter(crate::Data::read_from(&expected_path, None)); actual = actual.coerce_to(expected.intended_format()); if normalize_paths { - actual = NormalizePaths.filter(actual); + actual = FilterPaths.filter(actual); } actual = FilterRedactions::new(substitutions, &expected) - .filter(NormalizeNewlines.filter(actual)); + .filter(FilterNewlines.filter(actual)); if expected != actual { return Err(Self::ContentMismatch { diff --git a/crates/snapbox/src/filter/mod.rs b/crates/snapbox/src/filter/mod.rs index 50cc51ec..27fd531b 100644 --- a/crates/snapbox/src/filter/mod.rs +++ b/crates/snapbox/src/filter/mod.rs @@ -23,8 +23,26 @@ pub trait Filter { } } +#[deprecated(since = "0.5.11", note = "Replaced with `filter::FilterNewlines")] pub struct NormalizeNewlines; +#[allow(deprecated)] impl Filter for NormalizeNewlines { + fn normalize(&self, data: Data) -> Data { + FilterNewlines.normalize(data) + } +} + +#[deprecated(since = "0.5.11", note = "Replaced with `filter::FilterPaths")] +pub struct NormalizePaths; +#[allow(deprecated)] +impl Filter for NormalizePaths { + fn normalize(&self, data: Data) -> Data { + FilterPaths.normalize(data) + } +} + +pub struct FilterNewlines; +impl Filter for FilterNewlines { fn normalize(&self, data: Data) -> Data { let source = data.source; let filters = data.filters; @@ -64,8 +82,8 @@ fn normalize_lines_chars(data: impl Iterator) -> impl Iterator Data { let source = data.source; let filters = data.filters; diff --git a/crates/snapbox/src/filter/test.rs b/crates/snapbox/src/filter/test.rs index 34fb1b2a..0f8d1332 100644 --- a/crates/snapbox/src/filter/test.rs +++ b/crates/snapbox/src/filter/test.rs @@ -10,9 +10,9 @@ use super::*; fn json_normalize_paths_and_lines() { let json = json!({"name": "John\\Doe\r\n"}); let data = Data::json(json); - let data = NormalizePaths.filter(data); + let data = FilterPaths.filter(data); assert_eq!(Data::json(json!({"name": "John/Doe\r\n"})), data); - let data = NormalizeNewlines.filter(data); + let data = FilterNewlines.filter(data); assert_eq!(Data::json(json!({"name": "John/Doe\n"})), data); } @@ -26,7 +26,7 @@ fn json_normalize_obj_paths_and_lines() { } }); let data = Data::json(json); - let data = NormalizePaths.filter(data); + let data = FilterPaths.filter(data); let assert = json!({ "person": { "name": "John/Doe\r\n", @@ -34,7 +34,7 @@ fn json_normalize_obj_paths_and_lines() { } }); assert_eq!(Data::json(assert), data); - let data = NormalizeNewlines.filter(data); + let data = FilterNewlines.filter(data); let assert = json!({ "person": { "name": "John/Doe\n", @@ -49,10 +49,10 @@ fn json_normalize_obj_paths_and_lines() { fn json_normalize_array_paths_and_lines() { let json = json!({"people": ["John\\Doe\r\n", "Jo\\hn\r\n"]}); let data = Data::json(json); - let data = NormalizePaths.filter(data); + let data = FilterPaths.filter(data); let paths = json!({"people": ["John/Doe\r\n", "Jo/hn\r\n"]}); assert_eq!(Data::json(paths), data); - let data = NormalizeNewlines.filter(data); + let data = FilterNewlines.filter(data); let new_lines = json!({"people": ["John/Doe\n", "Jo/hn\n"]}); assert_eq!(Data::json(new_lines), data); } @@ -69,7 +69,7 @@ fn json_normalize_array_obj_paths_and_lines() { ] }); let data = Data::json(json); - let data = NormalizePaths.filter(data); + let data = FilterPaths.filter(data); let paths = json!({ "people": [ { @@ -79,7 +79,7 @@ fn json_normalize_array_obj_paths_and_lines() { ] }); assert_eq!(Data::json(paths), data); - let data = NormalizeNewlines.filter(data); + let data = FilterNewlines.filter(data); let new_lines = json!({ "people": [ { diff --git a/crates/trycmd/src/runner.rs b/crates/trycmd/src/runner.rs index 92b19d77..96159164 100644 --- a/crates/trycmd/src/runner.rs +++ b/crates/trycmd/src/runner.rs @@ -14,7 +14,7 @@ use std::io::stderr; use rayon::prelude::*; use snapbox::data::DataFormat; use snapbox::dir::FileType; -use snapbox::filter::{Filter as _, FilterRedactions, NormalizeNewlines, NormalizePaths}; +use snapbox::filter::{Filter as _, FilterNewlines, FilterPaths, FilterRedactions}; use snapbox::IntoData; #[derive(Debug)] @@ -738,7 +738,7 @@ impl Stream { if content.format() != DataFormat::Text { self.status = StreamStatus::Failure("Unable to convert underlying Data to Text".into()); } - self.content = NormalizeNewlines.filter(NormalizePaths.filter(content)); + self.content = FilterNewlines.filter(FilterPaths.filter(content)); self } diff --git a/crates/trycmd/src/schema.rs b/crates/trycmd/src/schema.rs index 69fea580..78e47975 100644 --- a/crates/trycmd/src/schema.rs +++ b/crates/trycmd/src/schema.rs @@ -2,7 +2,7 @@ //! //! [`OneShot`] is the top-level item in the `cmd.toml` files. -use snapbox::filter::{Filter as _, NormalizeNewlines, NormalizePaths}; +use snapbox::filter::{Filter as _, FilterNewlines, FilterPaths}; use std::collections::BTreeMap; use std::collections::VecDeque; @@ -40,8 +40,8 @@ impl TryCmd { let stdout_path = path.with_extension("stdout"); let stdout = if stdout_path.exists() { Some( - NormalizeNewlines.filter( - NormalizePaths + FilterNewlines.filter( + FilterPaths .filter(crate::Data::read_from(&stdout_path, Some(is_binary))), ), ) @@ -55,8 +55,8 @@ impl TryCmd { let stderr_path = path.with_extension("stderr"); let stderr = if stderr_path.exists() { Some( - NormalizeNewlines.filter( - NormalizePaths + FilterNewlines.filter( + FilterPaths .filter(crate::Data::read_from(&stderr_path, Some(is_binary))), ), )