about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHongxu Xu <xuhongxu96@hotmail.com>2022-06-14 21:41:09 +0800
committerHongxu Xu <xuhongxu96@hotmail.com>2022-06-14 21:41:09 +0800
commitd7eebd9706ebc48fc4c6e09249dc45baa9e1dc61 (patch)
tree28713759ca1ef6bf898085faf94b6fd83a2a548f
parent366bd7242ed00c65f293497a26eb81c7510ac682 (diff)
downloadrust-d7eebd9706ebc48fc4c6e09249dc45baa9e1dc61.tar.gz
rust-d7eebd9706ebc48fc4c6e09249dc45baa9e1dc61.zip
add test cases to complete fn generated by macro in pub trait
-rw-r--r--crates/ide-completion/src/tests/special.rs111
1 files changed, 110 insertions, 1 deletions
diff --git a/crates/ide-completion/src/tests/special.rs b/crates/ide-completion/src/tests/special.rs
index 6195537a18e..8231336237e 100644
--- a/crates/ide-completion/src/tests/special.rs
+++ b/crates/ide-completion/src/tests/special.rs
@@ -2,13 +2,21 @@
 
 use expect_test::{expect, Expect};
 
-use crate::tests::{check_edit, completion_list_no_kw};
+use crate::{
+    tests::{check_edit, completion_list_no_kw, completion_list_with_config, TEST_CONFIG},
+    CompletionConfig,
+};
 
 fn check(ra_fixture: &str, expect: Expect) {
     let actual = completion_list_no_kw(ra_fixture);
     expect.assert_eq(&actual)
 }
 
+fn check_with_config(config: CompletionConfig, ra_fixture: &str, expect: Expect) {
+    let actual = completion_list_with_config(config, ra_fixture, true, None);
+    expect.assert_eq(&actual)
+}
+
 #[test]
 fn completes_if_prefix_is_keyword() {
     check_edit(
@@ -636,3 +644,104 @@ fn bar() -> Bar {
             "#]],
     )
 }
+
+#[test]
+fn completes_fn_in_pub_trait_generated_by_macro() {
+    let mut config = TEST_CONFIG.clone();
+    config.enable_private_editable = false;
+
+    check_with_config(
+        config,
+        r#"
+mod other_mod {
+    macro_rules! make_method {
+        ($name:ident) => {
+            fn $name(&self) {}
+        };
+    }
+
+    pub trait MyTrait {
+        make_method! { by_macro }
+        fn not_by_macro(&self) {}
+    }
+
+    pub struct Foo {}
+
+    impl MyTrait for Foo {}
+}
+
+fn main() {
+    use other_mod::{Foo, MyTrait};
+    let f = Foo {};
+    f.$0
+}
+"#,
+        expect![[r#"
+            me by_macro() (as MyTrait) fn(&self)
+            me not_by_macro() (as MyTrait) fn(&self)
+            sn box                    Box::new(expr)
+            sn call                   function(expr)
+            sn dbg                    dbg!(expr)
+            sn dbgr                   dbg!(&expr)
+            sn let                    let
+            sn letm                   let mut
+            sn match                  match expr {}
+            sn ref                    &expr
+            sn refm                   &mut expr
+        "#]],
+    )
+}
+
+
+#[test]
+fn completes_fn_in_pub_trait_generated_by_recursive_macro() {
+    let mut config = TEST_CONFIG.clone();
+    config.enable_private_editable = false;
+
+    check_with_config(
+        config,
+        r#"
+mod other_mod {
+    macro_rules! make_method {
+        ($name:ident) => {
+            fn $name(&self) {}
+        };
+    }
+
+    macro_rules! make_trait {
+        () => {
+            pub trait MyTrait {
+                make_method! { by_macro }
+                fn not_by_macro(&self) {}
+            }
+        }
+    }
+
+    make_trait!();
+
+    pub struct Foo {}
+
+    impl MyTrait for Foo {}
+}
+
+fn main() {
+    use other_mod::{Foo, MyTrait};
+    let f = Foo {};
+    f.$0
+}
+"#,
+        expect![[r#"
+            me by_macro() (as MyTrait) fn(&self)
+            me not_by_macro() (as MyTrait) fn(&self)
+            sn box                    Box::new(expr)
+            sn call                   function(expr)
+            sn dbg                    dbg!(expr)
+            sn dbgr                   dbg!(&expr)
+            sn let                    let
+            sn letm                   let mut
+            sn match                  match expr {}
+            sn ref                    &expr
+            sn refm                   &mut expr
+        "#]],
+    )
+}
\ No newline at end of file