diff options
author | David Lattimore <[email protected]> | 2020-06-23 09:59:18 +0100 |
---|---|---|
committer | David Lattimore <[email protected]> | 2020-06-27 02:33:00 +0100 |
commit | f4dc54958257ad33fe182d600c418591341c86dd (patch) | |
tree | a250def8c836e089a6b296db9502f24a45c92061 /crates/ra_ssr/src/tests.rs | |
parent | 9a4d02faf9c47f401b8756c3f7fcab2198f5f9cd (diff) |
SSR: Allow matching within macro calls
Diffstat (limited to 'crates/ra_ssr/src/tests.rs')
-rw-r--r-- | crates/ra_ssr/src/tests.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/crates/ra_ssr/src/tests.rs b/crates/ra_ssr/src/tests.rs index 3ee1e74e9..d7e6d817a 100644 --- a/crates/ra_ssr/src/tests.rs +++ b/crates/ra_ssr/src/tests.rs | |||
@@ -355,6 +355,18 @@ fn match_nested_method_calls() { | |||
355 | ); | 355 | ); |
356 | } | 356 | } |
357 | 357 | ||
358 | // Make sure that our node matching semantics don't differ within macro calls. | ||
359 | #[test] | ||
360 | fn match_nested_method_calls_with_macro_call() { | ||
361 | assert_matches( | ||
362 | "$a.z().z().z()", | ||
363 | r#" | ||
364 | macro_rules! m1 { ($a:expr) => {$a}; } | ||
365 | fn f() {m1!(h().i().j().z().z().z().d().e())}"#, | ||
366 | &["h().i().j().z().z().z()"], | ||
367 | ); | ||
368 | } | ||
369 | |||
358 | #[test] | 370 | #[test] |
359 | fn match_complex_expr() { | 371 | fn match_complex_expr() { |
360 | let code = "fn f() -> i32 {foo(bar(40, 2), 42)}"; | 372 | let code = "fn f() -> i32 {foo(bar(40, 2), 42)}"; |
@@ -547,3 +559,40 @@ fn multiple_rules() { | |||
547 | "fn f() -> i32 {add_one(add(3, 2))}", | 559 | "fn f() -> i32 {add_one(add(3, 2))}", |
548 | ) | 560 | ) |
549 | } | 561 | } |
562 | |||
563 | #[test] | ||
564 | fn match_within_macro_invocation() { | ||
565 | let code = r#" | ||
566 | macro_rules! foo { | ||
567 | ($a:stmt; $b:expr) => { | ||
568 | $b | ||
569 | }; | ||
570 | } | ||
571 | struct A {} | ||
572 | impl A { | ||
573 | fn bar() {} | ||
574 | } | ||
575 | fn f1() { | ||
576 | let aaa = A {}; | ||
577 | foo!(macro_ignores_this(); aaa.bar()); | ||
578 | } | ||
579 | "#; | ||
580 | assert_matches("$a.bar()", code, &["aaa.bar()"]); | ||
581 | } | ||
582 | |||
583 | #[test] | ||
584 | fn replace_within_macro_expansion() { | ||
585 | assert_ssr_transform( | ||
586 | "$a.foo() ==>> bar($a)", | ||
587 | r#" | ||
588 | macro_rules! macro1 { | ||
589 | ($a:expr) => {$a} | ||
590 | } | ||
591 | fn f() {macro1!(5.x().foo().o2())}"#, | ||
592 | r#" | ||
593 | macro_rules! macro1 { | ||
594 | ($a:expr) => {$a} | ||
595 | } | ||
596 | fn f() {macro1!(bar(5.x()).o2())}"#, | ||
597 | ) | ||
598 | } | ||