aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ssr/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ssr/src')
-rw-r--r--crates/ra_ssr/src/tests.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/crates/ra_ssr/src/tests.rs b/crates/ra_ssr/src/tests.rs
index 11512c8cc..523035b31 100644
--- a/crates/ra_ssr/src/tests.rs
+++ b/crates/ra_ssr/src/tests.rs
@@ -586,6 +586,27 @@ fn replace_within_macro_expansion() {
586} 586}
587 587
588#[test] 588#[test]
589fn replace_outside_and_within_macro_expansion() {
590 assert_ssr_transform(
591 "foo($a) ==>> bar($a)",
592 r#"
593 fn foo() {} fn bar() {}
594 macro_rules! macro1 {
595 ($a:expr) => {$a}
596 }
597 fn f() {foo(foo(macro1!(foo(foo(42)))))}
598 "#,
599 expect![[r#"
600 fn foo() {} fn bar() {}
601 macro_rules! macro1 {
602 ($a:expr) => {$a}
603 }
604 fn f() {bar(bar(macro1!(bar(bar(42)))))}
605 "#]],
606 )
607}
608
609#[test]
589fn preserves_whitespace_within_macro_expansion() { 610fn preserves_whitespace_within_macro_expansion() {
590 assert_ssr_transform( 611 assert_ssr_transform(
591 "$a + $b ==>> $b - $a", 612 "$a + $b ==>> $b - $a",
@@ -631,3 +652,15 @@ fn match_failure_reasons() {
631 r#"Pattern wanted token '42' (INT_NUMBER), but code had token '43' (INT_NUMBER)"#, 652 r#"Pattern wanted token '42' (INT_NUMBER), but code had token '43' (INT_NUMBER)"#,
632 ); 653 );
633} 654}
655
656#[test]
657fn overlapping_possible_matches() {
658 // There are three possible matches here, however the middle one, `foo(foo(foo(42)))` shouldn't
659 // match because it overlaps with the outer match. The inner match is permitted since it's is
660 // contained entirely within the placeholder of the outer match.
661 assert_matches(
662 "foo(foo($a))",
663 "fn foo() {} fn main() {foo(foo(foo(foo(42))))}",
664 &["foo(foo(42))", "foo(foo(foo(foo(42))))"],
665 );
666}