22
33use expect_test:: { expect, Expect } ;
44
5- use crate :: tests:: { check_edit, completion_list_no_kw} ;
5+ use crate :: {
6+ tests:: { check_edit, completion_list_no_kw, completion_list_with_config, TEST_CONFIG } ,
7+ CompletionConfig ,
8+ } ;
69
710fn check ( ra_fixture : & str , expect : Expect ) {
811 let actual = completion_list_no_kw ( ra_fixture) ;
912 expect. assert_eq ( & actual)
1013}
1114
15+ fn check_with_config ( config : CompletionConfig , ra_fixture : & str , expect : Expect ) {
16+ let actual = completion_list_with_config ( config, ra_fixture, true , None ) ;
17+ expect. assert_eq ( & actual)
18+ }
19+
1220#[ test]
1321fn completes_if_prefix_is_keyword ( ) {
1422 check_edit (
@@ -636,3 +644,104 @@ fn bar() -> Bar {
636644 "# ] ] ,
637645 )
638646}
647+
648+ #[ test]
649+ fn completes_fn_in_pub_trait_generated_by_macro ( ) {
650+ let mut config = TEST_CONFIG . clone ( ) ;
651+ config. enable_private_editable = false ;
652+
653+ check_with_config (
654+ config,
655+ r#"
656+ mod other_mod {
657+ macro_rules! make_method {
658+ ($name:ident) => {
659+ fn $name(&self) {}
660+ };
661+ }
662+
663+ pub trait MyTrait {
664+ make_method! { by_macro }
665+ fn not_by_macro(&self) {}
666+ }
667+
668+ pub struct Foo {}
669+
670+ impl MyTrait for Foo {}
671+ }
672+
673+ fn main() {
674+ use other_mod::{Foo, MyTrait};
675+ let f = Foo {};
676+ f.$0
677+ }
678+ "# ,
679+ expect ! [ [ r#"
680+ me by_macro() (as MyTrait) fn(&self)
681+ me not_by_macro() (as MyTrait) fn(&self)
682+ sn box Box::new(expr)
683+ sn call function(expr)
684+ sn dbg dbg!(expr)
685+ sn dbgr dbg!(&expr)
686+ sn let let
687+ sn letm let mut
688+ sn match match expr {}
689+ sn ref &expr
690+ sn refm &mut expr
691+ "# ] ] ,
692+ )
693+ }
694+
695+
696+ #[ test]
697+ fn completes_fn_in_pub_trait_generated_by_recursive_macro ( ) {
698+ let mut config = TEST_CONFIG . clone ( ) ;
699+ config. enable_private_editable = false ;
700+
701+ check_with_config (
702+ config,
703+ r#"
704+ mod other_mod {
705+ macro_rules! make_method {
706+ ($name:ident) => {
707+ fn $name(&self) {}
708+ };
709+ }
710+
711+ macro_rules! make_trait {
712+ () => {
713+ pub trait MyTrait {
714+ make_method! { by_macro }
715+ fn not_by_macro(&self) {}
716+ }
717+ }
718+ }
719+
720+ make_trait!();
721+
722+ pub struct Foo {}
723+
724+ impl MyTrait for Foo {}
725+ }
726+
727+ fn main() {
728+ use other_mod::{Foo, MyTrait};
729+ let f = Foo {};
730+ f.$0
731+ }
732+ "# ,
733+ expect ! [ [ r#"
734+ me by_macro() (as MyTrait) fn(&self)
735+ me not_by_macro() (as MyTrait) fn(&self)
736+ sn box Box::new(expr)
737+ sn call function(expr)
738+ sn dbg dbg!(expr)
739+ sn dbgr dbg!(&expr)
740+ sn let let
741+ sn letm let mut
742+ sn match match expr {}
743+ sn ref &expr
744+ sn refm &mut expr
745+ "# ] ] ,
746+ )
747+ }
0 commit comments