From b9d85f55b7a0a2159971b42bb5dae71efbfeada4 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 21 Jun 2021 14:59:49 +0200 Subject: Move out completion type position tests --- .../src/completions/qualified_path.rs | 76 --------- .../src/completions/unqualified_path.rs | 97 ----------- crates/ide_completion/src/tests.rs | 14 +- crates/ide_completion/src/tests/items.rs | 32 ---- crates/ide_completion/src/tests/type_pos.rs | 185 +++++++++++++++++++++ 5 files changed, 198 insertions(+), 206 deletions(-) create mode 100644 crates/ide_completion/src/tests/type_pos.rs (limited to 'crates') diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index f5dbd203b..1b8997ecf 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs @@ -218,36 +218,6 @@ mod tests { expect.assert_eq(&actual); } - #[test] - fn dont_complete_values_in_type_pos() { - check( - r#" -const FOO: () = (); -static BAR: () = (); -struct Baz; -fn foo() { - let _: self::$0; -} -"#, - expect![[r#" - st Baz - "#]], - ); - } - - #[test] - fn dont_complete_enum_variants_in_type_pos() { - check( - r#" -enum Foo { Bar } -fn foo() { - let _: Foo::$0; -} -"#, - expect![[r#""#]], - ); - } - #[test] fn dont_complete_primitive_in_use() { check_builtin(r#"use self::$0;"#, expect![[""]]); @@ -258,32 +228,6 @@ fn foo() { check_builtin(r#"fn foo() { self::$0 }"#, expect![[""]]); } - #[test] - fn completes_primitives() { - check_builtin( - r#"fn main() { let _: $0 = 92; }"#, - expect![[r#" - 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 completes_enum_variant() { check( @@ -749,24 +693,4 @@ fn main() { "#]], ); } - - #[test] - fn completes_types_and_const_in_arg_list() { - check( - r#" -mod foo { - pub const CONST: () = (); - pub type Type = (); -} - -struct Foo(t); - -fn foo(_: Foo) {} -"#, - expect![[r#" - ta Type - ct CONST - "#]], - ); - } } diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index 819fa3a43..380c1e079 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs @@ -112,28 +112,6 @@ mod tests { expect.assert_eq(&actual) } - #[test] - fn dont_complete_values_in_type_pos() { - check( - r#" -const FOO: () = (); -static BAR: () = (); -enum Foo { - Bar -} -struct Baz; -fn foo() { - let local = (); - let _: $0; -} -"#, - expect![[r#" - en Foo - st Baz - "#]], - ); - } - #[test] fn completes_bindings_from_let() { check( @@ -238,29 +216,6 @@ fn main() { ); } - #[test] - fn completes_generic_params_in_struct() { - check( - r#"struct S { x: $0}"#, - expect![[r#" - sp Self - tp T - st S<…> - "#]], - ); - } - - #[test] - fn completes_self_in_enum() { - check( - r#"enum X { Y($0) }"#, - expect![[r#" - sp Self - en X - "#]], - ); - } - #[test] fn completes_module_items() { check( @@ -314,19 +269,6 @@ mod m { ); } - #[test] - fn completes_return_type() { - check( - r#" -struct Foo; -fn x() -> $0 -"#, - expect![[r#" - st Foo - "#]], - ); - } - #[test] fn dont_show_both_completions_for_shadowing() { check( @@ -508,19 +450,6 @@ fn foo() { $0 } ); } - #[test] - fn completes_macros_as_type() { - check( - r#" -macro_rules! foo { () => {} } -fn main() { let x: $0 } -"#, - expect![[r#" - ma foo!(…) macro_rules! foo - "#]], - ); - } - #[test] fn completes_macros_as_stmt() { check( @@ -666,30 +595,4 @@ fn f() {} expect![[""]], ) } - - #[test] - fn completes_types_and_const_in_arg_list() { - check( - r#" -enum Bar { - Baz -} -trait Foo { - type Bar; -} - -const CONST: () = (); - -fn foo, const CONST_PARAM: usize>(_: T) {} -"#, - expect![[r#" - ta Bar = type Bar; - tp T - cp CONST_PARAM - tt Foo - en Bar - ct CONST - "#]], - ); - } } diff --git a/crates/ide_completion/src/tests.rs b/crates/ide_completion/src/tests.rs index 7af8c903b..97298ff27 100644 --- a/crates/ide_completion/src/tests.rs +++ b/crates/ide_completion/src/tests.rs @@ -8,6 +8,9 @@ mod item_list; mod use_tree; mod items; mod pattern; +mod type_pos; + +use std::mem; use hir::{PrefixKind, Semantics}; use ide_db::{ @@ -46,7 +49,16 @@ pub(crate) fn completion_list(code: &str) -> String { } fn completion_list_with_config(config: CompletionConfig, code: &str) -> String { - render_completion_list(get_all_items(config, code)) + // filter out all but one builtintype completion for smaller test outputs + let items = get_all_items(config, code); + let mut bt_seen = false; + let items = items + .into_iter() + .filter(|it| { + it.completion_kind != CompletionKind::BuiltinType || !mem::replace(&mut bt_seen, true) + }) + .collect(); + render_completion_list(items) } /// Creates analysis from a multi-file fixture, returns positions marked with $0. diff --git a/crates/ide_completion/src/tests/items.rs b/crates/ide_completion/src/tests/items.rs index 8dfb8221b..b98baffd6 100644 --- a/crates/ide_completion/src/tests/items.rs +++ b/crates/ide_completion/src/tests/items.rs @@ -35,22 +35,6 @@ impl Tra$0 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 "##]], ) } @@ -69,22 +53,6 @@ impl Trait for Str$0 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 "##]], ) } diff --git a/crates/ide_completion/src/tests/type_pos.rs b/crates/ide_completion/src/tests/type_pos.rs new file mode 100644 index 000000000..2bfecdd08 --- /dev/null +++ b/crates/ide_completion/src/tests/type_pos.rs @@ -0,0 +1,185 @@ +//! Completions tests for type position. +use expect_test::{expect, Expect}; + +use crate::tests::completion_list; + +fn check_with(ra_fixture: &str, expect: Expect) { + let base = r#" +enum Enum { TupleV(u32), RecordV { field: u32 }, UnitV } +use self::Enum::TupleV; +mod module {} + +trait Trait {} +static STATIC: Unit = Unit; +const CONST: Unit = Unit; +struct Record { field: u32 } +struct Tuple(u32); +struct Unit +macro_rules! makro {} +"#; + let actual = completion_list(&format!("{}\n{}", base, ra_fixture)); + expect.assert_eq(&actual) +} + +#[test] +fn record_field_ty() { + // FIXME: pub shouldnt show up here + check_with( + r#" +struct Foo<'lt, T, const C: usize> { + f: $0 +} +"#, + expect![[r#" + kw pub(crate) + kw pub + sp Self + tp T + tt Trait + en Enum + st Record + st Tuple + md module + st Foo<…> + st Unit + ma makro!(…) macro_rules! makro + bt u32 + "#]], + ) +} + +#[test] +fn tuple_struct_field() { + // FIXME: pub should show up here + check_with( + r#" +struct Foo<'lt, T, const C: usize>(f$0); +"#, + expect![[r#" + sp Self + tp T + tt Trait + en Enum + st Record + st Tuple + md module + st Foo<…> + st Unit + ma makro!(…) macro_rules! makro + bt u32 + "#]], + ) +} + +#[test] +fn fn_return_type() { + // FIXME: return shouldnt show up here + check_with( + r#" +fn x<'lt, T, const C: usize>() -> $0 +"#, + expect![[r#" + kw return + tp T + tt Trait + en Enum + st Record + st Tuple + md module + st Unit + ma makro!(…) macro_rules! makro + bt u32 + "#]], + ); +} + +#[test] +fn body_type_pos() { + // FIXME: return shouldnt show up here + check_with( + r#" +fn foo<'lt, T, const C: usize>() { + let local = (); + let _: $0; +} +"#, + expect![[r#" + kw return + tp T + tt Trait + en Enum + st Record + st Tuple + md module + st Unit + ma makro!(…) macro_rules! makro + bt u32 + "#]], + ); + check_with( + r#" +fn foo<'lt, T, const C: usize>() { + let local = (); + let _: self::$0; +} +"#, + expect![[r#" + tt Trait + en Enum + st Record + st Tuple + md module + st Unit + "#]], + ); +} + +#[test] +fn completes_types_and_const_in_arg_list() { + // FIXME: return shouldnt show up here + // FIXME: we should complete the lifetime here for now + check_with( + r#" +trait Trait2 { + type Foo; +} + +fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {} +"#, + expect![[r#" + kw return + ta Foo = type Foo; + tp T + cp CONST_PARAM + tt Trait + en Enum + st Record + st Tuple + tt Trait2 + md module + st Unit + ct CONST + ma makro!(…) macro_rules! makro + bt u32 + "#]], + ); + check_with( + r#" +trait Trait2 { + type Foo; +} + +fn foo<'lt, T: Trait2, const CONST_PARAM: usize>(_: T) {} + "#, + expect![[r#" + tt Trait + en Enum + st Record + st Tuple + tt Trait2 + md module + st Unit + ct CONST + "#]], + ); +} -- cgit v1.2.3