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