diff --git a/CHANGELOG.md b/CHANGELOG.md index e3ddd1b8..e83c1cf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/macros.rs b/src/macros.rs index 3e2d12a4..ffad3f7f 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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 { diff --git a/tests/snapshots/test_basic__trailing_commas-2.snap b/tests/snapshots/test_basic__trailing_commas-2.snap new file mode 100644 index 00000000..d1a08192 --- /dev/null +++ b/tests/snapshots/test_basic__trailing_commas-2.snap @@ -0,0 +1,9 @@ +--- +source: tests/test_basic.rs +expression: "vec![1, 2, 3, 4, 5]" +--- +- 1 +- 2 +- 3 +- 4 +- 5 diff --git a/tests/test_basic.rs b/tests/test_basic.rs index 8f6cdfaa..010612f9 100644 --- a/tests/test_basic.rs +++ b/tests/test_basic.rs @@ -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; diff --git a/tests/test_inline.rs b/tests/test_inline.rs index 0749cc4a..71830be8 100644 --- a/tests/test_inline.rs +++ b/tests/test_inline.rs @@ -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"); diff --git a/tests/test_redaction.rs b/tests/test_redaction.rs index 8d75e71b..2b0f126b 100644 --- a/tests/test_redaction.rs +++ b/tests/test_redaction.rs @@ -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")]