diff --git a/cargo-insta/src/inline.rs b/cargo-insta/src/inline.rs index b0ee5150..5aee2f49 100644 --- a/cargo-insta/src/inline.rs +++ b/cargo-insta/src/inline.rs @@ -149,19 +149,22 @@ impl FilePatcher { impl Visitor { fn scan_nested_macros(&mut self, tokens: &[TokenTree]) { for idx in 0..tokens.len() { + // Look for the start of a macro (potential snapshot location) if let Some(TokenTree::Ident(_)) = tokens.get(idx) { if let Some(TokenTree::Punct(ref punct)) = tokens.get(idx + 1) { if punct.as_char() == '!' { if let Some(TokenTree::Group(ref group)) = tokens.get(idx + 2) { + // Found a macro, determine its indentation let indentation = scan_for_path_start(tokens, idx); + // Extract tokens from the macro arguments let tokens: Vec<_> = group.stream().into_iter().collect(); + // Try to extract a snapshot, passing the calculated indentation self.try_extract_snapshot(&tokens, indentation); } } } } } - for token in tokens { // recurse into groups if let TokenTree::Group(group) = token { diff --git a/insta/tests/test_inline.rs b/insta/tests/test_inline.rs index 93f70126..bdee1fed 100644 --- a/insta/tests/test_inline.rs +++ b/insta/tests/test_inline.rs @@ -304,3 +304,14 @@ fn test_inline_snapshot_whitespace() { "###); } + +#[test] +fn test_indentation() { + assert_snapshot!("aaa\nbbb\nccc\nddd", @r" + aaa + bbb + ccc + ddd + " + ); +}