diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-30 12:36:50 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-30 12:36:50 +0100 |
commit | 9042009b7f1ba0f85e892ac5184fa4542d0c10f5 (patch) | |
tree | b56e925c4f822f5479350883c87b952300995fc6 /crates/ra_ssr/src/tests.rs | |
parent | be803efb7c7ba257716fcc97c57ecfd07e278b07 (diff) | |
parent | fa1e4113224c119258670538f8c3ca6c8ea8ad1e (diff) |
Merge #5567
5567: SSR: Wrap placeholder expansions in parenthesis when necessary r=matklad a=davidlattimore
e.g. `foo($a) ==> $a.to_string()` should produce `(1 + 2).to_string()` not `1 + 2.to_string()`
We don't yet try to determine if the whole replacement needs to be wrapped in parenthesis. That's harder and I think perhaps less often an issue.
Co-authored-by: David Lattimore <[email protected]>
Diffstat (limited to 'crates/ra_ssr/src/tests.rs')
-rw-r--r-- | crates/ra_ssr/src/tests.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/crates/ra_ssr/src/tests.rs b/crates/ra_ssr/src/tests.rs index f5ffff7cc..a4fa2cb44 100644 --- a/crates/ra_ssr/src/tests.rs +++ b/crates/ra_ssr/src/tests.rs | |||
@@ -664,7 +664,7 @@ fn replace_binary_op() { | |||
664 | assert_ssr_transform( | 664 | assert_ssr_transform( |
665 | "$a + $b ==>> $b + $a", | 665 | "$a + $b ==>> $b + $a", |
666 | "fn f() {1 + 2 + 3 + 4}", | 666 | "fn f() {1 + 2 + 3 + 4}", |
667 | expect![["fn f() {4 + 3 + 2 + 1}"]], | 667 | expect![[r#"fn f() {4 + (3 + (2 + 1))}"#]], |
668 | ); | 668 | ); |
669 | } | 669 | } |
670 | 670 | ||
@@ -773,12 +773,33 @@ fn preserves_whitespace_within_macro_expansion() { | |||
773 | macro_rules! macro1 { | 773 | macro_rules! macro1 { |
774 | ($a:expr) => {$a} | 774 | ($a:expr) => {$a} |
775 | } | 775 | } |
776 | fn f() {macro1!(4 - 3 - 1 * 2} | 776 | fn f() {macro1!(4 - (3 - 1 * 2)} |
777 | "#]], | 777 | "#]], |
778 | ) | 778 | ) |
779 | } | 779 | } |
780 | 780 | ||
781 | #[test] | 781 | #[test] |
782 | fn add_parenthesis_when_necessary() { | ||
783 | assert_ssr_transform( | ||
784 | "foo($a) ==>> $a.to_string()", | ||
785 | r#" | ||
786 | fn foo(_: i32) {} | ||
787 | fn bar3(v: i32) { | ||
788 | foo(1 + 2); | ||
789 | foo(-v); | ||
790 | } | ||
791 | "#, | ||
792 | expect![[r#" | ||
793 | fn foo(_: i32) {} | ||
794 | fn bar3(v: i32) { | ||
795 | (1 + 2).to_string(); | ||
796 | (-v).to_string(); | ||
797 | } | ||
798 | "#]], | ||
799 | ) | ||
800 | } | ||
801 | |||
802 | #[test] | ||
782 | fn match_failure_reasons() { | 803 | fn match_failure_reasons() { |
783 | let code = r#" | 804 | let code = r#" |
784 | fn bar() {} | 805 | fn bar() {} |