]> git.proxmox.com Git - rustc.git/blob - src/tools/rust-analyzer/crates/ide-completion/src/tests/item_list.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / src / tools / rust-analyzer / crates / ide-completion / src / tests / item_list.rs
1 //! Completion tests for item list position.
2 use expect_test::{expect, Expect};
3
4 use crate::tests::{check_edit, completion_list, BASE_ITEMS_FIXTURE};
5
6 fn check(ra_fixture: &str, expect: Expect) {
7 let actual = completion_list(&format!("{BASE_ITEMS_FIXTURE}{ra_fixture}"));
8 expect.assert_eq(&actual)
9 }
10
11 #[test]
12 fn in_mod_item_list() {
13 check(
14 r#"mod tests { $0 }"#,
15 expect![[r#"
16 ma makro!(…) macro_rules! makro
17 kw const
18 kw crate::
19 kw enum
20 kw extern
21 kw fn
22 kw impl
23 kw mod
24 kw pub
25 kw pub(crate)
26 kw pub(super)
27 kw self::
28 kw static
29 kw struct
30 kw super::
31 kw trait
32 kw type
33 kw union
34 kw unsafe
35 kw use
36 sn macro_rules
37 sn tfn (Test function)
38 sn tmod (Test module)
39 "#]],
40 )
41 }
42
43 #[test]
44 fn in_source_file_item_list() {
45 check(
46 r#"$0"#,
47 expect![[r#"
48 ma makro!(…) macro_rules! makro
49 md module
50 kw const
51 kw crate::
52 kw enum
53 kw extern
54 kw fn
55 kw impl
56 kw mod
57 kw pub
58 kw pub(crate)
59 kw pub(super)
60 kw self::
61 kw static
62 kw struct
63 kw trait
64 kw type
65 kw union
66 kw unsafe
67 kw use
68 sn macro_rules
69 sn tfn (Test function)
70 sn tmod (Test module)
71 "#]],
72 )
73 }
74
75 #[test]
76 fn in_item_list_after_attr() {
77 check(
78 r#"#[attr] $0"#,
79 expect![[r#"
80 ma makro!(…) macro_rules! makro
81 md module
82 kw const
83 kw crate::
84 kw enum
85 kw extern
86 kw fn
87 kw impl
88 kw mod
89 kw pub
90 kw pub(crate)
91 kw pub(super)
92 kw self::
93 kw static
94 kw struct
95 kw trait
96 kw type
97 kw union
98 kw unsafe
99 kw use
100 sn macro_rules
101 sn tfn (Test function)
102 sn tmod (Test module)
103 "#]],
104 )
105 }
106
107 #[test]
108 fn in_qualified_path() {
109 check(
110 r#"crate::$0"#,
111 expect![[r#"
112 ma makro!(…) macro_rules! makro
113 md module
114 "#]],
115 )
116 }
117
118 #[test]
119 fn after_unsafe_token() {
120 check(
121 r#"unsafe $0"#,
122 expect![[r#"
123 kw fn
124 kw impl
125 kw trait
126 "#]],
127 );
128 }
129
130 #[test]
131 fn after_visibility() {
132 check(
133 r#"pub $0"#,
134 expect![[r#"
135 kw const
136 kw enum
137 kw extern
138 kw fn
139 kw mod
140 kw static
141 kw struct
142 kw trait
143 kw type
144 kw union
145 kw unsafe
146 kw use
147 "#]],
148 );
149 }
150
151 #[test]
152 fn after_visibility_unsafe() {
153 check(
154 r#"pub unsafe $0"#,
155 expect![[r#"
156 kw fn
157 kw trait
158 "#]],
159 );
160 }
161
162 #[test]
163 fn in_impl_assoc_item_list() {
164 check(
165 r#"impl Struct { $0 }"#,
166 expect![[r#"
167 ma makro!(…) macro_rules! makro
168 md module
169 kw const
170 kw crate::
171 kw fn
172 kw pub
173 kw pub(crate)
174 kw pub(super)
175 kw self::
176 kw unsafe
177 "#]],
178 )
179 }
180
181 #[test]
182 fn in_impl_assoc_item_list_after_attr() {
183 check(
184 r#"impl Struct { #[attr] $0 }"#,
185 expect![[r#"
186 ma makro!(…) macro_rules! makro
187 md module
188 kw const
189 kw crate::
190 kw fn
191 kw pub
192 kw pub(crate)
193 kw pub(super)
194 kw self::
195 kw unsafe
196 "#]],
197 )
198 }
199
200 #[test]
201 fn in_trait_assoc_item_list() {
202 check(
203 r"trait Foo { $0 }",
204 expect![[r#"
205 ma makro!(…) macro_rules! makro
206 md module
207 kw const
208 kw crate::
209 kw fn
210 kw self::
211 kw type
212 kw unsafe
213 "#]],
214 );
215 }
216
217 #[test]
218 fn in_trait_impl_assoc_item_list() {
219 check(
220 r#"
221 trait Test {
222 type Type0;
223 type Type1;
224 const CONST0: ();
225 const CONST1: ();
226 fn function0();
227 fn function1();
228 }
229
230 impl Test for () {
231 type Type0 = ();
232 const CONST0: () = ();
233 fn function0() {}
234 $0
235 }
236 "#,
237 expect![[r#"
238 ct const CONST1: () =
239 fn fn function1()
240 ma makro!(…) macro_rules! makro
241 md module
242 ta type Type1 =
243 kw crate::
244 kw self::
245 "#]],
246 );
247 }
248
249 #[test]
250 fn after_unit_struct() {
251 check(
252 r#"struct S; f$0"#,
253 expect![[r#"
254 ma makro!(…) macro_rules! makro
255 md module
256 kw const
257 kw crate::
258 kw enum
259 kw extern
260 kw fn
261 kw impl
262 kw mod
263 kw pub
264 kw pub(crate)
265 kw pub(super)
266 kw self::
267 kw static
268 kw struct
269 kw trait
270 kw type
271 kw union
272 kw unsafe
273 kw use
274 sn macro_rules
275 sn tfn (Test function)
276 sn tmod (Test module)
277 "#]],
278 );
279 }
280
281 #[test]
282 fn type_in_impl_trait() {
283 check_edit(
284 "type O",
285 r"
286 struct A;
287 trait B {
288 type O: ?Sized;
289 }
290 impl B for A {
291 $0
292 }
293 ",
294 r#"
295 struct A;
296 trait B {
297 type O: ?Sized;
298 }
299 impl B for A {
300 type O = $0;
301 }
302 "#,
303 );
304 check_edit(
305 "type O",
306 r"
307 struct A;
308 trait B {
309 type O;
310 }
311 impl B for A {
312 $0
313 }
314 ",
315 r#"
316 struct A;
317 trait B {
318 type O;
319 }
320 impl B for A {
321 type O = $0;
322 }
323 "#,
324 );
325 check_edit(
326 "type O",
327 r"
328 struct A;
329 trait B {
330 type O: ?Sized = u32;
331 }
332 impl B for A {
333 $0
334 }
335 ",
336 r#"
337 struct A;
338 trait B {
339 type O: ?Sized = u32;
340 }
341 impl B for A {
342 type O = $0;
343 }
344 "#,
345 );
346 check_edit(
347 "type O",
348 r"
349 struct A;
350 trait B {
351 type O = u32;
352 }
353 impl B for A {
354 $0
355 }
356 ",
357 r"
358 struct A;
359 trait B {
360 type O = u32;
361 }
362 impl B for A {
363 type O = $0;
364 }
365 ",
366 )
367 }