Skip to content

Commit

Permalink
feat: Allow clearing an existing variable
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 14, 2024
1 parent 599ecbd commit 429f432
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions crates/snapbox/src/substitutions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ impl Substitutions {
Ok(())
}

pub fn remove(&mut self, key: &'static str) -> Result<(), crate::Error> {
let key = validate_key(key)?;
self.vars.remove(key);
Ok(())
}

/// Apply match pattern to `input`
///
/// If `pattern` matches `input`, then `pattern` is returned.
Expand Down
10 changes: 9 additions & 1 deletion src/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl TestCases {

/// Batch add variables for normalizing output
///
/// See `insert_var`.
/// See [`insert_var`].
pub fn extend_vars(
&self,
vars: impl IntoIterator<Item = (&'static str, impl Into<Cow<'static, str>>)>,
Expand All @@ -152,6 +152,14 @@ impl TestCases {
Ok(self)
}

/// Remove an existing var values
///
/// See [`insert_var`].
pub fn clear_var(&self, var: &'static str) -> Result<&Self, crate::Error> {
self.substitutions.borrow_mut().remove(var)?;
Ok(self)
}

/// Run tests
///
/// This will happen on `drop` if not done explicitly
Expand Down

0 comments on commit 429f432

Please sign in to comment.