diff options
author | David Lattimore <[email protected]> | 2020-07-22 07:00:57 +0100 |
---|---|---|
committer | David Lattimore <[email protected]> | 2020-07-24 12:34:00 +0100 |
commit | 699619a65cf816b927fffa77b2b38f611d8460bc (patch) | |
tree | 0589a97a9ee75458df3f9b7bb647089c57d7ca3e | |
parent | 6fcaaa1201c650ce22b71160f6e9bf2288d10a1a (diff) |
SSR: Add a couple of tests for non-recursive search
These tests already pass, however once we switch to non-recursive
search, it'd be easy for these tests to not pass.
-rw-r--r-- | crates/ra_ssr/src/tests.rs | 33 |
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] |
589 | fn 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] | ||
589 | fn preserves_whitespace_within_macro_expansion() { | 610 | fn 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] | ||
657 | fn 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 | } | ||