Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(redact): Expose clear_unused #371

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading