]> git.lizzy.rs Git - rust.git/blob - crates/ide_completion/src/tests/type_pos.rs
a76f97f3da3f611ab9ea4b0269a7bb5c9889644c
[rust.git] / crates / ide_completion / src / tests / type_pos.rs
1 //! Completion tests for type position.
2 use expect_test::{expect, Expect};
3
4 use crate::tests::{completion_list, BASE_ITEMS_FIXTURE};
5
6 fn check(ra_fixture: &str, expect: Expect) {
7     let actual = completion_list(&format!("{}\n{}", BASE_ITEMS_FIXTURE, ra_fixture));
8     expect.assert_eq(&actual)
9 }
10
11 #[test]
12 fn record_field_ty() {
13     check(
14         r#"
15 struct Foo<'lt, T, const C: usize> {
16     f: $0
17 }
18 "#,
19         expect![[r##"
20             kw self
21             kw super
22             kw crate
23             sp Self
24             tp T
25             tt Trait
26             en Enum
27             st Record
28             st Tuple
29             md module
30             st Foo<…>
31             st Unit
32             ma makro!(…) #[macro_export] macro_rules! makro
33             un Union
34             bt u32
35         "##]],
36     )
37 }
38
39 #[test]
40 fn tuple_struct_field() {
41     check(
42         r#"
43 struct Foo<'lt, T, const C: usize>(f$0);
44 "#,
45         expect![[r##"
46             kw pub(crate)
47             kw pub(super)
48             kw pub
49             kw self
50             kw super
51             kw crate
52             sp Self
53             tp T
54             tt Trait
55             en Enum
56             st Record
57             st Tuple
58             md module
59             st Foo<…>
60             st Unit
61             ma makro!(…)  #[macro_export] macro_rules! makro
62             un Union
63             bt u32
64         "##]],
65     )
66 }
67
68 #[test]
69 fn fn_return_type() {
70     check(
71         r#"
72 fn x<'lt, T, const C: usize>() -> $0
73 "#,
74         expect![[r##"
75             kw self
76             kw super
77             kw crate
78             tp T
79             tt Trait
80             en Enum
81             st Record
82             st Tuple
83             md module
84             st Unit
85             ma makro!(…) #[macro_export] macro_rules! makro
86             un Union
87             bt u32
88         "##]],
89     );
90 }
91
92 #[test]
93 fn body_type_pos() {
94     check(
95         r#"
96 fn foo<'lt, T, const C: usize>() {
97     let local = ();
98     let _: $0;
99 }
100 "#,
101         expect![[r##"
102             kw self
103             kw super
104             kw crate
105             tp T
106             tt Trait
107             en Enum
108             st Record
109             st Tuple
110             md module
111             st Unit
112             ma makro!(…) #[macro_export] macro_rules! makro
113             un Union
114             bt u32
115         "##]],
116     );
117     check(
118         r#"
119 fn foo<'lt, T, const C: usize>() {
120     let local = ();
121     let _: self::$0;
122 }
123 "#,
124         expect![[r##"
125             tt Trait
126             en Enum
127             st Record
128             st Tuple
129             md module
130             st Unit
131             ma makro!(…) #[macro_export] macro_rules! makro
132             un Union
133         "##]],
134     );
135 }
136
137 #[test]
138 fn completes_types_and_const_in_arg_list() {
139     check(
140         r#"
141 trait Trait2 {
142     type Foo;
143 }
144
145 fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {}
146 "#,
147         expect![[r##"
148             kw self
149             kw super
150             kw crate
151             ta Foo =  (as Trait2) type Foo;
152             tp T
153             cp CONST_PARAM
154             tt Trait
155             en Enum
156             st Record
157             st Tuple
158             md module
159             st Unit
160             ma makro!(…)          #[macro_export] macro_rules! makro
161             tt Trait2
162             un Union
163             ct CONST
164             bt u32
165         "##]],
166     );
167     check(
168         r#"
169 trait Trait2 {
170     type Foo;
171 }
172
173 fn foo<'lt, T: Trait2<self::$0>, const CONST_PARAM: usize>(_: T) {}
174     "#,
175         expect![[r##"
176             tt Trait
177             en Enum
178             st Record
179             st Tuple
180             md module
181             st Unit
182             ma makro!(…) #[macro_export] macro_rules! makro
183             tt Trait2
184             un Union
185             ct CONST
186         "##]],
187     );
188 }
189
190 #[test]
191 fn enum_qualified() {
192     check(
193         r#"
194 impl Enum {
195     type AssocType = ();
196     const ASSOC_CONST: () = ();
197     fn assoc_fn() {}
198 }
199 fn func(_: Enum::$0) {}
200 "#,
201         expect![[r#"
202             ta AssocType type AssocType;
203         "#]],
204     );
205 }