Skip to content

Commit

Permalink
refactor(filters)!: Rename replace regex group with redacted
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Apr 22, 2024
1 parent 9e4ad59 commit 38c4fb8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions crates/snapbox/src/filters/redactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ impl Redactions {
///
/// With the `regex` feature, you can define patterns using regexes.
/// You can choose to replace a subset of the regex by giving it the named capture group
/// `replace`.
/// `redacted`.
///
/// ```rust
/// # #[cfg(feature = "regex")] {
/// let mut subst = snapbox::Redactions::new();
/// subst.insert("[OBJECT]", regex::Regex::new("(?<replace>(world|moon))").unwrap());
/// subst.insert("[OBJECT]", regex::Regex::new("(?<redacted>(world|moon))").unwrap());
/// # }
/// ```
pub fn insert(
Expand Down Expand Up @@ -135,7 +135,7 @@ impl RedactedValueInner {
#[cfg(feature = "regex")]
Self::Regex(r) => {
let captures = r.captures(buffer)?;
let m = captures.name("replace").or_else(|| captures.get(0))?;
let m = captures.name("redacted").or_else(|| captures.get(0))?;
Some(m.range())
}
}
Expand Down Expand Up @@ -561,8 +561,11 @@ mod test {
let input = "Hello world!";
let pattern = "Hello [OBJECT]!";
let mut sub = Redactions::new();
sub.insert("[OBJECT]", regex::Regex::new("(?<replace>world)!").unwrap())
.unwrap();
sub.insert(
"[OBJECT]",
regex::Regex::new("(?<redacted>world)!").unwrap(),
)
.unwrap();
let actual = normalize(input, pattern, &sub);
assert_eq!(actual, pattern);
}
Expand Down

0 comments on commit 38c4fb8

Please sign in to comment.