]> git.lizzy.rs Git - rust.git/blob - crates/ide_completion/src/tests/use_tree.rs
Simplify macro rendering, remove constructor structs
[rust.git] / crates / ide_completion / src / tests / use_tree.rs
1 //! Completion tests for use trees.
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 #[test]
12 fn use_tree_start() {
13     cov_mark::check!(unqualified_path_only_modules_in_import);
14     check(
15         r#"
16 //- /lib.rs crate:main deps:other_crate
17 use f$0
18
19 struct Foo;
20 mod foo {}
21 //- /other_crate/lib.rs crate:other_crate
22 // nothing here
23 "#,
24         expect![[r#"
25             md foo
26             md other_crate
27             kw self::
28             kw super::
29             kw crate::
30         "#]],
31     );
32 }
33
34 #[test]
35 fn dont_complete_current_use() {
36     cov_mark::check!(dont_complete_current_use);
37     check(r#"use self::foo$0;"#, expect![[r#""#]]);
38     check(
39         r#"
40 mod foo { pub struct S; }
41 use self::{foo::*, bar$0};
42 "#,
43         expect![[r#"
44             st S
45             md foo
46         "#]],
47     );
48 }
49
50 #[test]
51 fn nested_use_tree() {
52     check(
53         r#"
54 mod foo {
55     pub mod bar {
56         pub struct FooBar;
57     }
58 }
59 use foo::{bar::$0}
60 "#,
61         expect![[r#"
62             st FooBar
63         "#]],
64     );
65     check(
66         r#"
67 mod foo {
68     pub mod bar {
69         pub struct FooBar;
70     }
71 }
72 use foo::{$0}
73 "#,
74         expect![[r#"
75             kw self
76             md bar
77         "#]],
78     );
79 }
80
81 #[test]
82 fn deeply_nested_use_tree() {
83     check(
84         r#"
85 mod foo {
86     pub mod bar {
87         pub mod baz {
88             pub struct FooBarBaz;
89         }
90     }
91 }
92 use foo::{bar::{baz::$0}}
93 "#,
94         expect![[r#"
95             st FooBarBaz
96         "#]],
97     );
98     check(
99         r#"
100 mod foo {
101     pub mod bar {
102         pub mod baz {
103             pub struct FooBarBaz;
104         }
105     }
106 }
107 use foo::{bar::{$0}}
108 "#,
109         expect![[r#"
110             kw self
111             md baz
112         "#]],
113     );
114 }
115
116 #[test]
117 fn plain_qualified_use_tree() {
118     check(
119         r#"
120 use foo::$0
121
122 mod foo {
123     struct Private;
124     pub struct Foo;
125     macro_rules! foo_ { {} => {} }
126     pub use foo_ as foo;
127 }
128 struct Bar;
129 "#,
130         expect![[r#"
131             st Foo
132             ma foo macro_rules! foo_
133         "#]],
134     );
135 }
136
137 #[test]
138 fn self_qualified_use_tree() {
139     check(
140         r#"
141 use self::$0
142
143 mod foo {}
144 struct Bar;
145 "#,
146         expect![[r#"
147             md foo
148             st Bar
149         "#]],
150     );
151 }
152
153 #[test]
154 fn super_qualified_use_tree() {
155     check(
156         r#"
157 mod bar {
158     use super::$0
159 }
160
161 mod foo {}
162 struct Bar;
163 "#,
164         expect![[r#"
165             kw super::
166             st Bar
167             md bar
168             md foo
169         "#]],
170     );
171 }
172
173 #[test]
174 fn super_super_qualified_use_tree() {
175     check(
176         r#"
177 mod a {
178     const A: usize = 0;
179     mod b {
180         const B: usize = 0;
181         mod c { use super::super::$0 }
182     }
183 }
184 "#,
185         expect![[r#"
186             kw super::
187             md b
188             ct A
189         "#]],
190     );
191 }
192
193 #[test]
194 fn crate_qualified_use_tree() {
195     check(
196         r#"
197 use crate::$0
198
199 mod foo {}
200 struct Bar;
201 "#,
202         expect![[r#"
203             md foo
204             st Bar
205         "#]],
206     );
207 }
208
209 #[test]
210 fn extern_crate_qualified_use_tree() {
211     check(
212         r#"
213 //- /lib.rs crate:main deps:other_crate
214 use other_crate::$0
215 //- /other_crate/lib.rs crate:other_crate
216 pub struct Foo;
217 pub mod foo {}
218 "#,
219         expect![[r#"
220             st Foo
221             md foo
222         "#]],
223     );
224 }
225
226 #[test]
227 fn pub_use_tree() {
228     check(
229         r#"
230 pub struct X;
231 pub mod bar {}
232 pub use $0;
233 "#,
234         expect![[r#"
235             md bar
236             kw self::
237             kw super::
238             kw crate::
239         "#]],
240     );
241 }
242
243 #[test]
244 fn use_tree_braces_at_start() {
245     check(
246         r#"
247 struct X;
248 mod bar {}
249 use {$0};
250 "#,
251         expect![[r#"
252             md bar
253             kw self::
254             kw super::
255             kw crate::
256         "#]],
257     );
258 }
259
260 #[test]
261 fn impl_prefix_does_not_add_fn_snippet() {
262     // regression test for 7222
263     check(
264         r#"
265 mod foo {
266     pub fn bar(x: u32) {}
267 }
268 use self::foo::impl$0
269 "#,
270         expect![[r#"
271             fn bar fn(u32)
272         "#]],
273     );
274 }