diff --git a/cargo-insta/src/inline.rs b/cargo-insta/src/inline.rs index 5aee2f49..e4c7b07e 100644 --- a/cargo-insta/src/inline.rs +++ b/cargo-insta/src/inline.rs @@ -188,7 +188,8 @@ impl FilePatcher { } match tokens[tokens.len() - 2] { - TokenTree::Punct(ref punct) if punct.as_char() == '@' => {} + TokenTree::Punct(ref punct) + if punct.as_char() == '@' || punct.as_char() == '+' => {} _ => { return false; } diff --git a/insta/src/macros.rs b/insta/src/macros.rs index ba837e40..cfae80ec 100644 --- a/insta/src/macros.rs +++ b/insta/src/macros.rs @@ -330,6 +330,15 @@ macro_rules! _assert_snapshot_base { $($arg),* ) }; + // Or using the new syntax + (transform=$transform:expr, $($arg:expr),*, !$snapshot:literal $(,)?) => { + $crate::_assert_snapshot_base!( + transform = $transform, + #[allow(clippy::needless_raw_string_hashes)] + $crate::_macro_support::ReferenceValue::Inline($snapshot), + $($arg),* + ) + }; // If there's no debug_expr, use the stringified value, call self. (transform=$transform:expr, $name:expr, $value:expr $(,)?) => { $crate::_assert_snapshot_base!(transform = $transform, $name, $value, stringify!($value)) diff --git a/insta/tests/test_inline.rs b/insta/tests/test_inline.rs index bdee1fed..ea899cae 100644 --- a/insta/tests/test_inline.rs +++ b/insta/tests/test_inline.rs @@ -37,6 +37,16 @@ fn test_single_line() { assert_snapshot!("Testing", @"Testing"); } +#[test] +fn test_single_line_plus() { + // New `+` syntax + assert_snapshot!("Testing", !"Testing"); + + // TODO: move to integration test: confirm this fails (it wouldn't fail with + // a `-` prefix, for example) + // assert_snapshot!("Testing", *5); +} + // We used to use the thread name for snapshot name detection. This is unreliable // so this test now basically does exactly the same as `test_unnamed_single_line`. #[test]