Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/tests/expression.rs')
-rw-r--r--crates/ide-completion/src/tests/expression.rs469
1 files changed, 468 insertions, 1 deletions
diff --git a/crates/ide-completion/src/tests/expression.rs b/crates/ide-completion/src/tests/expression.rs
index ea1b7ad787..3046614868 100644
--- a/crates/ide-completion/src/tests/expression.rs
+++ b/crates/ide-completion/src/tests/expression.rs
@@ -1,13 +1,30 @@
//! Completion tests for expressions.
use expect_test::{expect, Expect};
-use crate::tests::{check_edit, check_empty, completion_list, BASE_ITEMS_FIXTURE};
+use crate::{
+ config::AutoImportExclusionType,
+ tests::{
+ check_edit, check_empty, completion_list, completion_list_with_config, BASE_ITEMS_FIXTURE,
+ TEST_CONFIG,
+ },
+ CompletionConfig,
+};
fn check(ra_fixture: &str, expect: Expect) {
let actual = completion_list(&format!("{BASE_ITEMS_FIXTURE}{ra_fixture}"));
expect.assert_eq(&actual)
}
+fn check_with_config(config: CompletionConfig<'_>, ra_fixture: &str, expect: Expect) {
+ let actual = completion_list_with_config(
+ config,
+ &format!("{BASE_ITEMS_FIXTURE}{ra_fixture}"),
+ true,
+ None,
+ );
+ expect.assert_eq(&actual)
+}
+
#[test]
fn complete_literal_struct_with_a_private_field() {
// `FooDesc.bar` is private, the completion should not be triggered.
@@ -1390,3 +1407,453 @@ fn main() {
"#]],
);
}
+
+#[test]
+fn excluded_trait_method_is_excluded() {
+ check_with_config(
+ CompletionConfig { exclude_traits: &["test::ExcludedTrait".to_owned()], ..TEST_CONFIG },
+ r#"
+trait ExcludedTrait {
+ fn foo(&self) {}
+ fn bar(&self) {}
+ fn baz(&self) {}
+}
+
+impl<T> ExcludedTrait for T {}
+
+struct Foo;
+impl Foo {
+ fn inherent(&self) {}
+}
+
+fn foo() {
+ Foo.$0
+}
+ "#,
+ expect![[r#"
+ me bar() (as ExcludedTrait) fn(&self)
+ me baz() (as ExcludedTrait) fn(&self)
+ me foo() (as ExcludedTrait) fn(&self)
+ me inherent() fn(&self)
+ sn box Box::new(expr)
+ sn call function(expr)
+ sn dbg dbg!(expr)
+ sn dbgr dbg!(&expr)
+ sn deref *expr
+ sn let let
+ sn letm let mut
+ sn match match expr {}
+ sn ref &expr
+ sn refm &mut expr
+ sn return return expr
+ sn unsafe unsafe {}
+ "#]],
+ );
+}
+
+#[test]
+fn excluded_trait_not_excluded_when_inherent() {
+ check_with_config(
+ CompletionConfig { exclude_traits: &["test::ExcludedTrait".to_owned()], ..TEST_CONFIG },
+ r#"
+trait ExcludedTrait {
+ fn foo(&self) {}
+ fn bar(&self) {}
+ fn baz(&self) {}
+}
+
+impl<T> ExcludedTrait for T {}
+
+fn foo(v: &dyn ExcludedTrait) {
+ v.$0
+}
+ "#,
+ expect![[r#"
+ me bar() (as ExcludedTrait) fn(&self)
+ me baz() (as ExcludedTrait) fn(&self)
+ me foo() (as ExcludedTrait) fn(&self)
+ sn box Box::new(expr)
+ sn call function(expr)
+ sn dbg dbg!(expr)
+ sn dbgr dbg!(&expr)
+ sn deref *expr
+ sn let let
+ sn letm let mut
+ sn match match expr {}
+ sn ref &expr
+ sn refm &mut expr
+ sn return return expr
+ sn unsafe unsafe {}
+ "#]],
+ );
+ check_with_config(
+ CompletionConfig { exclude_traits: &["test::ExcludedTrait".to_owned()], ..TEST_CONFIG },
+ r#"
+trait ExcludedTrait {
+ fn foo(&self) {}
+ fn bar(&self) {}
+ fn baz(&self) {}
+}
+
+impl<T> ExcludedTrait for T {}
+
+fn foo(v: impl ExcludedTrait) {
+ v.$0
+}
+ "#,
+ expect![[r#"
+ me bar() (as ExcludedTrait) fn(&self)
+ me baz() (as ExcludedTrait) fn(&self)
+ me foo() (as ExcludedTrait) fn(&self)
+ sn box Box::new(expr)
+ sn call function(expr)
+ sn dbg dbg!(expr)
+ sn dbgr dbg!(&expr)
+ sn deref *expr
+ sn let let
+ sn letm let mut
+ sn match match expr {}
+ sn ref &expr
+ sn refm &mut expr
+ sn return return expr
+ sn unsafe unsafe {}
+ "#]],
+ );
+ check_with_config(
+ CompletionConfig { exclude_traits: &["test::ExcludedTrait".to_owned()], ..TEST_CONFIG },
+ r#"
+trait ExcludedTrait {
+ fn foo(&self) {}
+ fn bar(&self) {}
+ fn baz(&self) {}
+}
+
+impl<T> ExcludedTrait for T {}
+
+fn foo<T: ExcludedTrait>(v: T) {
+ v.$0
+}
+ "#,
+ expect![[r#"
+ me bar() (as ExcludedTrait) fn(&self)
+ me baz() (as ExcludedTrait) fn(&self)
+ me foo() (as ExcludedTrait) fn(&self)
+ sn box Box::new(expr)
+ sn call function(expr)
+ sn dbg dbg!(expr)
+ sn dbgr dbg!(&expr)
+ sn deref *expr
+ sn let let
+ sn letm let mut
+ sn match match expr {}
+ sn ref &expr
+ sn refm &mut expr
+ sn return return expr
+ sn unsafe unsafe {}
+ "#]],
+ );
+}
+
+#[test]
+fn excluded_trait_method_is_excluded_from_flyimport() {
+ check_with_config(
+ CompletionConfig {
+ exclude_traits: &["test::module2::ExcludedTrait".to_owned()],
+ ..TEST_CONFIG
+ },
+ r#"
+mod module2 {
+ pub trait ExcludedTrait {
+ fn foo(&self) {}
+ fn bar(&self) {}
+ fn baz(&self) {}
+ }
+
+ impl<T> ExcludedTrait for T {}
+}
+
+struct Foo;
+impl Foo {
+ fn inherent(&self) {}
+}
+
+fn foo() {
+ Foo.$0
+}
+ "#,
+ expect![[r#"
+ me bar() (use module2::ExcludedTrait) fn(&self)
+ me baz() (use module2::ExcludedTrait) fn(&self)
+ me foo() (use module2::ExcludedTrait) fn(&self)
+ me inherent() fn(&self)
+ sn box Box::new(expr)
+ sn call function(expr)
+ sn dbg dbg!(expr)
+ sn dbgr dbg!(&expr)
+ sn deref *expr
+ sn let let
+ sn letm let mut
+ sn match match expr {}
+ sn ref &expr
+ sn refm &mut expr
+ sn return return expr
+ sn unsafe unsafe {}
+ "#]],
+ );
+}
+
+#[test]
+fn flyimport_excluded_trait_method_is_excluded_from_flyimport() {
+ check_with_config(
+ CompletionConfig {
+ exclude_flyimport: vec![(
+ "test::module2::ExcludedTrait".to_owned(),
+ AutoImportExclusionType::Methods,
+ )],
+ ..TEST_CONFIG
+ },
+ r#"
+mod module2 {
+ pub trait ExcludedTrait {
+ fn foo(&self) {}
+ fn bar(&self) {}
+ fn baz(&self) {}
+ }
+
+ impl<T> ExcludedTrait for T {}
+}
+
+struct Foo;
+impl Foo {
+ fn inherent(&self) {}
+}
+
+fn foo() {
+ Foo.$0
+}
+ "#,
+ expect![[r#"
+ me bar() (use module2::ExcludedTrait) fn(&self)
+ me baz() (use module2::ExcludedTrait) fn(&self)
+ me foo() (use module2::ExcludedTrait) fn(&self)
+ me inherent() fn(&self)
+ sn box Box::new(expr)
+ sn call function(expr)
+ sn dbg dbg!(expr)
+ sn dbgr dbg!(&expr)
+ sn deref *expr
+ sn let let
+ sn letm let mut
+ sn match match expr {}
+ sn ref &expr
+ sn refm &mut expr
+ sn return return expr
+ sn unsafe unsafe {}
+ "#]],
+ );
+}
+
+#[test]
+fn excluded_trait_method_is_excluded_from_path_completion() {
+ check_with_config(
+ CompletionConfig { exclude_traits: &["test::ExcludedTrait".to_owned()], ..TEST_CONFIG },
+ r#"
+pub trait ExcludedTrait {
+ fn foo(&self) {}
+ fn bar(&self) {}
+ fn baz(&self) {}
+}
+
+impl<T> ExcludedTrait for T {}
+
+struct Foo;
+impl Foo {
+ fn inherent(&self) {}
+}
+
+fn foo() {
+ Foo::$0
+}
+ "#,
+ expect![[r#"
+ me bar(…) (as ExcludedTrait) fn(&self)
+ me baz(…) (as ExcludedTrait) fn(&self)
+ me foo(…) (as ExcludedTrait) fn(&self)
+ me inherent(…) fn(&self)
+ "#]],
+ );
+}
+
+#[test]
+fn excluded_trait_method_is_not_excluded_when_trait_is_specified() {
+ check_with_config(
+ CompletionConfig { exclude_traits: &["test::ExcludedTrait".to_owned()], ..TEST_CONFIG },
+ r#"
+pub trait ExcludedTrait {
+ fn foo(&self) {}
+ fn bar(&self) {}
+ fn baz(&self) {}
+}
+
+impl<T> ExcludedTrait for T {}
+
+struct Foo;
+impl Foo {
+ fn inherent(&self) {}
+}
+
+fn foo() {
+ ExcludedTrait::$0
+}
+ "#,
+ expect![[r#"
+ me bar(…) (as ExcludedTrait) fn(&self)
+ me baz(…) (as ExcludedTrait) fn(&self)
+ me foo(…) (as ExcludedTrait) fn(&self)
+ "#]],
+ );
+ check_with_config(
+ CompletionConfig { exclude_traits: &["test::ExcludedTrait".to_owned()], ..TEST_CONFIG },
+ r#"
+pub trait ExcludedTrait {
+ fn foo(&self) {}
+ fn bar(&self) {}
+ fn baz(&self) {}
+}
+
+impl<T> ExcludedTrait for T {}
+
+struct Foo;
+impl Foo {
+ fn inherent(&self) {}
+}
+
+fn foo() {
+ <Foo as ExcludedTrait>::$0
+}
+ "#,
+ expect![[r#"
+ me bar(…) (as ExcludedTrait) fn(&self)
+ me baz(…) (as ExcludedTrait) fn(&self)
+ me foo(…) (as ExcludedTrait) fn(&self)
+ "#]],
+ );
+}
+
+#[test]
+fn excluded_trait_not_excluded_when_inherent_path() {
+ check_with_config(
+ CompletionConfig { exclude_traits: &["test::ExcludedTrait".to_owned()], ..TEST_CONFIG },
+ r#"
+trait ExcludedTrait {
+ fn foo(&self) {}
+ fn bar(&self) {}
+ fn baz(&self) {}
+}
+
+impl<T> ExcludedTrait for T {}
+
+fn foo() {
+ <dyn ExcludedTrait>::$0
+}
+ "#,
+ expect![[r#"
+ me bar(…) (as ExcludedTrait) fn(&self)
+ me baz(…) (as ExcludedTrait) fn(&self)
+ me foo(…) (as ExcludedTrait) fn(&self)
+ "#]],
+ );
+ check_with_config(
+ CompletionConfig { exclude_traits: &["test::ExcludedTrait".to_owned()], ..TEST_CONFIG },
+ r#"
+trait ExcludedTrait {
+ fn foo(&self) {}
+ fn bar(&self) {}
+ fn baz(&self) {}
+}
+
+impl<T> ExcludedTrait for T {}
+
+fn foo<T: ExcludedTrait>() {
+ T::$0
+}
+ "#,
+ expect![[r#"
+ me bar(…) (as ExcludedTrait) fn(&self)
+ me baz(…) (as ExcludedTrait) fn(&self)
+ me foo(…) (as ExcludedTrait) fn(&self)
+ "#]],
+ );
+}
+
+#[test]
+fn hide_ragennew_synthetic_identifiers() {
+ check_empty(
+ r#"
+//- minicore: iterator
+fn bar() {
+ for i in [0; 10] {
+ r$0
+ }
+}
+ "#,
+ expect![[r#"
+ en Option Option<{unknown}>
+ en Result Result<{unknown}, {unknown}>
+ fn bar() fn()
+ lc i i32
+ ma const_format_args!(…) macro_rules! const_format_args
+ ma format_args!(…) macro_rules! format_args
+ ma format_args_nl!(…) macro_rules! format_args_nl
+ ma panic!(…) macro_rules! panic
+ ma print!(…) macro_rules! print
+ md core
+ md result (use core::result)
+ md rust_2015 (use core::prelude::rust_2015)
+ md rust_2018 (use core::prelude::rust_2018)
+ md rust_2021 (use core::prelude::rust_2021)
+ tt Clone
+ tt Copy
+ tt IntoIterator
+ tt Iterator
+ ta Result (use core::fmt::Result)
+ ev Err(…) Err(E)
+ ev None None
+ ev Ok(…) Ok(T)
+ ev Some(…) Some(T)
+ bt u32 u32
+ kw async
+ kw break
+ kw const
+ kw continue
+ kw crate::
+ kw enum
+ kw extern
+ kw false
+ kw fn
+ kw for
+ kw if
+ kw if let
+ kw impl
+ kw let
+ kw loop
+ kw match
+ kw mod
+ kw return
+ kw self::
+ kw static
+ kw struct
+ kw trait
+ kw true
+ kw type
+ kw union
+ kw unsafe
+ kw use
+ kw while
+ kw while let
+ sn macro_rules
+ sn pd
+ sn ppd
+ "#]],
+ );
+}