diff --git a/crates/ide_completion/src/completions/record.rs b/crates/ide_completion/src/completions/record.rs index c7b8ba3d14..c7cf5e3e4b 100644 --- a/crates/ide_completion/src/completions/record.rs +++ b/crates/ide_completion/src/completions/record.rs @@ -44,3 +44,77 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Some(()) } + +#[cfg(test)] +mod tests { + + use crate::tests::check_edit; + + #[test] + fn default_completion_edit() { + check_edit( + "..Default::default()", + r#" +//- minicore: default +struct Struct { foo: u32, bar: usize } + +impl Default for Struct { + fn default() -> Self {} +} + +fn foo() { + let other = Struct { + foo: 5, + .$0 + }; +} +"#, + r#" +struct Struct { foo: u32, bar: usize } + +impl Default for Struct { + fn default() -> Self {} +} + +fn foo() { + let other = Struct { + foo: 5, + ..Default::default() + }; +} +"#, + ); + check_edit( + "..Default::default()", + r#" +//- minicore: default +struct Struct { foo: u32, bar: usize } + +impl Default for Struct { + fn default() -> Self {} +} + +fn foo() { + let other = Struct { + foo: 5, + $0 + }; +} +"#, + r#" +struct Struct { foo: u32, bar: usize } + +impl Default for Struct { + fn default() -> Self {} +} + +fn foo() { + let other = Struct { + foo: 5, + ..Default::default() + }; +} +"#, + ); + } +} diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs index cbc20cc2c3..6237a6ef1e 100644 --- a/crates/ide_completion/src/completions/snippet.rs +++ b/crates/ide_completion/src/completions/snippet.rs @@ -108,10 +108,4 @@ mod tests { "#]], ); } - - #[test] - fn should_not_complete_snippets_in_path() { - check(r#"fn foo(x: i32) { ::foo$0 }"#, expect![[""]]); - check(r#"fn foo(x: i32) { ::$0 }"#, expect![[""]]); - } } diff --git a/crates/ide_completion/src/completions/trait_impl.rs b/crates/ide_completion/src/completions/trait_impl.rs index 65f0f38430..3713be0a17 100644 --- a/crates/ide_completion/src/completions/trait_impl.rs +++ b/crates/ide_completion/src/completions/trait_impl.rs @@ -299,29 +299,6 @@ mod tests { expect.assert_eq(&actual) } - #[test] - fn name_ref_function_type_const() { - check( - r#" -trait Test { - type TestType; - const TEST_CONST: u16; - fn test(); -} -struct T; - -impl Test for T { - t$0 -} -"#, - expect![[" -ta type TestType = \n\ -ct const TEST_CONST: u16 = \n\ -fn fn test() -"]], - ); - } - #[test] fn no_completion_inside_fn() { check( @@ -572,27 +549,6 @@ impl Test for T { ); } - #[test] - fn hide_implemented_fn() { - check( - r#" -trait Test { - fn foo(); - fn foo_bar(); -} -struct T; - -impl Test for T { - fn foo() {} - fn f$0 -} -"#, - expect![[r#" - fn fn foo_bar() - "#]], - ); - } - #[test] fn generic_fn() { check_edit( diff --git a/crates/ide_completion/src/tests.rs b/crates/ide_completion/src/tests.rs index 1eec2c113e..cd812b617e 100644 --- a/crates/ide_completion/src/tests.rs +++ b/crates/ide_completion/src/tests.rs @@ -3,6 +3,9 @@ //! Most tests live in this module or its submodules unless for very specific completions like //! `attributes` or `lifetimes` where the completed concept is a distinct thing. //! Notable examples for completions that are being tested in this module's submodule are paths. +//! Another exception are `check_edit` tests which usually live in the completion modules themselves, +//! as the main purpose of this test module here is to give the developer an overview of whats being +//! completed where, not how. mod attribute; mod fn_param; diff --git a/crates/ide_completion/src/tests/item_list.rs b/crates/ide_completion/src/tests/item_list.rs index a170616f55..1c1915ffbd 100644 --- a/crates/ide_completion/src/tests/item_list.rs +++ b/crates/ide_completion/src/tests/item_list.rs @@ -210,3 +210,40 @@ fn in_trait_assoc_item_list() { "##]], ); } + +#[test] +fn in_trait_impl_assoc_item_list() { + check( + r#" +trait Test { + type Type0; + type Type1; + const CONST0: (); + const CONST1: (); + fn function0(); + fn function1(); +} + +impl Test for () { + type Type0 = (); + const CONST0: () = (); + fn function0() {} + $0 +} +"#, + expect![[r##" + kw pub(crate) + kw pub + kw unsafe + kw fn + kw const + kw type + kw self + kw super + kw crate + md module + ma makro!(…) #[macro_export] macro_rules! makro + ma makro!(…) #[macro_export] macro_rules! makro + "##]], + ); +} diff --git a/crates/ide_completion/src/tests/record.rs b/crates/ide_completion/src/tests/record.rs index fa5f3fe46e..db3e315307 100644 --- a/crates/ide_completion/src/tests/record.rs +++ b/crates/ide_completion/src/tests/record.rs @@ -1,6 +1,6 @@ use expect_test::{expect, Expect}; -use crate::tests::{check_edit, completion_list}; +use crate::tests::completion_list; fn check(ra_fixture: &str, expect: Expect) { let actual = completion_list(ra_fixture); @@ -162,71 +162,3 @@ fn main() { "#]], ); } - -#[test] -fn default_completion_edit() { - check_edit( - "..Default::default()", - r#" -//- minicore: default -struct Struct { foo: u32, bar: usize } - -impl Default for Struct { - fn default() -> Self {} -} - -fn foo() { - let other = Struct { - foo: 5, - .$0 - }; -} -"#, - r#" -struct Struct { foo: u32, bar: usize } - -impl Default for Struct { - fn default() -> Self {} -} - -fn foo() { - let other = Struct { - foo: 5, - ..Default::default() - }; -} -"#, - ); - check_edit( - "..Default::default()", - r#" -//- minicore: default -struct Struct { foo: u32, bar: usize } - -impl Default for Struct { - fn default() -> Self {} -} - -fn foo() { - let other = Struct { - foo: 5, - $0 - }; -} -"#, - r#" -struct Struct { foo: u32, bar: usize } - -impl Default for Struct { - fn default() -> Self {} -} - -fn foo() { - let other = Struct { - foo: 5, - ..Default::default() - }; -} -"#, - ); -}