diff options
author | Lukas Wirth <[email protected]> | 2021-06-21 12:48:25 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-06-21 12:48:25 +0100 |
commit | f835279b3ae41644e9568187b4468cd9d9e84eca (patch) | |
tree | fc5b37d8257674d0c5fa7a8e8c1177e21dc4750c /crates/ide_completion/src | |
parent | c2aa7782d65c4f2765f68b99f00f4203e1f143c1 (diff) |
Move out completion pattern tests
Diffstat (limited to 'crates/ide_completion/src')
-rw-r--r-- | crates/ide_completion/src/completions/keyword.rs | 22 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/pattern.rs | 395 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/unqualified_path.rs | 50 | ||||
-rw-r--r-- | crates/ide_completion/src/tests.rs | 1 | ||||
-rw-r--r-- | crates/ide_completion/src/tests/pattern.rs | 348 |
5 files changed, 349 insertions, 467 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs index 07541c79c..e40ec6280 100644 --- a/crates/ide_completion/src/completions/keyword.rs +++ b/crates/ide_completion/src/completions/keyword.rs | |||
@@ -373,28 +373,6 @@ fn quux() -> i32 { | |||
373 | } | 373 | } |
374 | 374 | ||
375 | #[test] | 375 | #[test] |
376 | fn test_mut_in_ref_and_in_fn_parameters_list() { | ||
377 | check( | ||
378 | r"fn my_fn(&$0) {}", | ||
379 | expect![[r#" | ||
380 | kw mut | ||
381 | "#]], | ||
382 | ); | ||
383 | check( | ||
384 | r"fn my_fn($0) {}", | ||
385 | expect![[r#" | ||
386 | kw mut | ||
387 | "#]], | ||
388 | ); | ||
389 | check( | ||
390 | r"fn my_fn() { let &$0 }", | ||
391 | expect![[r#" | ||
392 | kw mut | ||
393 | "#]], | ||
394 | ); | ||
395 | } | ||
396 | |||
397 | #[test] | ||
398 | fn no_keyword_completion_in_comments() { | 376 | fn no_keyword_completion_in_comments() { |
399 | cov_mark::check!(no_keyword_completion_in_comments); | 377 | cov_mark::check!(no_keyword_completion_in_comments); |
400 | check( | 378 | check( |
diff --git a/crates/ide_completion/src/completions/pattern.rs b/crates/ide_completion/src/completions/pattern.rs index efe3c957a..bd13a62d7 100644 --- a/crates/ide_completion/src/completions/pattern.rs +++ b/crates/ide_completion/src/completions/pattern.rs | |||
@@ -55,398 +55,3 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { | |||
55 | } | 55 | } |
56 | }); | 56 | }); |
57 | } | 57 | } |
58 | |||
59 | #[cfg(test)] | ||
60 | mod tests { | ||
61 | use expect_test::{expect, Expect}; | ||
62 | |||
63 | use crate::{ | ||
64 | tests::{check_edit, filtered_completion_list}, | ||
65 | CompletionKind, | ||
66 | }; | ||
67 | |||
68 | fn check(ra_fixture: &str, expect: Expect) { | ||
69 | let actual = filtered_completion_list(ra_fixture, CompletionKind::Reference); | ||
70 | expect.assert_eq(&actual) | ||
71 | } | ||
72 | |||
73 | fn check_snippet(ra_fixture: &str, expect: Expect) { | ||
74 | let actual = filtered_completion_list(ra_fixture, CompletionKind::Snippet); | ||
75 | expect.assert_eq(&actual) | ||
76 | } | ||
77 | |||
78 | #[test] | ||
79 | fn completes_enum_variants_and_modules() { | ||
80 | check( | ||
81 | r#" | ||
82 | enum E { X } | ||
83 | use self::E::X; | ||
84 | const Z: E = E::X; | ||
85 | mod m {} | ||
86 | |||
87 | static FOO: E = E::X; | ||
88 | struct Bar { f: u32 } | ||
89 | |||
90 | fn foo() { | ||
91 | match E::X { a$0 } | ||
92 | } | ||
93 | "#, | ||
94 | expect![[r#" | ||
95 | en E | ||
96 | ct Z | ||
97 | st Bar | ||
98 | ev X | ||
99 | md m | ||
100 | "#]], | ||
101 | ); | ||
102 | } | ||
103 | |||
104 | #[test] | ||
105 | fn does_not_complete_non_fn_macros() { | ||
106 | check( | ||
107 | r#" | ||
108 | macro_rules! m { ($e:expr) => { $e } } | ||
109 | enum E { X } | ||
110 | |||
111 | #[rustc_builtin_macro] | ||
112 | macro Clone {} | ||
113 | |||
114 | fn foo() { | ||
115 | match E::X { $0 } | ||
116 | } | ||
117 | "#, | ||
118 | expect![[r#" | ||
119 | ev E::X () | ||
120 | en E | ||
121 | ma m!(…) macro_rules! m | ||
122 | "#]], | ||
123 | ); | ||
124 | } | ||
125 | |||
126 | #[test] | ||
127 | fn completes_in_simple_macro_call() { | ||
128 | check( | ||
129 | r#" | ||
130 | macro_rules! m { ($e:expr) => { $e } } | ||
131 | enum E { X } | ||
132 | |||
133 | fn foo() { | ||
134 | m!(match E::X { a$0 }) | ||
135 | } | ||
136 | "#, | ||
137 | expect![[r#" | ||
138 | ev E::X () | ||
139 | en E | ||
140 | ma m!(…) macro_rules! m | ||
141 | "#]], | ||
142 | ); | ||
143 | } | ||
144 | |||
145 | #[test] | ||
146 | fn completes_in_irrefutable_let() { | ||
147 | check( | ||
148 | r#" | ||
149 | enum E { X } | ||
150 | use self::E::X; | ||
151 | const Z: E = E::X; | ||
152 | mod m {} | ||
153 | |||
154 | static FOO: E = E::X; | ||
155 | struct Bar { f: u32 } | ||
156 | |||
157 | fn foo() { | ||
158 | let a$0 | ||
159 | } | ||
160 | "#, | ||
161 | expect![[r#" | ||
162 | st Bar | ||
163 | "#]], | ||
164 | ); | ||
165 | } | ||
166 | |||
167 | #[test] | ||
168 | fn completes_in_param() { | ||
169 | check( | ||
170 | r#" | ||
171 | enum E { X } | ||
172 | |||
173 | static FOO: E = E::X; | ||
174 | struct Bar { f: u32 } | ||
175 | |||
176 | fn foo(a$0) { | ||
177 | } | ||
178 | "#, | ||
179 | expect![[r#" | ||
180 | st Bar | ||
181 | "#]], | ||
182 | ); | ||
183 | } | ||
184 | |||
185 | #[test] | ||
186 | fn completes_pat_in_let() { | ||
187 | check_snippet( | ||
188 | r#" | ||
189 | struct Bar { f: u32 } | ||
190 | |||
191 | fn foo() { | ||
192 | let a$0 | ||
193 | } | ||
194 | "#, | ||
195 | expect![[r#" | ||
196 | bn Bar Bar { f$1 }$0 | ||
197 | "#]], | ||
198 | ); | ||
199 | } | ||
200 | |||
201 | #[test] | ||
202 | fn completes_param_pattern() { | ||
203 | check_snippet( | ||
204 | r#" | ||
205 | struct Foo { bar: String, baz: String } | ||
206 | struct Bar(String, String); | ||
207 | struct Baz; | ||
208 | fn outer(a$0) {} | ||
209 | "#, | ||
210 | expect![[r#" | ||
211 | bn Foo Foo { bar$1, baz$2 }: Foo$0 | ||
212 | bn Bar Bar($1, $2): Bar$0 | ||
213 | "#]], | ||
214 | ) | ||
215 | } | ||
216 | |||
217 | #[test] | ||
218 | fn completes_let_pattern() { | ||
219 | check_snippet( | ||
220 | r#" | ||
221 | struct Foo { bar: String, baz: String } | ||
222 | struct Bar(String, String); | ||
223 | struct Baz; | ||
224 | fn outer() { | ||
225 | let a$0 | ||
226 | } | ||
227 | "#, | ||
228 | expect![[r#" | ||
229 | bn Foo Foo { bar$1, baz$2 }$0 | ||
230 | bn Bar Bar($1, $2)$0 | ||
231 | "#]], | ||
232 | ) | ||
233 | } | ||
234 | |||
235 | #[test] | ||
236 | fn completes_refutable_pattern() { | ||
237 | check_snippet( | ||
238 | r#" | ||
239 | struct Foo { bar: i32, baz: i32 } | ||
240 | struct Bar(String, String); | ||
241 | struct Baz; | ||
242 | fn outer() { | ||
243 | match () { | ||
244 | a$0 | ||
245 | } | ||
246 | } | ||
247 | "#, | ||
248 | expect![[r#" | ||
249 | bn Foo Foo { bar$1, baz$2 }$0 | ||
250 | bn Bar Bar($1, $2)$0 | ||
251 | "#]], | ||
252 | ) | ||
253 | } | ||
254 | |||
255 | #[test] | ||
256 | fn omits_private_fields_pat() { | ||
257 | check_snippet( | ||
258 | r#" | ||
259 | mod foo { | ||
260 | pub struct Foo { pub bar: i32, baz: i32 } | ||
261 | pub struct Bar(pub String, String); | ||
262 | pub struct Invisible(String, String); | ||
263 | } | ||
264 | use foo::*; | ||
265 | |||
266 | fn outer() { | ||
267 | match () { | ||
268 | a$0 | ||
269 | } | ||
270 | } | ||
271 | "#, | ||
272 | expect![[r#" | ||
273 | bn Foo Foo { bar$1, .. }$0 | ||
274 | bn Bar Bar($1, ..)$0 | ||
275 | "#]], | ||
276 | ) | ||
277 | } | ||
278 | |||
279 | #[test] | ||
280 | fn only_shows_ident_completion() { | ||
281 | check_edit( | ||
282 | "Foo", | ||
283 | r#" | ||
284 | struct Foo(i32); | ||
285 | fn main() { | ||
286 | match Foo(92) { | ||
287 | a$0(92) => (), | ||
288 | } | ||
289 | } | ||
290 | "#, | ||
291 | r#" | ||
292 | struct Foo(i32); | ||
293 | fn main() { | ||
294 | match Foo(92) { | ||
295 | Foo(92) => (), | ||
296 | } | ||
297 | } | ||
298 | "#, | ||
299 | ); | ||
300 | } | ||
301 | |||
302 | #[test] | ||
303 | fn completes_self_pats() { | ||
304 | check_snippet( | ||
305 | r#" | ||
306 | struct Foo(i32); | ||
307 | impl Foo { | ||
308 | fn foo() { | ||
309 | match () { | ||
310 | a$0 | ||
311 | } | ||
312 | } | ||
313 | } | ||
314 | "#, | ||
315 | expect![[r#" | ||
316 | bn Self Self($1)$0 | ||
317 | bn Foo Foo($1)$0 | ||
318 | "#]], | ||
319 | ) | ||
320 | } | ||
321 | |||
322 | #[test] | ||
323 | fn completes_qualified_variant() { | ||
324 | check_snippet( | ||
325 | r#" | ||
326 | enum Foo { | ||
327 | Bar { baz: i32 } | ||
328 | } | ||
329 | impl Foo { | ||
330 | fn foo() { | ||
331 | match {Foo::Bar { baz: 0 }} { | ||
332 | B$0 | ||
333 | } | ||
334 | } | ||
335 | } | ||
336 | "#, | ||
337 | expect![[r#" | ||
338 | bn Self::Bar Self::Bar { baz$1 }$0 | ||
339 | bn Foo::Bar Foo::Bar { baz$1 }$0 | ||
340 | "#]], | ||
341 | ) | ||
342 | } | ||
343 | |||
344 | #[test] | ||
345 | fn completes_enum_variant_matcharm() { | ||
346 | check( | ||
347 | r#" | ||
348 | enum Foo { Bar, Baz, Quux } | ||
349 | |||
350 | fn main() { | ||
351 | let foo = Foo::Quux; | ||
352 | match foo { Qu$0 } | ||
353 | } | ||
354 | "#, | ||
355 | expect![[r#" | ||
356 | ev Foo::Bar () | ||
357 | ev Foo::Baz () | ||
358 | ev Foo::Quux () | ||
359 | en Foo | ||
360 | "#]], | ||
361 | ) | ||
362 | } | ||
363 | |||
364 | #[test] | ||
365 | fn completes_enum_variant_matcharm_ref() { | ||
366 | check( | ||
367 | r#" | ||
368 | enum Foo { Bar, Baz, Quux } | ||
369 | |||
370 | fn main() { | ||
371 | let foo = Foo::Quux; | ||
372 | match &foo { Qu$0 } | ||
373 | } | ||
374 | "#, | ||
375 | expect![[r#" | ||
376 | ev Foo::Bar () | ||
377 | ev Foo::Baz () | ||
378 | ev Foo::Quux () | ||
379 | en Foo | ||
380 | "#]], | ||
381 | ) | ||
382 | } | ||
383 | |||
384 | #[test] | ||
385 | fn completes_enum_variant_iflet() { | ||
386 | check( | ||
387 | r#" | ||
388 | enum Foo { Bar, Baz, Quux } | ||
389 | |||
390 | fn main() { | ||
391 | let foo = Foo::Quux; | ||
392 | if let Qu$0 = foo { } | ||
393 | } | ||
394 | "#, | ||
395 | expect![[r#" | ||
396 | ev Foo::Bar () | ||
397 | ev Foo::Baz () | ||
398 | ev Foo::Quux () | ||
399 | en Foo | ||
400 | "#]], | ||
401 | ) | ||
402 | } | ||
403 | |||
404 | #[test] | ||
405 | fn completes_enum_variant_impl() { | ||
406 | check( | ||
407 | r#" | ||
408 | enum Foo { Bar, Baz, Quux } | ||
409 | impl Foo { | ||
410 | fn foo() { match Foo::Bar { Q$0 } } | ||
411 | } | ||
412 | "#, | ||
413 | expect![[r#" | ||
414 | ev Self::Bar () | ||
415 | ev Self::Baz () | ||
416 | ev Self::Quux () | ||
417 | ev Foo::Bar () | ||
418 | ev Foo::Baz () | ||
419 | ev Foo::Quux () | ||
420 | sp Self | ||
421 | en Foo | ||
422 | "#]], | ||
423 | ) | ||
424 | } | ||
425 | |||
426 | #[test] | ||
427 | fn completes_in_record_field_pat() { | ||
428 | check_snippet( | ||
429 | r#" | ||
430 | struct Foo { bar: Bar } | ||
431 | struct Bar(u32); | ||
432 | fn outer(Foo { bar: $0 }: Foo) {} | ||
433 | "#, | ||
434 | expect![[r#" | ||
435 | bn Foo Foo { bar$1 }$0 | ||
436 | bn Bar Bar($1)$0 | ||
437 | "#]], | ||
438 | ) | ||
439 | } | ||
440 | |||
441 | #[test] | ||
442 | fn skips_in_record_field_pat_name() { | ||
443 | check_snippet( | ||
444 | r#" | ||
445 | struct Foo { bar: Bar } | ||
446 | struct Bar(u32); | ||
447 | fn outer(Foo { bar$0 }: Foo) {} | ||
448 | "#, | ||
449 | expect![[r#""#]], | ||
450 | ) | ||
451 | } | ||
452 | } | ||
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index 81c4fb305..819fa3a43 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs | |||
@@ -135,56 +135,6 @@ fn foo() { | |||
135 | } | 135 | } |
136 | 136 | ||
137 | #[test] | 137 | #[test] |
138 | fn bind_pat_and_path_ignore_at() { | ||
139 | check( | ||
140 | r#" | ||
141 | enum Enum { A, B } | ||
142 | fn quux(x: Option<Enum>) { | ||
143 | match x { | ||
144 | None => (), | ||
145 | Some(en$0 @ Enum::A) => (), | ||
146 | } | ||
147 | } | ||
148 | "#, | ||
149 | expect![[r#""#]], | ||
150 | ); | ||
151 | } | ||
152 | |||
153 | #[test] | ||
154 | fn bind_pat_and_path_ignore_ref() { | ||
155 | check( | ||
156 | r#" | ||
157 | enum Enum { A, B } | ||
158 | fn quux(x: Option<Enum>) { | ||
159 | match x { | ||
160 | None => (), | ||
161 | Some(ref en$0) => (), | ||
162 | } | ||
163 | } | ||
164 | "#, | ||
165 | expect![[r#""#]], | ||
166 | ); | ||
167 | } | ||
168 | |||
169 | #[test] | ||
170 | fn bind_pat_and_path() { | ||
171 | check( | ||
172 | r#" | ||
173 | enum Enum { A, B } | ||
174 | fn quux(x: Option<Enum>) { | ||
175 | match x { | ||
176 | None => (), | ||
177 | Some(En$0) => (), | ||
178 | } | ||
179 | } | ||
180 | "#, | ||
181 | expect![[r#" | ||
182 | en Enum | ||
183 | "#]], | ||
184 | ); | ||
185 | } | ||
186 | |||
187 | #[test] | ||
188 | fn completes_bindings_from_let() { | 138 | fn completes_bindings_from_let() { |
189 | check( | 139 | check( |
190 | r#" | 140 | r#" |
diff --git a/crates/ide_completion/src/tests.rs b/crates/ide_completion/src/tests.rs index 211c89c40..7af8c903b 100644 --- a/crates/ide_completion/src/tests.rs +++ b/crates/ide_completion/src/tests.rs | |||
@@ -7,6 +7,7 @@ | |||
7 | mod item_list; | 7 | mod item_list; |
8 | mod use_tree; | 8 | mod use_tree; |
9 | mod items; | 9 | mod items; |
10 | mod pattern; | ||
10 | 11 | ||
11 | use hir::{PrefixKind, Semantics}; | 12 | use hir::{PrefixKind, Semantics}; |
12 | use ide_db::{ | 13 | use ide_db::{ |
diff --git a/crates/ide_completion/src/tests/pattern.rs b/crates/ide_completion/src/tests/pattern.rs new file mode 100644 index 000000000..1ad5ccd97 --- /dev/null +++ b/crates/ide_completion/src/tests/pattern.rs | |||
@@ -0,0 +1,348 @@ | |||
1 | //! Completions tests for pattern position. | ||
2 | use expect_test::{expect, Expect}; | ||
3 | |||
4 | use crate::tests::completion_list; | ||
5 | |||
6 | fn check(ra_fixture: &str, expect: Expect) { | ||
7 | let actual = completion_list(ra_fixture); | ||
8 | expect.assert_eq(&actual) | ||
9 | } | ||
10 | |||
11 | fn check_with(ra_fixture: &str, expect: Expect) { | ||
12 | let base = r#" | ||
13 | enum Enum { TupleV(u32), RecordV { field: u32 }, UnitV } | ||
14 | use self::Enum::TupleV; | ||
15 | mod module {} | ||
16 | |||
17 | static STATIC: Unit = Unit; | ||
18 | const CONST: Unit = Unit; | ||
19 | struct Record { field: u32 } | ||
20 | struct Tuple(u32); | ||
21 | struct Unit | ||
22 | macro_rules! makro {} | ||
23 | "#; | ||
24 | let actual = completion_list(&format!("{}\n{}", base, ra_fixture)); | ||
25 | expect.assert_eq(&actual) | ||
26 | } | ||
27 | |||
28 | #[test] | ||
29 | fn ident_rebind_pat() { | ||
30 | check( | ||
31 | r#" | ||
32 | fn quux() { | ||
33 | let en$0 @ x | ||
34 | } | ||
35 | "#, | ||
36 | expect![[r#" | ||
37 | kw mut | ||
38 | "#]], | ||
39 | ); | ||
40 | } | ||
41 | |||
42 | #[test] | ||
43 | fn ident_ref_pat() { | ||
44 | check( | ||
45 | r#" | ||
46 | fn quux() { | ||
47 | let ref en$0 | ||
48 | } | ||
49 | "#, | ||
50 | expect![[r#" | ||
51 | kw mut | ||
52 | "#]], | ||
53 | ); | ||
54 | check( | ||
55 | r#" | ||
56 | fn quux() { | ||
57 | let ref en$0 @ x | ||
58 | } | ||
59 | "#, | ||
60 | expect![[r#" | ||
61 | kw mut | ||
62 | "#]], | ||
63 | ); | ||
64 | } | ||
65 | |||
66 | #[test] | ||
67 | fn ident_ref_mut_pat() { | ||
68 | // FIXME mut is already here, don't complete it again | ||
69 | check( | ||
70 | r#" | ||
71 | fn quux() { | ||
72 | let ref mut en$0 | ||
73 | } | ||
74 | "#, | ||
75 | expect![[r#" | ||
76 | kw mut | ||
77 | "#]], | ||
78 | ); | ||
79 | check( | ||
80 | r#" | ||
81 | fn quux() { | ||
82 | let ref mut en$0 @ x | ||
83 | } | ||
84 | "#, | ||
85 | expect![[r#" | ||
86 | kw mut | ||
87 | "#]], | ||
88 | ); | ||
89 | } | ||
90 | |||
91 | #[test] | ||
92 | fn ref_pat() { | ||
93 | check( | ||
94 | r#" | ||
95 | fn quux() { | ||
96 | let &en$0 | ||
97 | } | ||
98 | "#, | ||
99 | expect![[r#" | ||
100 | kw mut | ||
101 | "#]], | ||
102 | ); | ||
103 | // FIXME mut is already here, don't complete it again | ||
104 | check( | ||
105 | r#" | ||
106 | fn quux() { | ||
107 | let &mut en$0 | ||
108 | } | ||
109 | "#, | ||
110 | expect![[r#" | ||
111 | kw mut | ||
112 | "#]], | ||
113 | ); | ||
114 | } | ||
115 | |||
116 | #[test] | ||
117 | fn refutable() { | ||
118 | check_with( | ||
119 | r#" | ||
120 | fn foo() { | ||
121 | if let a$0 | ||
122 | } | ||
123 | "#, | ||
124 | expect![[r#" | ||
125 | kw mut | ||
126 | bn Record Record { field$1 }$0 | ||
127 | st Record | ||
128 | en Enum | ||
129 | bn Tuple Tuple($1)$0 | ||
130 | st Tuple | ||
131 | md module | ||
132 | bn TupleV TupleV($1)$0 | ||
133 | ev TupleV | ||
134 | st Unit | ||
135 | ct CONST | ||
136 | ma makro!(…) macro_rules! makro | ||
137 | "#]], | ||
138 | ); | ||
139 | } | ||
140 | |||
141 | #[test] | ||
142 | fn irrefutable() { | ||
143 | check_with( | ||
144 | r#" | ||
145 | fn foo() { | ||
146 | let a$0 | ||
147 | } | ||
148 | "#, | ||
149 | expect![[r#" | ||
150 | kw mut | ||
151 | bn Record Record { field$1 }$0 | ||
152 | st Record | ||
153 | bn Tuple Tuple($1)$0 | ||
154 | st Tuple | ||
155 | st Unit | ||
156 | ma makro!(…) macro_rules! makro | ||
157 | "#]], | ||
158 | ); | ||
159 | } | ||
160 | |||
161 | #[test] | ||
162 | fn in_param() { | ||
163 | check_with( | ||
164 | r#" | ||
165 | fn foo(a$0) { | ||
166 | } | ||
167 | "#, | ||
168 | expect![[r#" | ||
169 | kw mut | ||
170 | bn Record Record { field$1 }: Record$0 | ||
171 | st Record | ||
172 | bn Tuple Tuple($1): Tuple$0 | ||
173 | st Tuple | ||
174 | st Unit | ||
175 | ma makro!(…) macro_rules! makro | ||
176 | "#]], | ||
177 | ); | ||
178 | } | ||
179 | |||
180 | #[test] | ||
181 | fn only_fn_like_macros() { | ||
182 | check( | ||
183 | r#" | ||
184 | macro_rules! m { ($e:expr) => { $e } } | ||
185 | |||
186 | #[rustc_builtin_macro] | ||
187 | macro Clone {} | ||
188 | |||
189 | fn foo() { | ||
190 | let x$0 | ||
191 | } | ||
192 | "#, | ||
193 | expect![[r#" | ||
194 | kw mut | ||
195 | ma m!(…) macro_rules! m | ||
196 | "#]], | ||
197 | ); | ||
198 | } | ||
199 | |||
200 | #[test] | ||
201 | fn in_simple_macro_call() { | ||
202 | check( | ||
203 | r#" | ||
204 | macro_rules! m { ($e:expr) => { $e } } | ||
205 | enum E { X } | ||
206 | |||
207 | fn foo() { | ||
208 | m!(match E::X { a$0 }) | ||
209 | } | ||
210 | "#, | ||
211 | expect![[r#" | ||
212 | kw mut | ||
213 | ev E::X () | ||
214 | en E | ||
215 | ma m!(…) macro_rules! m | ||
216 | "#]], | ||
217 | ); | ||
218 | } | ||
219 | |||
220 | #[test] | ||
221 | fn omits_private_fields_pat() { | ||
222 | check( | ||
223 | r#" | ||
224 | mod foo { | ||
225 | pub struct Record { pub field: i32, _field: i32 } | ||
226 | pub struct Tuple(pub u32, u32); | ||
227 | pub struct Invisible(u32, u32); | ||
228 | } | ||
229 | use foo::*; | ||
230 | |||
231 | fn outer() { | ||
232 | if let a$0 | ||
233 | } | ||
234 | "#, | ||
235 | expect![[r#" | ||
236 | kw mut | ||
237 | bn Record Record { field$1, .. }$0 | ||
238 | st Record | ||
239 | bn Tuple Tuple($1, ..)$0 | ||
240 | st Tuple | ||
241 | st Invisible | ||
242 | md foo | ||
243 | "#]], | ||
244 | ) | ||
245 | } | ||
246 | |||
247 | // #[test] | ||
248 | // fn only_shows_ident_completion() { | ||
249 | // check_edit( | ||
250 | // "Foo", | ||
251 | // r#" | ||
252 | // struct Foo(i32); | ||
253 | // fn main() { | ||
254 | // match Foo(92) { | ||
255 | // a$0(92) => (), | ||
256 | // } | ||
257 | // } | ||
258 | // "#, | ||
259 | // r#" | ||
260 | // struct Foo(i32); | ||
261 | // fn main() { | ||
262 | // match Foo(92) { | ||
263 | // Foo(92) => (), | ||
264 | // } | ||
265 | // } | ||
266 | // "#, | ||
267 | // ); | ||
268 | // } | ||
269 | |||
270 | #[test] | ||
271 | fn completes_self_pats() { | ||
272 | check( | ||
273 | r#" | ||
274 | struct Foo(i32); | ||
275 | impl Foo { | ||
276 | fn foo() { | ||
277 | match Foo(0) { | ||
278 | a$0 | ||
279 | } | ||
280 | } | ||
281 | } | ||
282 | "#, | ||
283 | expect![[r#" | ||
284 | kw mut | ||
285 | bn Self Self($1)$0 | ||
286 | sp Self | ||
287 | bn Foo Foo($1)$0 | ||
288 | st Foo | ||
289 | "#]], | ||
290 | ) | ||
291 | } | ||
292 | |||
293 | #[test] | ||
294 | fn completes_qualified_variant() { | ||
295 | check( | ||
296 | r#" | ||
297 | enum Foo { | ||
298 | Bar { baz: i32 } | ||
299 | } | ||
300 | impl Foo { | ||
301 | fn foo() { | ||
302 | match {Foo::Bar { baz: 0 }} { | ||
303 | B$0 | ||
304 | } | ||
305 | } | ||
306 | } | ||
307 | "#, | ||
308 | expect![[r#" | ||
309 | kw mut | ||
310 | bn Self::Bar Self::Bar { baz$1 }$0 | ||
311 | ev Self::Bar { baz: i32 } | ||
312 | bn Foo::Bar Foo::Bar { baz$1 }$0 | ||
313 | ev Foo::Bar { baz: i32 } | ||
314 | sp Self | ||
315 | en Foo | ||
316 | "#]], | ||
317 | ) | ||
318 | } | ||
319 | |||
320 | #[test] | ||
321 | fn completes_in_record_field_pat() { | ||
322 | check( | ||
323 | r#" | ||
324 | struct Foo { bar: Bar } | ||
325 | struct Bar(u32); | ||
326 | fn outer(Foo { bar: $0 }: Foo) {} | ||
327 | "#, | ||
328 | expect![[r#" | ||
329 | kw mut | ||
330 | bn Foo Foo { bar$1 }$0 | ||
331 | st Foo | ||
332 | bn Bar Bar($1)$0 | ||
333 | st Bar | ||
334 | "#]], | ||
335 | ) | ||
336 | } | ||
337 | |||
338 | #[test] | ||
339 | fn skips_in_record_field_pat_name() { | ||
340 | check( | ||
341 | r#" | ||
342 | struct Foo { bar: Bar } | ||
343 | struct Bar(u32); | ||
344 | fn outer(Foo { bar$0 }: Foo) {} | ||
345 | "#, | ||
346 | expect![[r#""#]], | ||
347 | ) | ||
348 | } | ||