@@ -47,322 +47,74 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) ->
47
47
48
48
#[ cfg( test) ]
49
49
mod tests {
50
- use expect_test:: { expect, Expect } ;
51
50
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;
66
52
67
53
#[ 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 ( ) {
106
55
check_edit (
107
56
"..Default::default()" ,
108
57
r#"
109
58
//- minicore: default
110
- struct S { foo: u32, bar: usize }
59
+ struct Struct { foo: u32, bar: usize }
111
60
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 {}
119
63
}
120
64
121
- fn process(f: S ) {
122
- let other = S {
65
+ fn foo( ) {
66
+ let other = Struct {
123
67
foo: 5,
124
68
.$0
125
69
};
126
70
}
127
71
"# ,
128
72
r#"
129
- struct S { foo: u32, bar: usize }
73
+ struct Struct { foo: u32, bar: usize }
130
74
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 {}
138
77
}
139
78
140
- fn process(f: S ) {
141
- let other = S {
79
+ fn foo( ) {
80
+ let other = Struct {
142
81
foo: 5,
143
82
..Default::default()
144
83
};
145
84
}
146
85
"# ,
147
86
) ;
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()" ,
231
89
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 }
236
92
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 {}
243
95
}
244
- "# ,
245
- expect ! [ [ r#"
246
- fd bar u32
247
- fd baz u32
248
- "# ] ] ,
249
- ) ;
250
- }
251
96
252
- #[ test]
253
- fn test_record_literal_field ( ) {
254
- check (
255
- r#"
256
- struct A { the_field: u32 }
257
97
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
+ };
274
102
}
275
103
"# ,
276
- expect ! [ [ r#"
277
- fd a u32
278
- "# ] ] ,
279
- ) ;
280
- }
281
-
282
- #[ test]
283
- fn test_record_literal_two_structs ( ) {
284
- check (
285
104
r#"
286
- struct A { a: u32 }
287
- struct B { b: u32 }
105
+ struct Struct { foo: u32, bar: usize }
288
106
289
- fn foo() {
290
- let _: A = B { $0 }
107
+ impl Default for Struct {
108
+ fn default() -> Self { }
291
109
}
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 }
304
110
305
111
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
+ };
361
116
}
362
117
"# ,
363
- expect ! [ [ r#"
364
- fd foo2 u32
365
- "# ] ] ,
366
118
) ;
367
119
}
368
120
}
0 commit comments