Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable inline trailing commas while we fix value replacement
Browse files Browse the repository at this point in the history
max-sixty committed Mar 5, 2024

Verified

This commit was signed with the committer’s verified signature.
max-sixty Maximilian Roos
1 parent 9dc95b4 commit 2ade0af
Showing 6 changed files with 18 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ All notable changes to insta and cargo-insta are documented here.

## 1.37.0

- All macros should now handle trailing commas.
- All macros for file snapshots should now handle trailing commas (but not yet inline snapshots)

## 1.36.1

10 changes: 6 additions & 4 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -219,7 +219,7 @@ macro_rules! assert_compact_json_snapshot {
};
}

// This macro is expected to handle optional trailing commas.
// The macro handles optional trailing commas for file snapshots.
#[doc(hidden)]
#[macro_export]
macro_rules! _assert_serialized_snapshot {
@@ -228,7 +228,8 @@ macro_rules! _assert_serialized_snapshot {
//
// Note that if we could unify the Inline & File represenations of snapshots
// redactions we could unify some of these branches.
(format=$format:ident, $value:expr, $(match ..)? {$($k:expr => $v:expr),* $(,)?}, @$snapshot:literal $(,)?) => {{

(format=$format:ident, $value:expr, $(match ..)? {$($k:expr => $v:expr),* $(,)?}, @$snapshot:literal) => {{
let transform = |value| {
let (_, value) = $crate::_prepare_snapshot_for_redaction!(value, {$($k => $v),*}, $format, Inline);
value
@@ -249,7 +250,8 @@ macro_rules! _assert_serialized_snapshot {
}};
// If there's an inline snapshot, capture serialization function and pass to
// `_assert_snapshot_base`, specifying `Inline`
(format=$format:ident, $($arg:expr),*, @$snapshot:literal) => {{
//
(format=$format:ident, $($arg:expr),*, @$snapshot:literal) => {{
let transform = |value| {$crate::_macro_support::serialize_value(
&value,
$crate::_macro_support::SerializationFormat::$format,
@@ -319,7 +321,7 @@ macro_rules! assert_debug_snapshot {
// the value. This allows us to implement other macros with a small wrapper. All
// snapshot macros eventually call this macro.
//
// This macro is expected to handle trailing commas.
// The macro handles optional trailing commas in file snapshots.
#[doc(hidden)]
#[macro_export]
macro_rules! _assert_snapshot_base {
9 changes: 9 additions & 0 deletions tests/snapshots/test_basic__trailing_commas-2.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
source: tests/test_basic.rs
expression: "vec![1, 2, 3, 4, 5]"
---
- 1
- 2
- 3
- 4
- 5
2 changes: 2 additions & 0 deletions tests/test_basic.rs
Original file line number Diff line number Diff line change
@@ -68,6 +68,8 @@ fn test_trailing_commas() {
assert_snapshot!("Testing",);
assert_snapshot!("Testing", "name",);
assert_snapshot!("Testing", "name", "expr",);
#[cfg(feature = "yaml")]
assert_yaml_snapshot!(vec![1, 2, 3, 4, 5],);
}

struct TestDisplay;
8 changes: 0 additions & 8 deletions tests/test_inline.rs
Original file line number Diff line number Diff line change
@@ -29,14 +29,6 @@ fn test_single_line() {
assert_snapshot!("Testing", @"Testing");
}

#[test]
fn test_trailing_commas() {
assert_snapshot!(
"Testing",
@"Testing",
);
}

#[test]
fn test_unnamed_single_line() {
assert_snapshot!("Testing");
18 changes: 0 additions & 18 deletions tests/test_redaction.rs
Original file line number Diff line number Diff line change
@@ -111,24 +111,6 @@ fn test_with_random_value_and_match_comma() {
".id" => "[id]",
}, // comma here
);
assert_yaml_snapshot!(
&User {
id: 11,
username: "john_doe".to_string(),
email: Email("john@example.com".to_string()),
extra: "".to_string(),
},
match .. {
".id" => "[id]",
},
@r###"
---
id: "[id]"
username: john_doe
email: john@example.com
extra: ""
"###, // comma here
);
}

#[cfg(feature = "csv")]

0 comments on commit 2ade0af

Please sign in to comment.