aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ssr/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ssr/src/tests.rs')
-rw-r--r--crates/ra_ssr/src/tests.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/crates/ra_ssr/src/tests.rs b/crates/ra_ssr/src/tests.rs
index 4b747fe18..3ee1e74e9 100644
--- a/crates/ra_ssr/src/tests.rs
+++ b/crates/ra_ssr/src/tests.rs
@@ -427,6 +427,45 @@ fn match_reordered_struct_instantiation() {
427} 427}
428 428
429#[test] 429#[test]
430fn match_macro_invocation() {
431 assert_matches("foo!($a)", "fn() {foo(foo!(foo()))}", &["foo!(foo())"]);
432 assert_matches("foo!(41, $a, 43)", "fn() {foo!(41, 42, 43)}", &["foo!(41, 42, 43)"]);
433 assert_no_match("foo!(50, $a, 43)", "fn() {foo!(41, 42, 43}");
434 assert_no_match("foo!(41, $a, 50)", "fn() {foo!(41, 42, 43}");
435 assert_matches("foo!($a())", "fn() {foo!(bar())}", &["foo!(bar())"]);
436}
437
438// When matching within a macro expansion, we only allow matches of nodes that originated from
439// the macro call, not from the macro definition.
440#[test]
441fn no_match_expression_from_macro() {
442 assert_no_match(
443 "$a.clone()",
444 r#"
445 macro_rules! m1 {
446 () => {42.clone()}
447 }
448 fn f1() {m1!()}
449 "#,
450 );
451}
452
453// We definitely don't want to allow matching of an expression that part originates from the
454// macro call `42` and part from the macro definition `.clone()`.
455#[test]
456fn no_match_split_expression() {
457 assert_no_match(
458 "$a.clone()",
459 r#"
460 macro_rules! m1 {
461 ($x:expr) => {$x.clone()}
462 }
463 fn f1() {m1!(42)}
464 "#,
465 );
466}
467
468#[test]
430fn replace_function_call() { 469fn replace_function_call() {
431 assert_ssr_transform("foo() ==>> bar()", "fn f1() {foo(); foo();}", "fn f1() {bar(); bar();}"); 470 assert_ssr_transform("foo() ==>> bar()", "fn f1() {foo(); foo();}", "fn f1() {bar(); bar();}");
432} 471}
@@ -468,6 +507,20 @@ fn replace_struct_init() {
468} 507}
469 508
470#[test] 509#[test]
510fn replace_macro_invocations() {
511 assert_ssr_transform(
512 "try!($a) ==>> $a?",
513 "fn f1() -> Result<(), E> {bar(try!(foo()));}",
514 "fn f1() -> Result<(), E> {bar(foo()?);}",
515 );
516 assert_ssr_transform(
517 "foo!($a($b)) ==>> foo($b, $a)",
518 "fn f1() {foo!(abc(def() + 2));}",
519 "fn f1() {foo(def() + 2, abc);}",
520 );
521}
522
523#[test]
471fn replace_binary_op() { 524fn replace_binary_op() {
472 assert_ssr_transform( 525 assert_ssr_transform(
473 "$a + $b ==>> $b + $a", 526 "$a + $b ==>> $b + $a",