From 64a49589e74447da668bd5acab8375206a10253f Mon Sep 17 00:00:00 2001 From: David Lattimore Date: Sat, 27 Jun 2020 20:34:21 +1000 Subject: Fix handling of whitespace when applying SSR within macro expansions. I originally did replacement by passing in the full file text. Then as some point I thought I could do without it. Turns out calling .text() on a node coming from a macro expansion isn't a great idea, especially when you then try and use ranges from the original source to cut that text. The test I added here actually panics without the rest of this change (sorry I didn't notice sooner). --- crates/ra_ssr/src/tests.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'crates/ra_ssr/src/tests.rs') diff --git a/crates/ra_ssr/src/tests.rs b/crates/ra_ssr/src/tests.rs index 7a3141be8..8be60c293 100644 --- a/crates/ra_ssr/src/tests.rs +++ b/crates/ra_ssr/src/tests.rs @@ -606,3 +606,20 @@ fn replace_within_macro_expansion() { fn f() {macro1!(bar(5.x()).o2())}"#, ) } + +#[test] +fn preserves_whitespace_within_macro_expansion() { + assert_ssr_transform( + "$a + $b ==>> $b - $a", + r#" + macro_rules! macro1 { + ($a:expr) => {$a} + } + fn f() {macro1!(1 * 2 + 3 + 4}"#, + r#" + macro_rules! macro1 { + ($a:expr) => {$a} + } + fn f() {macro1!(4 - 3 - 1 * 2}"#, + ) +} -- cgit v1.2.3