Skip to content

Commit b9d85f5

Browse files
committed
Move out completion type position tests
1 parent f835279 commit b9d85f5

File tree

5 files changed

+198
-206
lines changed

5 files changed

+198
-206
lines changed

crates/ide_completion/src/completions/qualified_path.rs

-76
Original file line numberDiff line numberDiff line change
@@ -218,36 +218,6 @@ mod tests {
218218
expect.assert_eq(&actual);
219219
}
220220

221-
#[test]
222-
fn dont_complete_values_in_type_pos() {
223-
check(
224-
r#"
225-
const FOO: () = ();
226-
static BAR: () = ();
227-
struct Baz;
228-
fn foo() {
229-
let _: self::$0;
230-
}
231-
"#,
232-
expect![[r#"
233-
st Baz
234-
"#]],
235-
);
236-
}
237-
238-
#[test]
239-
fn dont_complete_enum_variants_in_type_pos() {
240-
check(
241-
r#"
242-
enum Foo { Bar }
243-
fn foo() {
244-
let _: Foo::$0;
245-
}
246-
"#,
247-
expect![[r#""#]],
248-
);
249-
}
250-
251221
#[test]
252222
fn dont_complete_primitive_in_use() {
253223
check_builtin(r#"use self::$0;"#, expect![[""]]);
@@ -258,32 +228,6 @@ fn foo() {
258228
check_builtin(r#"fn foo() { self::$0 }"#, expect![[""]]);
259229
}
260230

261-
#[test]
262-
fn completes_primitives() {
263-
check_builtin(
264-
r#"fn main() { let _: $0 = 92; }"#,
265-
expect![[r#"
266-
bt u32
267-
bt bool
268-
bt u8
269-
bt isize
270-
bt u16
271-
bt u64
272-
bt u128
273-
bt f32
274-
bt i128
275-
bt i16
276-
bt str
277-
bt i64
278-
bt char
279-
bt f64
280-
bt i32
281-
bt i8
282-
bt usize
283-
"#]],
284-
);
285-
}
286-
287231
#[test]
288232
fn completes_enum_variant() {
289233
check(
@@ -749,24 +693,4 @@ fn main() {
749693
"#]],
750694
);
751695
}
752-
753-
#[test]
754-
fn completes_types_and_const_in_arg_list() {
755-
check(
756-
r#"
757-
mod foo {
758-
pub const CONST: () = ();
759-
pub type Type = ();
760-
}
761-
762-
struct Foo<T>(t);
763-
764-
fn foo(_: Foo<foo::$0>) {}
765-
"#,
766-
expect![[r#"
767-
ta Type
768-
ct CONST
769-
"#]],
770-
);
771-
}
772696
}

crates/ide_completion/src/completions/unqualified_path.rs

-97
Original file line numberDiff line numberDiff line change
@@ -112,28 +112,6 @@ mod tests {
112112
expect.assert_eq(&actual)
113113
}
114114

115-
#[test]
116-
fn dont_complete_values_in_type_pos() {
117-
check(
118-
r#"
119-
const FOO: () = ();
120-
static BAR: () = ();
121-
enum Foo {
122-
Bar
123-
}
124-
struct Baz;
125-
fn foo() {
126-
let local = ();
127-
let _: $0;
128-
}
129-
"#,
130-
expect![[r#"
131-
en Foo
132-
st Baz
133-
"#]],
134-
);
135-
}
136-
137115
#[test]
138116
fn completes_bindings_from_let() {
139117
check(
@@ -238,29 +216,6 @@ fn main() {
238216
);
239217
}
240218

241-
#[test]
242-
fn completes_generic_params_in_struct() {
243-
check(
244-
r#"struct S<T> { x: $0}"#,
245-
expect![[r#"
246-
sp Self
247-
tp T
248-
st S<…>
249-
"#]],
250-
);
251-
}
252-
253-
#[test]
254-
fn completes_self_in_enum() {
255-
check(
256-
r#"enum X { Y($0) }"#,
257-
expect![[r#"
258-
sp Self
259-
en X
260-
"#]],
261-
);
262-
}
263-
264219
#[test]
265220
fn completes_module_items() {
266221
check(
@@ -314,19 +269,6 @@ mod m {
314269
);
315270
}
316271

317-
#[test]
318-
fn completes_return_type() {
319-
check(
320-
r#"
321-
struct Foo;
322-
fn x() -> $0
323-
"#,
324-
expect![[r#"
325-
st Foo
326-
"#]],
327-
);
328-
}
329-
330272
#[test]
331273
fn dont_show_both_completions_for_shadowing() {
332274
check(
@@ -508,19 +450,6 @@ fn foo() { $0 }
508450
);
509451
}
510452

511-
#[test]
512-
fn completes_macros_as_type() {
513-
check(
514-
r#"
515-
macro_rules! foo { () => {} }
516-
fn main() { let x: $0 }
517-
"#,
518-
expect![[r#"
519-
ma foo!(…) macro_rules! foo
520-
"#]],
521-
);
522-
}
523-
524453
#[test]
525454
fn completes_macros_as_stmt() {
526455
check(
@@ -666,30 +595,4 @@ fn f() {}
666595
expect![[""]],
667596
)
668597
}
669-
670-
#[test]
671-
fn completes_types_and_const_in_arg_list() {
672-
check(
673-
r#"
674-
enum Bar {
675-
Baz
676-
}
677-
trait Foo {
678-
type Bar;
679-
}
680-
681-
const CONST: () = ();
682-
683-
fn foo<T: Foo<$0>, const CONST_PARAM: usize>(_: T) {}
684-
"#,
685-
expect![[r#"
686-
ta Bar = type Bar;
687-
tp T
688-
cp CONST_PARAM
689-
tt Foo
690-
en Bar
691-
ct CONST
692-
"#]],
693-
);
694-
}
695598
}

crates/ide_completion/src/tests.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ mod item_list;
88
mod use_tree;
99
mod items;
1010
mod pattern;
11+
mod type_pos;
12+
13+
use std::mem;
1114

1215
use hir::{PrefixKind, Semantics};
1316
use ide_db::{
@@ -46,7 +49,16 @@ pub(crate) fn completion_list(code: &str) -> String {
4649
}
4750

4851
fn completion_list_with_config(config: CompletionConfig, code: &str) -> String {
49-
render_completion_list(get_all_items(config, code))
52+
// filter out all but one builtintype completion for smaller test outputs
53+
let items = get_all_items(config, code);
54+
let mut bt_seen = false;
55+
let items = items
56+
.into_iter()
57+
.filter(|it| {
58+
it.completion_kind != CompletionKind::BuiltinType || !mem::replace(&mut bt_seen, true)
59+
})
60+
.collect();
61+
render_completion_list(items)
5062
}
5163

5264
/// Creates analysis from a multi-file fixture, returns positions marked with $0.

crates/ide_completion/src/tests/items.rs

-32
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,6 @@ impl Tra$0
3535
ma foo!(…) #[macro_export] macro_rules! foo
3636
ma foo!(…) #[macro_export] macro_rules! foo
3737
bt u32
38-
bt bool
39-
bt u8
40-
bt isize
41-
bt u16
42-
bt u64
43-
bt u128
44-
bt f32
45-
bt i128
46-
bt i16
47-
bt str
48-
bt i64
49-
bt char
50-
bt f64
51-
bt i32
52-
bt i8
53-
bt usize
5438
"##]],
5539
)
5640
}
@@ -69,22 +53,6 @@ impl Trait for Str$0
6953
ma foo!(…) #[macro_export] macro_rules! foo
7054
ma foo!(…) #[macro_export] macro_rules! foo
7155
bt u32
72-
bt bool
73-
bt u8
74-
bt isize
75-
bt u16
76-
bt u64
77-
bt u128
78-
bt f32
79-
bt i128
80-
bt i16
81-
bt str
82-
bt i64
83-
bt char
84-
bt f64
85-
bt i32
86-
bt i8
87-
bt usize
8856
"##]],
8957
)
9058
}

0 commit comments

Comments
 (0)