@@ -209,6 +209,11 @@ fn assert_ssr_transform(rule: &str, input: &str, result: &str) {
209209 assert_ssr_transforms ( & [ rule] , input, result) ;
210210}
211211
212+ fn normalize_code ( code : & str ) -> String {
213+ let ( db, file_id) = single_file ( code) ;
214+ db. file_text ( file_id) . to_string ( )
215+ }
216+
212217fn assert_ssr_transforms ( rules : & [ & str ] , input : & str , result : & str ) {
213218 let ( db, file_id) = single_file ( input) ;
214219 let mut match_finder = MatchFinder :: new ( & db) ;
@@ -217,8 +222,13 @@ fn assert_ssr_transforms(rules: &[&str], input: &str, result: &str) {
217222 match_finder. add_rule ( rule) ;
218223 }
219224 if let Some ( edits) = match_finder. edits_for_file ( file_id) {
220- let mut after = input. to_string ( ) ;
225+ // Note, db.file_text is not necessarily the same as `input`, since fixture parsing alters
226+ // stuff.
227+ let mut after = db. file_text ( file_id) . to_string ( ) ;
221228 edits. apply ( & mut after) ;
229+ // Likewise, we need to make sure that whatever transformations fixture parsing applies,
230+ // also get appplied to our expected result.
231+ let result = normalize_code ( result) ;
222232 assert_eq ! ( after, result) ;
223233 } else {
224234 panic ! ( "No edits were made" ) ;
@@ -355,6 +365,18 @@ fn match_nested_method_calls() {
355365 ) ;
356366}
357367
368+ // Make sure that our node matching semantics don't differ within macro calls.
369+ #[ test]
370+ fn match_nested_method_calls_with_macro_call ( ) {
371+ assert_matches (
372+ "$a.z().z().z()" ,
373+ r#"
374+ macro_rules! m1 { ($a:expr) => {$a}; }
375+ fn f() {m1!(h().i().j().z().z().z().d().e())}"# ,
376+ & [ "h().i().j().z().z().z()" ] ,
377+ ) ;
378+ }
379+
358380#[ test]
359381fn match_complex_expr ( ) {
360382 let code = "fn f() -> i32 {foo(bar(40, 2), 42)}" ;
@@ -547,3 +569,40 @@ fn multiple_rules() {
547569 "fn f() -> i32 {add_one(add(3, 2))}" ,
548570 )
549571}
572+
573+ #[ test]
574+ fn match_within_macro_invocation ( ) {
575+ let code = r#"
576+ macro_rules! foo {
577+ ($a:stmt; $b:expr) => {
578+ $b
579+ };
580+ }
581+ struct A {}
582+ impl A {
583+ fn bar() {}
584+ }
585+ fn f1() {
586+ let aaa = A {};
587+ foo!(macro_ignores_this(); aaa.bar());
588+ }
589+ "# ;
590+ assert_matches ( "$a.bar()" , code, & [ "aaa.bar()" ] ) ;
591+ }
592+
593+ #[ test]
594+ fn replace_within_macro_expansion ( ) {
595+ assert_ssr_transform (
596+ "$a.foo() ==>> bar($a)" ,
597+ r#"
598+ macro_rules! macro1 {
599+ ($a:expr) => {$a}
600+ }
601+ fn f() {macro1!(5.x().foo().o2())}"# ,
602+ r#"
603+ macro_rules! macro1 {
604+ ($a:expr) => {$a}
605+ }
606+ fn f() {macro1!(bar(5.x()).o2())}"# ,
607+ )
608+ }
0 commit comments