aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/assists
diff options
context:
space:
mode:
authorFelix Kohlgrüber <[email protected]>2019-11-20 18:01:06 +0000
committerFelix Kohlgrüber <[email protected]>2019-11-20 18:01:06 +0000
commitbcb2ea912bf96f38505c67a0b6896c6a5ac278ed (patch)
tree41a304a33955dd12d1f0ec127a80551367c8ffa0 /crates/ra_assists/src/assists
parent7a5fd1f3f3c4a8f64407f9bd08a3d5e7f79417e0 (diff)
fix 2190; add test for "replace if let with match"
Diffstat (limited to 'crates/ra_assists/src/assists')
-rw-r--r--crates/ra_assists/src/assists/replace_if_let_with_match.rs32
1 files changed, 30 insertions, 2 deletions
diff --git a/crates/ra_assists/src/assists/replace_if_let_with_match.rs b/crates/ra_assists/src/assists/replace_if_let_with_match.rs
index dff84d865..3272801ff 100644
--- a/crates/ra_assists/src/assists/replace_if_let_with_match.rs
+++ b/crates/ra_assists/src/assists/replace_if_let_with_match.rs
@@ -66,8 +66,8 @@ fn build_match_expr(
66 66
67fn format_arm(block: &ast::BlockExpr) -> String { 67fn format_arm(block: &ast::BlockExpr) -> String {
68 match extract_trivial_expression(block) { 68 match extract_trivial_expression(block) {
69 None => block.syntax().text().to_string(), 69 Some(e) if !e.syntax().text().contains_char('\n') => format!("{},", e.syntax().text()),
70 Some(e) => format!("{},", e.syntax().text()), 70 _ => block.syntax().text().to_string(),
71 } 71 }
72} 72}
73 73
@@ -103,6 +103,34 @@ impl VariantData {
103 } 103 }
104 104
105 #[test] 105 #[test]
106 fn test_replace_if_let_with_match_doesnt_unwrap_multiline_expressions() {
107 check_assist(
108 replace_if_let_with_match,
109 "
110fn foo() {
111 if <|>let VariantData::Struct(..) = a {
112 bar(
113 123
114 )
115 } else {
116 false
117 }
118} ",
119 "
120fn foo() {
121 <|>match a {
122 VariantData::Struct(..) => {
123 bar(
124 123
125 )
126 }
127 _ => false,
128 }
129} ",
130 )
131 }
132
133 #[test]
106 fn replace_if_let_with_match_target() { 134 fn replace_if_let_with_match_target() {
107 check_assist_target( 135 check_assist_target(
108 replace_if_let_with_match, 136 replace_if_let_with_match,