aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers/introduce_variable.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/handlers/introduce_variable.rs')
-rw-r--r--crates/ra_assists/src/handlers/introduce_variable.rs60
1 files changed, 24 insertions, 36 deletions
diff --git a/crates/ra_assists/src/handlers/introduce_variable.rs b/crates/ra_assists/src/handlers/introduce_variable.rs
index 7312ce687..b453c51fb 100644
--- a/crates/ra_assists/src/handlers/introduce_variable.rs
+++ b/crates/ra_assists/src/handlers/introduce_variable.rs
@@ -136,15 +136,13 @@ fn anchor_stmt(expr: ast::Expr) -> Option<(SyntaxNode, bool)> {
136mod tests { 136mod tests {
137 use test_utils::covers; 137 use test_utils::covers;
138 138
139 use crate::helpers::{ 139 use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target};
140 check_assist_range, check_assist_range_not_applicable, check_assist_range_target,
141 };
142 140
143 use super::*; 141 use super::*;
144 142
145 #[test] 143 #[test]
146 fn test_introduce_var_simple() { 144 fn test_introduce_var_simple() {
147 check_assist_range( 145 check_assist(
148 introduce_variable, 146 introduce_variable,
149 " 147 "
150fn foo() { 148fn foo() {
@@ -161,16 +159,13 @@ fn foo() {
161 #[test] 159 #[test]
162 fn introduce_var_in_comment_is_not_applicable() { 160 fn introduce_var_in_comment_is_not_applicable() {
163 covers!(introduce_var_in_comment_is_not_applicable); 161 covers!(introduce_var_in_comment_is_not_applicable);
164 check_assist_range_not_applicable( 162 check_assist_not_applicable(introduce_variable, "fn main() { 1 + /* <|>comment<|> */ 1; }");
165 introduce_variable,
166 "fn main() { 1 + /* <|>comment<|> */ 1; }",
167 );
168 } 163 }
169 164
170 #[test] 165 #[test]
171 fn test_introduce_var_expr_stmt() { 166 fn test_introduce_var_expr_stmt() {
172 covers!(test_introduce_var_expr_stmt); 167 covers!(test_introduce_var_expr_stmt);
173 check_assist_range( 168 check_assist(
174 introduce_variable, 169 introduce_variable,
175 " 170 "
176fn foo() { 171fn foo() {
@@ -181,7 +176,7 @@ fn foo() {
181 let <|>var_name = 1 + 1; 176 let <|>var_name = 1 + 1;
182}", 177}",
183 ); 178 );
184 check_assist_range( 179 check_assist(
185 introduce_variable, 180 introduce_variable,
186 " 181 "
187fn foo() { 182fn foo() {
@@ -198,7 +193,7 @@ fn foo() {
198 193
199 #[test] 194 #[test]
200 fn test_introduce_var_part_of_expr_stmt() { 195 fn test_introduce_var_part_of_expr_stmt() {
201 check_assist_range( 196 check_assist(
202 introduce_variable, 197 introduce_variable,
203 " 198 "
204fn foo() { 199fn foo() {
@@ -215,7 +210,7 @@ fn foo() {
215 #[test] 210 #[test]
216 fn test_introduce_var_last_expr() { 211 fn test_introduce_var_last_expr() {
217 covers!(test_introduce_var_last_expr); 212 covers!(test_introduce_var_last_expr);
218 check_assist_range( 213 check_assist(
219 introduce_variable, 214 introduce_variable,
220 " 215 "
221fn foo() { 216fn foo() {
@@ -227,7 +222,7 @@ fn foo() {
227 bar(var_name) 222 bar(var_name)
228}", 223}",
229 ); 224 );
230 check_assist_range( 225 check_assist(
231 introduce_variable, 226 introduce_variable,
232 " 227 "
233fn foo() { 228fn foo() {
@@ -243,7 +238,7 @@ fn foo() {
243 238
244 #[test] 239 #[test]
245 fn test_introduce_var_in_match_arm_no_block() { 240 fn test_introduce_var_in_match_arm_no_block() {
246 check_assist_range( 241 check_assist(
247 introduce_variable, 242 introduce_variable,
248 " 243 "
249fn main() { 244fn main() {
@@ -268,7 +263,7 @@ fn main() {
268 263
269 #[test] 264 #[test]
270 fn test_introduce_var_in_match_arm_with_block() { 265 fn test_introduce_var_in_match_arm_with_block() {
271 check_assist_range( 266 check_assist(
272 introduce_variable, 267 introduce_variable,
273 " 268 "
274fn main() { 269fn main() {
@@ -300,7 +295,7 @@ fn main() {
300 295
301 #[test] 296 #[test]
302 fn test_introduce_var_in_closure_no_block() { 297 fn test_introduce_var_in_closure_no_block() {
303 check_assist_range( 298 check_assist(
304 introduce_variable, 299 introduce_variable,
305 " 300 "
306fn main() { 301fn main() {
@@ -317,7 +312,7 @@ fn main() {
317 312
318 #[test] 313 #[test]
319 fn test_introduce_var_in_closure_with_block() { 314 fn test_introduce_var_in_closure_with_block() {
320 check_assist_range( 315 check_assist(
321 introduce_variable, 316 introduce_variable,
322 " 317 "
323fn main() { 318fn main() {
@@ -334,7 +329,7 @@ fn main() {
334 329
335 #[test] 330 #[test]
336 fn test_introduce_var_path_simple() { 331 fn test_introduce_var_path_simple() {
337 check_assist_range( 332 check_assist(
338 introduce_variable, 333 introduce_variable,
339 " 334 "
340fn main() { 335fn main() {
@@ -352,7 +347,7 @@ fn main() {
352 347
353 #[test] 348 #[test]
354 fn test_introduce_var_path_method() { 349 fn test_introduce_var_path_method() {
355 check_assist_range( 350 check_assist(
356 introduce_variable, 351 introduce_variable,
357 " 352 "
358fn main() { 353fn main() {
@@ -370,7 +365,7 @@ fn main() {
370 365
371 #[test] 366 #[test]
372 fn test_introduce_var_return() { 367 fn test_introduce_var_return() {
373 check_assist_range( 368 check_assist(
374 introduce_variable, 369 introduce_variable,
375 " 370 "
376fn foo() -> u32 { 371fn foo() -> u32 {
@@ -388,7 +383,7 @@ fn foo() -> u32 {
388 383
389 #[test] 384 #[test]
390 fn test_introduce_var_does_not_add_extra_whitespace() { 385 fn test_introduce_var_does_not_add_extra_whitespace() {
391 check_assist_range( 386 check_assist(
392 introduce_variable, 387 introduce_variable,
393 " 388 "
394fn foo() -> u32 { 389fn foo() -> u32 {
@@ -407,7 +402,7 @@ fn foo() -> u32 {
407", 402",
408 ); 403 );
409 404
410 check_assist_range( 405 check_assist(
411 introduce_variable, 406 introduce_variable,
412 " 407 "
413fn foo() -> u32 { 408fn foo() -> u32 {
@@ -424,7 +419,7 @@ fn foo() -> u32 {
424", 419",
425 ); 420 );
426 421
427 check_assist_range( 422 check_assist(
428 introduce_variable, 423 introduce_variable,
429 " 424 "
430fn foo() -> u32 { 425fn foo() -> u32 {
@@ -452,7 +447,7 @@ fn foo() -> u32 {
452 447
453 #[test] 448 #[test]
454 fn test_introduce_var_break() { 449 fn test_introduce_var_break() {
455 check_assist_range( 450 check_assist(
456 introduce_variable, 451 introduce_variable,
457 " 452 "
458fn main() { 453fn main() {
@@ -474,7 +469,7 @@ fn main() {
474 469
475 #[test] 470 #[test]
476 fn test_introduce_var_for_cast() { 471 fn test_introduce_var_for_cast() {
477 check_assist_range( 472 check_assist(
478 introduce_variable, 473 introduce_variable,
479 " 474 "
480fn main() { 475fn main() {
@@ -492,27 +487,20 @@ fn main() {
492 487
493 #[test] 488 #[test]
494 fn test_introduce_var_for_return_not_applicable() { 489 fn test_introduce_var_for_return_not_applicable() {
495 check_assist_range_not_applicable(introduce_variable, "fn foo() { <|>return<|>; } "); 490 check_assist_not_applicable(introduce_variable, "fn foo() { <|>return<|>; } ");
496 } 491 }
497 492
498 #[test] 493 #[test]
499 fn test_introduce_var_for_break_not_applicable() { 494 fn test_introduce_var_for_break_not_applicable() {
500 check_assist_range_not_applicable( 495 check_assist_not_applicable(introduce_variable, "fn main() { loop { <|>break<|>; }; }");
501 introduce_variable,
502 "fn main() { loop { <|>break<|>; }; }",
503 );
504 } 496 }
505 497
506 // FIXME: This is not quite correct, but good enough(tm) for the sorting heuristic 498 // FIXME: This is not quite correct, but good enough(tm) for the sorting heuristic
507 #[test] 499 #[test]
508 fn introduce_var_target() { 500 fn introduce_var_target() {
509 check_assist_range_target( 501 check_assist_target(introduce_variable, "fn foo() -> u32 { <|>return 2 + 2<|>; }", "2 + 2");
510 introduce_variable,
511 "fn foo() -> u32 { <|>return 2 + 2<|>; }",
512 "2 + 2",
513 );
514 502
515 check_assist_range_target( 503 check_assist_target(
516 introduce_variable, 504 introduce_variable,
517 " 505 "
518fn main() { 506fn main() {