From a9a77671f2405e0cb65160c17268beec5114e259 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 17 Jun 2021 15:32:34 +0200 Subject: Move item specific completion tests --- crates/ide_completion/src/completions/keyword.rs | 32 ------ crates/ide_completion/src/completions/mod_.rs | 4 +- .../src/completions/qualified_path.rs | 20 ---- .../src/completions/unqualified_path.rs | 17 ---- crates/ide_completion/src/tests.rs | 1 + crates/ide_completion/src/tests/items.rs | 108 +++++++++++++++++++++ 6 files changed, 111 insertions(+), 71 deletions(-) create mode 100644 crates/ide_completion/src/tests/items.rs (limited to 'crates/ide_completion/src') diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs index af67f9315..c5cd3c2f7 100644 --- a/crates/ide_completion/src/completions/keyword.rs +++ b/crates/ide_completion/src/completions/keyword.rs @@ -387,22 +387,6 @@ fn quux() -> i32 { ); } - #[test] - fn test_where_keyword() { - check( - r"trait A $0", - expect![[r#" - kw where - "#]], - ); - check( - r"impl A $0", - expect![[r#" - kw where - "#]], - ); - } - #[test] fn no_keyword_completion_in_comments() { cov_mark::check!(no_keyword_completion_in_comments); @@ -479,22 +463,6 @@ fn foo() { ) } - #[test] - fn before_field() { - check( - r#" -struct Foo { - $0 - pub f: i32, -} -"#, - expect![[r#" - kw pub(crate) - kw pub - "#]], - ) - } - #[test] fn skip_struct_initializer() { cov_mark::check!(no_keyword_completion_in_record_lit); diff --git a/crates/ide_completion/src/completions/mod_.rs b/crates/ide_completion/src/completions/mod_.rs index dee3ec88d..1c864c0e7 100644 --- a/crates/ide_completion/src/completions/mod_.rs +++ b/crates/ide_completion/src/completions/mod_.rs @@ -141,11 +141,11 @@ fn module_chain_to_containing_module_file( #[cfg(test)] mod tests { - use crate::{tests::filtered_completion_list, CompletionKind}; + use crate::tests::completion_list; use expect_test::{expect, Expect}; fn check(ra_fixture: &str, expect: Expect) { - let actual = filtered_completion_list(ra_fixture, CompletionKind::Magic); + let actual = completion_list(ra_fixture); expect.assert_eq(&actual); } diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index 0597879ac..88f4d940d 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs @@ -555,26 +555,6 @@ fn f() {m::$0} ); } - #[test] - fn completes_in_assoc_item_list() { - check( - r#" -#[macro_export] -macro_rules! foo { () => {} } -mod bar {} - -struct MyStruct {} -impl MyStruct { - crate::$0 -} -"#, - expect![[r##" - md bar - ma foo!(…) #[macro_export] macro_rules! foo - "##]], - ); - } - #[test] fn completes_reexported_items_under_correct_name() { check( diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index 6f96eceb9..1864bfbcc 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs @@ -712,23 +712,6 @@ fn f() {} ) } - #[test] - fn completes_target_type_or_trait_in_impl_block() { - check( - r#" -trait MyTrait {} -struct MyStruct {} - -impl My$0 -"#, - expect![[r#" - sp Self - tt MyTrait - st MyStruct - "#]], - ) - } - #[test] fn completes_types_and_const_in_arg_list() { check( diff --git a/crates/ide_completion/src/tests.rs b/crates/ide_completion/src/tests.rs index 4b7e19cc0..1ea6017ce 100644 --- a/crates/ide_completion/src/tests.rs +++ b/crates/ide_completion/src/tests.rs @@ -6,6 +6,7 @@ mod item_list; mod use_tree; +mod items; use hir::{PrefixKind, Semantics}; use ide_db::{ diff --git a/crates/ide_completion/src/tests/items.rs b/crates/ide_completion/src/tests/items.rs new file mode 100644 index 000000000..dd4ba3864 --- /dev/null +++ b/crates/ide_completion/src/tests/items.rs @@ -0,0 +1,108 @@ +//! Completions tests for item specifics overall. +//! +//! Except for use items which are tested in [super::use_tree] and mod declarations with are tested +//! in [crate::completions::mod_]. +use expect_test::{expect, Expect}; + +use crate::tests::completion_list; + +fn check(ra_fixture: &str, expect: Expect) { + let base = r#"#[rustc_builtin_macro] +pub macro Clone {} +enum Enum { Variant } +struct Struct {} +#[macro_export] +macro_rules! foo {} +mod bar {} +const CONST: () = (); +trait Trait {} +"#; + let actual = completion_list(&format!("{}{}", base, ra_fixture)); + expect.assert_eq(&actual) +} + +#[test] +fn target_type_or_trait_in_impl_block() { + // FIXME: should not complete `Self` + check( + r#" +impl My$0 +"#, + expect![[r##" + sp Self + tt Trait + en Enum + st Struct + md bar + ma foo!(…) #[macro_export] macro_rules! foo + ma foo!(…) #[macro_export] macro_rules! foo + bt u32 + bt bool + bt u8 + bt isize + bt u16 + bt u64 + bt u128 + bt f32 + bt i128 + bt i16 + bt str + bt i64 + bt char + bt f64 + bt i32 + bt i8 + bt usize + "##]], + ) +} + +#[test] +fn after_trait_name_in_trait_def() { + // FIXME: should only complete `where` + check( + r"trait A $0", + expect![[r##" + kw where + sn tmod (Test module) + sn tfn (Test function) + sn macro_rules + md bar + ma foo!(…) #[macro_export] macro_rules! foo + ma foo!(…) #[macro_export] macro_rules! foo + "##]], + ); +} + +#[test] +fn after_trait_or_target_name_in_impl() { + // FIXME: should only complete `for` and `where` + check( + r"impl A $0", + expect![[r##" + kw where + sn tmod (Test module) + sn tfn (Test function) + sn macro_rules + md bar + ma foo!(…) #[macro_export] macro_rules! foo + ma foo!(…) #[macro_export] macro_rules! foo + "##]], + ); +} + +#[test] +fn before_record_field() { + check( + r#" +struct Foo { + $0 + pub f: i32, +} +"#, + expect![[r#" + kw pub(crate) + kw pub + "#]], + ) +} -- cgit v1.2.3