diff options
Diffstat (limited to 'crates/hir_def/src/nameres/tests/globs.rs')
-rw-r--r-- | crates/hir_def/src/nameres/tests/globs.rs | 338 |
1 files changed, 338 insertions, 0 deletions
diff --git a/crates/hir_def/src/nameres/tests/globs.rs b/crates/hir_def/src/nameres/tests/globs.rs new file mode 100644 index 000000000..2ae836e3c --- /dev/null +++ b/crates/hir_def/src/nameres/tests/globs.rs | |||
@@ -0,0 +1,338 @@ | |||
1 | use super::*; | ||
2 | |||
3 | #[test] | ||
4 | fn glob_1() { | ||
5 | check( | ||
6 | r#" | ||
7 | //- /lib.rs | ||
8 | mod foo; | ||
9 | use foo::*; | ||
10 | |||
11 | //- /foo/mod.rs | ||
12 | pub mod bar; | ||
13 | pub use self::bar::Baz; | ||
14 | pub struct Foo; | ||
15 | |||
16 | //- /foo/bar.rs | ||
17 | pub struct Baz; | ||
18 | "#, | ||
19 | expect![[r#" | ||
20 | crate | ||
21 | Baz: t v | ||
22 | Foo: t v | ||
23 | bar: t | ||
24 | foo: t | ||
25 | |||
26 | crate::foo | ||
27 | Baz: t v | ||
28 | Foo: t v | ||
29 | bar: t | ||
30 | |||
31 | crate::foo::bar | ||
32 | Baz: t v | ||
33 | "#]], | ||
34 | ); | ||
35 | } | ||
36 | |||
37 | #[test] | ||
38 | fn glob_2() { | ||
39 | check( | ||
40 | r#" | ||
41 | //- /lib.rs | ||
42 | mod foo; | ||
43 | use foo::*; | ||
44 | |||
45 | //- /foo/mod.rs | ||
46 | pub mod bar; | ||
47 | pub use self::bar::*; | ||
48 | pub struct Foo; | ||
49 | |||
50 | //- /foo/bar.rs | ||
51 | pub struct Baz; | ||
52 | pub use super::*; | ||
53 | "#, | ||
54 | expect![[r#" | ||
55 | crate | ||
56 | Baz: t v | ||
57 | Foo: t v | ||
58 | bar: t | ||
59 | foo: t | ||
60 | |||
61 | crate::foo | ||
62 | Baz: t v | ||
63 | Foo: t v | ||
64 | bar: t | ||
65 | |||
66 | crate::foo::bar | ||
67 | Baz: t v | ||
68 | Foo: t v | ||
69 | bar: t | ||
70 | "#]], | ||
71 | ); | ||
72 | } | ||
73 | |||
74 | #[test] | ||
75 | fn glob_privacy_1() { | ||
76 | check( | ||
77 | r" | ||
78 | //- /lib.rs | ||
79 | mod foo; | ||
80 | use foo::*; | ||
81 | |||
82 | //- /foo/mod.rs | ||
83 | pub mod bar; | ||
84 | pub use self::bar::*; | ||
85 | struct PrivateStructFoo; | ||
86 | |||
87 | //- /foo/bar.rs | ||
88 | pub struct Baz; | ||
89 | struct PrivateStructBar; | ||
90 | pub use super::*; | ||
91 | ", | ||
92 | expect![[r#" | ||
93 | crate | ||
94 | Baz: t v | ||
95 | bar: t | ||
96 | foo: t | ||
97 | |||
98 | crate::foo | ||
99 | Baz: t v | ||
100 | PrivateStructFoo: t v | ||
101 | bar: t | ||
102 | |||
103 | crate::foo::bar | ||
104 | Baz: t v | ||
105 | PrivateStructBar: t v | ||
106 | PrivateStructFoo: t v | ||
107 | bar: t | ||
108 | "#]], | ||
109 | ); | ||
110 | } | ||
111 | |||
112 | #[test] | ||
113 | fn glob_privacy_2() { | ||
114 | check( | ||
115 | r" | ||
116 | //- /lib.rs | ||
117 | mod foo; | ||
118 | use foo::*; | ||
119 | use foo::bar::*; | ||
120 | |||
121 | //- /foo/mod.rs | ||
122 | mod bar; | ||
123 | fn Foo() {}; | ||
124 | pub struct Foo {}; | ||
125 | |||
126 | //- /foo/bar.rs | ||
127 | pub(super) struct PrivateBaz; | ||
128 | struct PrivateBar; | ||
129 | pub(crate) struct PubCrateStruct; | ||
130 | ", | ||
131 | expect![[r#" | ||
132 | crate | ||
133 | Foo: t | ||
134 | PubCrateStruct: t v | ||
135 | foo: t | ||
136 | |||
137 | crate::foo | ||
138 | Foo: t v | ||
139 | bar: t | ||
140 | |||
141 | crate::foo::bar | ||
142 | PrivateBar: t v | ||
143 | PrivateBaz: t v | ||
144 | PubCrateStruct: t v | ||
145 | "#]], | ||
146 | ); | ||
147 | } | ||
148 | |||
149 | #[test] | ||
150 | fn glob_across_crates() { | ||
151 | mark::check!(glob_across_crates); | ||
152 | check( | ||
153 | r#" | ||
154 | //- /main.rs crate:main deps:test_crate | ||
155 | use test_crate::*; | ||
156 | |||
157 | //- /lib.rs crate:test_crate | ||
158 | pub struct Baz; | ||
159 | "#, | ||
160 | expect![[r#" | ||
161 | crate | ||
162 | Baz: t v | ||
163 | "#]], | ||
164 | ); | ||
165 | } | ||
166 | |||
167 | #[test] | ||
168 | fn glob_privacy_across_crates() { | ||
169 | check( | ||
170 | r#" | ||
171 | //- /main.rs crate:main deps:test_crate | ||
172 | use test_crate::*; | ||
173 | |||
174 | //- /lib.rs crate:test_crate | ||
175 | pub struct Baz; | ||
176 | struct Foo; | ||
177 | "#, | ||
178 | expect![[r#" | ||
179 | crate | ||
180 | Baz: t v | ||
181 | "#]], | ||
182 | ); | ||
183 | } | ||
184 | |||
185 | #[test] | ||
186 | fn glob_enum() { | ||
187 | mark::check!(glob_enum); | ||
188 | check( | ||
189 | r#" | ||
190 | enum Foo { Bar, Baz } | ||
191 | use self::Foo::*; | ||
192 | "#, | ||
193 | expect![[r#" | ||
194 | crate | ||
195 | Bar: t v | ||
196 | Baz: t v | ||
197 | Foo: t | ||
198 | "#]], | ||
199 | ); | ||
200 | } | ||
201 | |||
202 | #[test] | ||
203 | fn glob_enum_group() { | ||
204 | mark::check!(glob_enum_group); | ||
205 | check( | ||
206 | r#" | ||
207 | enum Foo { Bar, Baz } | ||
208 | use self::Foo::{*}; | ||
209 | "#, | ||
210 | expect![[r#" | ||
211 | crate | ||
212 | Bar: t v | ||
213 | Baz: t v | ||
214 | Foo: t | ||
215 | "#]], | ||
216 | ); | ||
217 | } | ||
218 | |||
219 | #[test] | ||
220 | fn glob_shadowed_def() { | ||
221 | mark::check!(import_shadowed); | ||
222 | check( | ||
223 | r#" | ||
224 | //- /lib.rs | ||
225 | mod foo; | ||
226 | mod bar; | ||
227 | use foo::*; | ||
228 | use bar::baz; | ||
229 | use baz::Bar; | ||
230 | |||
231 | //- /foo.rs | ||
232 | pub mod baz { pub struct Foo; } | ||
233 | |||
234 | //- /bar.rs | ||
235 | pub mod baz { pub struct Bar; } | ||
236 | "#, | ||
237 | expect![[r#" | ||
238 | crate | ||
239 | Bar: t v | ||
240 | bar: t | ||
241 | baz: t | ||
242 | foo: t | ||
243 | |||
244 | crate::bar | ||
245 | baz: t | ||
246 | |||
247 | crate::bar::baz | ||
248 | Bar: t v | ||
249 | |||
250 | crate::foo | ||
251 | baz: t | ||
252 | |||
253 | crate::foo::baz | ||
254 | Foo: t v | ||
255 | "#]], | ||
256 | ); | ||
257 | } | ||
258 | |||
259 | #[test] | ||
260 | fn glob_shadowed_def_reversed() { | ||
261 | check( | ||
262 | r#" | ||
263 | //- /lib.rs | ||
264 | mod foo; | ||
265 | mod bar; | ||
266 | use bar::baz; | ||
267 | use foo::*; | ||
268 | use baz::Bar; | ||
269 | |||
270 | //- /foo.rs | ||
271 | pub mod baz { pub struct Foo; } | ||
272 | |||
273 | //- /bar.rs | ||
274 | pub mod baz { pub struct Bar; } | ||
275 | "#, | ||
276 | expect![[r#" | ||
277 | crate | ||
278 | Bar: t v | ||
279 | bar: t | ||
280 | baz: t | ||
281 | foo: t | ||
282 | |||
283 | crate::bar | ||
284 | baz: t | ||
285 | |||
286 | crate::bar::baz | ||
287 | Bar: t v | ||
288 | |||
289 | crate::foo | ||
290 | baz: t | ||
291 | |||
292 | crate::foo::baz | ||
293 | Foo: t v | ||
294 | "#]], | ||
295 | ); | ||
296 | } | ||
297 | |||
298 | #[test] | ||
299 | fn glob_shadowed_def_dependencies() { | ||
300 | check( | ||
301 | r#" | ||
302 | mod a { pub mod foo { pub struct X; } } | ||
303 | mod b { pub use super::a::foo; } | ||
304 | mod c { pub mod foo { pub struct Y; } } | ||
305 | mod d { | ||
306 | use super::c::foo; | ||
307 | use super::b::*; | ||
308 | use foo::Y; | ||
309 | } | ||
310 | "#, | ||
311 | expect![[r#" | ||
312 | crate | ||
313 | a: t | ||
314 | b: t | ||
315 | c: t | ||
316 | d: t | ||
317 | |||
318 | crate::d | ||
319 | Y: t v | ||
320 | foo: t | ||
321 | |||
322 | crate::c | ||
323 | foo: t | ||
324 | |||
325 | crate::c::foo | ||
326 | Y: t v | ||
327 | |||
328 | crate::b | ||
329 | foo: t | ||
330 | |||
331 | crate::a | ||
332 | foo: t | ||
333 | |||
334 | crate::a::foo | ||
335 | X: t v | ||
336 | "#]], | ||
337 | ); | ||
338 | } | ||