Skip to content

Commit 096e369

Browse files
bors[bot]Veykril
andauthored
Merge #9675
9675: internal: Move and clean up record completion tests r=Veykril a=Veykril Now all that's left are the expression related tests which will take some time to go through bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents 444679f + d5947d9 commit 096e369

File tree

6 files changed

+234
-327
lines changed

6 files changed

+234
-327
lines changed

crates/ide_completion/src/completions/record.rs

Lines changed: 29 additions & 277 deletions
Original file line numberDiff line numberDiff line change
@@ -47,322 +47,74 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) ->
4747

4848
#[cfg(test)]
4949
mod tests {
50-
use expect_test::{expect, Expect};
5150

52-
use crate::{
53-
tests::{check_edit, filtered_completion_list},
54-
CompletionKind,
55-
};
56-
57-
fn check(ra_fixture: &str, expect: Expect) {
58-
let actual = filtered_completion_list(ra_fixture, CompletionKind::Reference);
59-
expect.assert_eq(&actual);
60-
}
61-
62-
fn check_snippet(ra_fixture: &str, expect: Expect) {
63-
let actual = filtered_completion_list(ra_fixture, CompletionKind::Snippet);
64-
expect.assert_eq(&actual);
65-
}
51+
use crate::tests::check_edit;
6652

6753
#[test]
68-
fn test_record_literal_field_default() {
69-
let test_code = r#"
70-
//- minicore: default
71-
struct S { foo: u32, bar: usize }
72-
73-
impl Default for S {
74-
fn default() -> Self {
75-
S {
76-
foo: 0,
77-
bar: 0,
78-
}
79-
}
80-
}
81-
82-
fn process(f: S) {
83-
let other = S {
84-
foo: 5,
85-
.$0
86-
};
87-
}
88-
"#;
89-
check(
90-
test_code,
91-
expect![[r#"
92-
fd bar usize
93-
"#]],
94-
);
95-
96-
check_snippet(
97-
test_code,
98-
expect![[r#"
99-
fd ..Default::default()
100-
"#]],
101-
);
102-
}
103-
104-
#[test]
105-
fn test_record_literal_field_default_completion() {
54+
fn default_completion_edit() {
10655
check_edit(
10756
"..Default::default()",
10857
r#"
10958
//- minicore: default
110-
struct S { foo: u32, bar: usize }
59+
struct Struct { foo: u32, bar: usize }
11160
112-
impl Default for S {
113-
fn default() -> Self {
114-
S {
115-
foo: 0,
116-
bar: 0,
117-
}
118-
}
61+
impl Default for Struct {
62+
fn default() -> Self {}
11963
}
12064
121-
fn process(f: S) {
122-
let other = S {
65+
fn foo() {
66+
let other = Struct {
12367
foo: 5,
12468
.$0
12569
};
12670
}
12771
"#,
12872
r#"
129-
struct S { foo: u32, bar: usize }
73+
struct Struct { foo: u32, bar: usize }
13074
131-
impl Default for S {
132-
fn default() -> Self {
133-
S {
134-
foo: 0,
135-
bar: 0,
136-
}
137-
}
75+
impl Default for Struct {
76+
fn default() -> Self {}
13877
}
13978
140-
fn process(f: S) {
141-
let other = S {
79+
fn foo() {
80+
let other = Struct {
14281
foo: 5,
14382
..Default::default()
14483
};
14584
}
14685
"#,
14786
);
148-
}
149-
150-
#[test]
151-
fn test_record_literal_field_without_default() {
152-
let test_code = r#"
153-
struct S { foo: u32, bar: usize }
154-
155-
fn process(f: S) {
156-
let other = S {
157-
foo: 5,
158-
.$0
159-
};
160-
}
161-
"#;
162-
check(
163-
test_code,
164-
expect![[r#"
165-
fd bar usize
166-
"#]],
167-
);
168-
169-
check_snippet(test_code, expect![[r#""#]]);
170-
}
171-
172-
#[test]
173-
fn test_record_pattern_field() {
174-
check(
175-
r#"
176-
struct S { foo: u32 }
177-
178-
fn process(f: S) {
179-
match f {
180-
S { f$0: 92 } => (),
181-
}
182-
}
183-
"#,
184-
expect![[r#"
185-
fd foo u32
186-
"#]],
187-
);
188-
}
189-
190-
#[test]
191-
fn test_record_pattern_enum_variant() {
192-
check(
193-
r#"
194-
enum E { S { foo: u32, bar: () } }
195-
196-
fn process(e: E) {
197-
match e {
198-
E::S { $0 } => (),
199-
}
200-
}
201-
"#,
202-
expect![[r#"
203-
fd foo u32
204-
fd bar ()
205-
"#]],
206-
);
207-
}
208-
209-
#[test]
210-
fn test_record_pattern_field_in_simple_macro() {
211-
check(
212-
r"
213-
macro_rules! m { ($e:expr) => { $e } }
214-
struct S { foo: u32 }
215-
216-
fn process(f: S) {
217-
m!(match f {
218-
S { f$0: 92 } => (),
219-
})
220-
}
221-
",
222-
expect![[r#"
223-
fd foo u32
224-
"#]],
225-
);
226-
}
227-
228-
#[test]
229-
fn only_missing_fields_are_completed_in_destruct_pats() {
230-
check(
87+
check_edit(
88+
"..Default::default()",
23189
r#"
232-
struct S {
233-
foo1: u32, foo2: u32,
234-
bar: u32, baz: u32,
235-
}
90+
//- minicore: default
91+
struct Struct { foo: u32, bar: usize }
23692
237-
fn main() {
238-
let s = S {
239-
foo1: 1, foo2: 2,
240-
bar: 3, baz: 4,
241-
};
242-
if let S { foo1, foo2: a, $0 } = s {}
93+
impl Default for Struct {
94+
fn default() -> Self {}
24395
}
244-
"#,
245-
expect![[r#"
246-
fd bar u32
247-
fd baz u32
248-
"#]],
249-
);
250-
}
25196
252-
#[test]
253-
fn test_record_literal_field() {
254-
check(
255-
r#"
256-
struct A { the_field: u32 }
25797
fn foo() {
258-
A { the$0 }
259-
}
260-
"#,
261-
expect![[r#"
262-
fd the_field u32
263-
"#]],
264-
);
265-
}
266-
267-
#[test]
268-
fn test_record_literal_enum_variant() {
269-
check(
270-
r#"
271-
enum E { A { a: u32 } }
272-
fn foo() {
273-
let _ = E::A { $0 }
98+
let other = Struct {
99+
foo: 5,
100+
$0
101+
};
274102
}
275103
"#,
276-
expect![[r#"
277-
fd a u32
278-
"#]],
279-
);
280-
}
281-
282-
#[test]
283-
fn test_record_literal_two_structs() {
284-
check(
285104
r#"
286-
struct A { a: u32 }
287-
struct B { b: u32 }
105+
struct Struct { foo: u32, bar: usize }
288106
289-
fn foo() {
290-
let _: A = B { $0 }
107+
impl Default for Struct {
108+
fn default() -> Self {}
291109
}
292-
"#,
293-
expect![[r#"
294-
fd b u32
295-
"#]],
296-
);
297-
}
298-
299-
#[test]
300-
fn test_record_literal_generic_struct() {
301-
check(
302-
r#"
303-
struct A<T> { a: T }
304110
305111
fn foo() {
306-
let _: A<u32> = A { $0 }
307-
}
308-
"#,
309-
expect![[r#"
310-
fd a u32
311-
"#]],
312-
);
313-
}
314-
315-
#[test]
316-
fn test_record_literal_field_in_simple_macro() {
317-
check(
318-
r#"
319-
macro_rules! m { ($e:expr) => { $e } }
320-
struct A { the_field: u32 }
321-
fn foo() {
322-
m!(A { the$0 })
323-
}
324-
"#,
325-
expect![[r#"
326-
fd the_field u32
327-
"#]],
328-
);
329-
}
330-
331-
#[test]
332-
fn only_missing_fields_are_completed() {
333-
check(
334-
r#"
335-
struct S {
336-
foo1: u32, foo2: u32,
337-
bar: u32, baz: u32,
338-
}
339-
340-
fn main() {
341-
let foo1 = 1;
342-
let s = S { foo1, foo2: 5, $0 }
343-
}
344-
"#,
345-
expect![[r#"
346-
fd bar u32
347-
fd baz u32
348-
"#]],
349-
);
350-
}
351-
352-
#[test]
353-
fn completes_functional_update() {
354-
check(
355-
r#"
356-
struct S { foo1: u32, foo2: u32 }
357-
358-
fn main() {
359-
let foo1 = 1;
360-
let s = S { foo1, $0 .. loop {} }
112+
let other = Struct {
113+
foo: 5,
114+
..Default::default()
115+
};
361116
}
362117
"#,
363-
expect![[r#"
364-
fd foo2 u32
365-
"#]],
366118
);
367119
}
368120
}

crates/ide_completion/src/completions/snippet.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,4 @@ mod tests {
108108
"#]],
109109
);
110110
}
111-
112-
#[test]
113-
fn should_not_complete_snippets_in_path() {
114-
check(r#"fn foo(x: i32) { ::foo$0 }"#, expect![[""]]);
115-
check(r#"fn foo(x: i32) { ::$0 }"#, expect![[""]]);
116-
}
117111
}

0 commit comments

Comments
 (0)