Skip to content

Commit

Permalink
Merge pull request #288 from epage/norm
Browse files Browse the repository at this point in the history
fix(filters)!: Move Filters from data
  • Loading branch information
epage authored Apr 22, 2024
2 parents ae2eaf2 + fe2fb1e commit 247e294
Show file tree
Hide file tree
Showing 9 changed files with 585 additions and 604 deletions.
14 changes: 7 additions & 7 deletions crates/snapbox/src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anstream::stderr;
#[cfg(not(feature = "color"))]
use std::io::stderr;

use crate::data::{NormalizeMatches, NormalizeNewlines, NormalizePaths};
use crate::filters::{Filter as _, FilterNewlines, FilterPaths, FilterRedactions};
use crate::Action;

/// Snapshot assertion against a file's contents
Expand Down Expand Up @@ -143,11 +143,11 @@ impl Assert {
expected: crate::Data,
mut actual: crate::Data,
) -> (crate::Data, crate::Data) {
let expected = expected.normalize(NormalizeNewlines);
let expected = FilterNewlines.filter(expected);
// On `expected` being an error, make a best guess
let format = expected.intended_format();

actual = actual.coerce_to(format).normalize(NormalizeNewlines);
actual = FilterNewlines.filter(actual.coerce_to(format));

(expected, actual)
}
Expand All @@ -157,19 +157,19 @@ impl Assert {
expected: crate::Data,
mut actual: crate::Data,
) -> (crate::Data, crate::Data) {
let expected = expected.normalize(NormalizeNewlines);
let expected = FilterNewlines.filter(expected);
// On `expected` being an error, make a best guess
let format = expected.intended_format();
actual = actual.coerce_to(format);

if self.normalize_paths {
actual = actual.normalize(NormalizePaths);
actual = FilterPaths.filter(actual);
}
// Always normalize new lines
actual = actual.normalize(NormalizeNewlines);
actual = FilterNewlines.filter(actual);

// If expected is not an error normalize matches
actual = actual.normalize(NormalizeMatches::new(&self.substitutions, &expected));
actual = FilterRedactions::new(&self.substitutions, &expected).filter(actual);

(expected, actual)
}
Expand Down
16 changes: 2 additions & 14 deletions crates/snapbox/src/data/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
mod format;
mod normalize;
mod runtime;
mod source;
#[cfg(test)]
mod tests;

pub use format::DataFormat;
pub use normalize::Normalize;
pub use normalize::NormalizeMatches;
pub use normalize::NormalizeNewlines;
pub use normalize::NormalizePaths;
pub use source::DataSource;
pub use source::Inline;
pub use source::Position;
Expand Down Expand Up @@ -97,8 +92,8 @@ macro_rules! str {
/// This provides conveniences for tracking the intended format (binary vs text).
#[derive(Clone, Debug)]
pub struct Data {
inner: DataInner,
source: Option<DataSource>,
pub(crate) inner: DataInner,
pub(crate) source: Option<DataSource>,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -221,13 +216,6 @@ impl Data {
.map_err(|e| format!("Failed to write {}: {}", path.display(), e).into())
}

/// Post-process text
///
/// See [utils][crate::utils]
pub fn normalize(self, op: impl Normalize) -> Self {
op.normalize(self)
}

/// Return the underlying `String`
///
/// Note: this will not inspect binary data for being a valid `String`.
Expand Down
210 changes: 0 additions & 210 deletions crates/snapbox/src/data/normalize.rs

This file was deleted.

Loading

0 comments on commit 247e294

Please sign in to comment.