Skip to content

Commit

Permalink
Merge pull request #371 from epage/clear
Browse files Browse the repository at this point in the history
feat(redact): Expose clear_unused
  • Loading branch information
epage authored Nov 7, 2024
2 parents e60453c + 6a9a6b2 commit 90ad298
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/snapbox/src/filter/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ fn line_matches(mut actual: &str, expected: &str, redactions: &Redactions) -> bo
return true;
}

let expected = redactions.clear(expected);
let expected = redactions.clear_unused(expected);
let mut sections = expected.split("[..]").peekable();
while let Some(section) = sections.next() {
if let Some(remainder) = actual.strip_prefix(section) {
Expand Down
7 changes: 6 additions & 1 deletion crates/snapbox/src/filter/redactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ impl Redactions {
input
}

pub(crate) fn clear<'v>(&self, pattern: &'v str) -> Cow<'v, str> {
/// Clear unused redactions from expected data
///
/// Some redactions can be conditionally present, like redacting [`std::env::consts::EXE_SUFFIX`].
/// When the redaction is not present, it needs to be removed from the expected data so it can
/// be matched against the actual data.
pub fn clear_unused<'v>(&self, pattern: &'v str) -> Cow<'v, str> {
if !self.unused.as_ref().map(|s| s.is_empty()).unwrap_or(false) && pattern.contains('[') {
let mut pattern = pattern.to_owned();
replace_many(
Expand Down

0 comments on commit 90ad298

Please sign in to comment.