From 38c4fb8887414b53d2bc462e6e754d26289a9a14 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 22 Apr 2024 10:43:42 -0500 Subject: [PATCH] refactor(filters)!: Rename `replace` regex group with `redacted` --- crates/snapbox/src/filters/redactions.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/snapbox/src/filters/redactions.rs b/crates/snapbox/src/filters/redactions.rs index ca864c3c..927c6c23 100644 --- a/crates/snapbox/src/filters/redactions.rs +++ b/crates/snapbox/src/filters/redactions.rs @@ -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("(?(world|moon))").unwrap()); + /// subst.insert("[OBJECT]", regex::Regex::new("(?(world|moon))").unwrap()); /// # } /// ``` pub fn insert( @@ -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()) } } @@ -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("(?world)!").unwrap()) - .unwrap(); + sub.insert( + "[OBJECT]", + regex::Regex::new("(?world)!").unwrap(), + ) + .unwrap(); let actual = normalize(input, pattern, &sub); assert_eq!(actual, pattern); }