Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mitsuhiko/insta
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.7.2
Choose a base ref
...
head repository: mitsuhiko/insta
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.8.0
Choose a head ref
  • 2 commits
  • 8 files changed
  • 1 contributor

Commits on Sep 10, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    600b22a View commit details
  2. 1.8.0

    mitsuhiko committed Sep 10, 2021
    Copy the full SHA
    dfa35dc View commit details
Showing with 60 additions and 7 deletions.
  1. +4 −0 CHANGELOG.md
  2. +1 −1 Cargo.toml
  3. +2 −2 cargo-insta/Cargo.lock
  4. +2 −2 cargo-insta/Cargo.toml
  5. +6 −1 src/redaction.rs
  6. +1 −1 src/select_grammar.pest
  7. +10 −0 tests/snapshots/test_redaction__map_key_redaction.snap
  8. +34 −0 tests/test_redaction.rs
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,10 @@

All notable changes to insta and cargo-insta are documented here.

## 1.8.0

- Added the ability to redact into a key. (#192)

## 1.7.2

- Fixed an issue where selectors could not start with underscore. (#189)
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "insta"
version = "1.7.2"
version = "1.8.0"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A snapshot testing library for Rust"
4 changes: 2 additions & 2 deletions cargo-insta/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cargo-insta/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-insta"
version = "1.7.2"
version = "1.8.0"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A review tool for the insta snapshot testing library for Rust"
@@ -12,7 +12,7 @@ edition = "2018"
readme = "README.md"

[dependencies]
insta = { version = "1.7.2", path = "..", features = ["redactions"] }
insta = { version = "1.8.0", path = "..", features = ["redactions"] }
console = "0.14.0"
clap = { version = "2.33.3", default-features = false }
difference = "2.0.0"
7 changes: 6 additions & 1 deletion src/redaction.rs
Original file line number Diff line number Diff line change
@@ -417,10 +417,15 @@ impl<'a> Selector<'a> {
Content::Map(map) => Content::Map(
map.into_iter()
.map(|(key, value)| {
path.push(PathItem::Field("$key"));
let new_key = self.redact_impl(key.clone(), redaction, path);
path.pop();

path.push(PathItem::Content(key.clone()));
let new_value = self.redact_impl(value, redaction, path);
path.pop();
(key, new_value)

(new_key, new_value)
})
.collect(),
),
2 changes: 1 addition & 1 deletion src/select_grammar.pest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
WHITESPACE = _{ WHITE_SPACE }

ident = @{ ( "_" | XID_START ) ~ XID_CONTINUE* }
ident = @{ ( "_" | "$" | XID_START ) ~ XID_CONTINUE* }
deep_wildcard = { "." ~ "**" }
wildcard = { "." ~ "*" }
key = @{ "." ~ ident }
10 changes: 10 additions & 0 deletions tests/snapshots/test_redaction__map_key_redaction.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: tests/test_redaction.rs
expression: foo
---
hm:
? bucket: "[bucket]"
value: 0
: 42
btm:
"[key]": 23
34 changes: 34 additions & 0 deletions tests/test_redaction.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![cfg(feature = "redactions")]

use std::collections::{BTreeMap, HashMap};

use insta::_macro_support::Selector;
use insta::{
assert_debug_snapshot, assert_json_snapshot, assert_yaml_snapshot, with_settings, Settings,
@@ -307,3 +309,35 @@ fn test_struct_array_redaction() {
"[].products[].product_name" => "[product_name]",
});
}

#[test]
fn test_map_key_redaction() {
#[derive(Serialize, Hash, PartialEq, PartialOrd, Eq, Ord)]
struct Key {
bucket: u32,
value: u32,
}

#[derive(Serialize)]
struct Foo {
hm: HashMap<Key, u32>,
btm: BTreeMap<(u32, u32), u32>,
}

let mut hm = HashMap::new();
hm.insert(
Key {
bucket: 1,
value: 0,
},
42,
);
let mut btm = BTreeMap::new();
btm.insert((0, 0), 23);
let foo = Foo { hm, btm };

insta::assert_yaml_snapshot!(foo, {
".hm.$key.bucket" => "[bucket]",
".btm.$key" => "[key]",
});
}