Skip to content

Commit 189440c

Browse files
committed
Add a Union to the base item completion test fixture
1 parent 8de3f7e commit 189440c

File tree

7 files changed

+134
-142
lines changed

7 files changed

+134
-142
lines changed

crates/ide_completion/src/completions/qualified_path.rs

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -255,60 +255,6 @@ mod tests {
255255
expect.assert_eq(&actual);
256256
}
257257

258-
fn check_builtin(ra_fixture: &str, expect: Expect) {
259-
let actual = filtered_completion_list(ra_fixture, CompletionKind::BuiltinType);
260-
expect.assert_eq(&actual);
261-
}
262-
263-
#[test]
264-
fn dont_complete_primitive_in_use() {
265-
check_builtin(r#"use self::$0;"#, expect![[""]]);
266-
}
267-
268-
#[test]
269-
fn dont_complete_primitive_in_module_scope() {
270-
check_builtin(r#"fn foo() { self::$0 }"#, expect![[""]]);
271-
}
272-
273-
#[test]
274-
fn completes_enum_variant() {
275-
check(
276-
r#"
277-
enum E { Foo, Bar(i32) }
278-
fn foo() { let _ = E::$0 }
279-
"#,
280-
expect![[r#"
281-
ev Foo ()
282-
ev Bar(…) (i32)
283-
"#]],
284-
);
285-
}
286-
287-
#[test]
288-
fn completes_struct_associated_items() {
289-
check(
290-
r#"
291-
//- /lib.rs
292-
struct S;
293-
294-
impl S {
295-
fn a() {}
296-
fn b(&self) {}
297-
const C: i32 = 42;
298-
type T = i32;
299-
}
300-
301-
fn foo() { let _ = S::$0 }
302-
"#,
303-
expect![[r#"
304-
fn a() fn()
305-
me b(…) fn(&self)
306-
ct C const C: i32 = 42;
307-
ta T type T = i32;
308-
"#]],
309-
);
310-
}
311-
312258
#[test]
313259
fn associated_item_visibility() {
314260
check(
@@ -336,21 +282,6 @@ fn foo() { let _ = S::$0 }
336282
);
337283
}
338284

339-
#[test]
340-
fn completes_enum_associated_method() {
341-
check(
342-
r#"
343-
enum E {};
344-
impl E { fn m() { } }
345-
346-
fn foo() { let _ = E::$0 }
347-
"#,
348-
expect![[r#"
349-
fn m() fn()
350-
"#]],
351-
);
352-
}
353-
354285
#[test]
355286
fn completes_union_associated_method() {
356287
check(

crates/ide_completion/src/tests.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//! Tests and test utilities for completions.
22
//!
3-
//! Most tests live in this module or its submodules unless for very specific completions like
4-
//! `attributes` or `lifetimes` where the completed concept is a distinct thing.
5-
//! Notable examples for completions that are being tested in this module's submodule are paths.
6-
//! Another exception are `check_edit` tests which usually live in the completion modules themselves,
7-
//! as the main purpose of this test module here is to give the developer an overview of whats being
8-
//! completed where, not how.
3+
//! Most tests live in this module or its submodules. The tests in these submodules are "location"
4+
//! oriented, that is they try to check completions for something like type position, param position
5+
//! etc.
6+
//! Tests that are more orientated towards specific completion types like visibility checks of path
7+
//! completions or `check_edit` tests usually live in their respective completion modules instead.
8+
//! This gives this test module and its submodules here the main purpose of giving the developer an
9+
//! overview of whats being completed where, not how.
910
1011
mod attribute;
1112
mod expression;
@@ -55,6 +56,7 @@ macro_rules! makro {}
5556
#[rustc_builtin_macro]
5657
pub macro Clone {}
5758
fn function() {}
59+
union Union { field: i32 }
5860
"#;
5961

6062
pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {

crates/ide_completion/src/tests/expression.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl Unit {
7070
}
7171
}
7272
"#,
73+
// `self` is in here twice, once as the module, once as the local
7374
expect![[r##"
7475
kw unsafe
7576
kw fn
@@ -114,12 +115,42 @@ impl Unit {
114115
?? Unresolved
115116
fn function() fn()
116117
sc STATIC
118+
un Union
117119
ev TupleV(…) (u32)
118120
ct CONST
119121
ma makro!(…) #[macro_export] macro_rules! makro
120122
me self.foo() fn(self)
121123
"##]],
122124
);
125+
check(
126+
r#"
127+
use non_existant::Unresolved;
128+
mod qualified { pub enum Enum { Variant } }
129+
130+
impl Unit {
131+
fn foo<'lifetime, TypeParam, const CONST_PARAM: usize>(self) {
132+
fn local_func() {}
133+
self::$0
134+
}
135+
}
136+
"#,
137+
expect![[r##"
138+
tt Trait
139+
en Enum
140+
st Record
141+
st Tuple
142+
md module
143+
st Unit
144+
md qualified
145+
ma makro!(…) #[macro_export] macro_rules! makro
146+
?? Unresolved
147+
fn function() fn()
148+
sc STATIC
149+
un Union
150+
ev TupleV(…) (u32)
151+
ct CONST
152+
"##]],
153+
);
123154
}
124155

125156
#[test]
@@ -247,3 +278,27 @@ fn quux(x: i32) {
247278
"#]],
248279
);
249280
}
281+
282+
#[test]
283+
fn enum_qualified() {
284+
check(
285+
r#"
286+
impl Enum {
287+
type AssocType = ();
288+
const ASSOC_CONST: () = ();
289+
fn assoc_fn() {}
290+
}
291+
fn func() {
292+
Enum::$0
293+
}
294+
"#,
295+
expect![[r#"
296+
ev TupleV(…) (u32)
297+
ev RecordV { field: u32 }
298+
ev UnitV ()
299+
ct ASSOC_CONST const ASSOC_CONST: () = ();
300+
fn assoc_fn() fn()
301+
ta AssocType type AssocType = ();
302+
"#]],
303+
);
304+
}

crates/ide_completion/src/tests/item.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl Tra$0
2828
md module
2929
st Unit
3030
ma makro!(…) #[macro_export] macro_rules! makro
31+
un Union
3132
ma makro!(…) #[macro_export] macro_rules! makro
3233
bt u32
3334
"##]],
@@ -51,6 +52,7 @@ impl Trait for Str$0
5152
md module
5253
st Unit
5354
ma makro!(…) #[macro_export] macro_rules! makro
55+
un Union
5456
ma makro!(…) #[macro_export] macro_rules! makro
5557
bt u32
5658
"##]],

0 commit comments

Comments
 (0)