diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-17 13:38:52 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-17 13:38:52 +0100 |
commit | 23df3834333a4db1449b2ba52e878ade47d1dfb2 (patch) | |
tree | 33f5b632ed98ffd6cbd7d670b4d9ee79893e31de /crates/ra_hir_def/src/nameres/tests/mod_resolution.rs | |
parent | 2ca0e9e00e5a55bd591ae0a85fb00918b111e063 (diff) | |
parent | fcdac030335ba58e8267f3414101d4c2edb3797c (diff) |
Merge #5422
5422: Rewrite def map tests from insta to expect r=matklad a=matklad
Those indentation markers are annoying...
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/nameres/tests/mod_resolution.rs')
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/mod_resolution.rs | 1257 |
1 files changed, 608 insertions, 649 deletions
diff --git a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs index 753684201..3da16fbe3 100644 --- a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs +++ b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs | |||
@@ -3,710 +3,672 @@ use super::*; | |||
3 | #[test] | 3 | #[test] |
4 | fn name_res_works_for_broken_modules() { | 4 | fn name_res_works_for_broken_modules() { |
5 | mark::check!(name_res_works_for_broken_modules); | 5 | mark::check!(name_res_works_for_broken_modules); |
6 | let map = def_map( | 6 | check( |
7 | r" | 7 | r" |
8 | //- /lib.rs | 8 | //- /lib.rs |
9 | mod foo // no `;`, no body | 9 | mod foo // no `;`, no body |
10 | 10 | use self::foo::Baz; | |
11 | use self::foo::Baz; | 11 | |
12 | 12 | //- /foo/mod.rs | |
13 | //- /foo/mod.rs | 13 | pub mod bar; |
14 | pub mod bar; | 14 | pub use self::bar::Baz; |
15 | 15 | ||
16 | pub use self::bar::Baz; | 16 | //- /foo/bar.rs |
17 | 17 | pub struct Baz; | |
18 | //- /foo/bar.rs | 18 | ", |
19 | pub struct Baz; | 19 | expect![[r#" |
20 | ", | 20 | crate |
21 | Baz: _ | ||
22 | foo: t | ||
23 | |||
24 | crate::foo | ||
25 | "#]], | ||
21 | ); | 26 | ); |
22 | assert_snapshot!(map, @r###" | ||
23 | crate | ||
24 | Baz: _ | ||
25 | foo: t | ||
26 | |||
27 | crate::foo | ||
28 | "###); | ||
29 | } | 27 | } |
30 | 28 | ||
31 | #[test] | 29 | #[test] |
32 | fn nested_module_resolution() { | 30 | fn nested_module_resolution() { |
33 | let map = def_map( | 31 | check( |
34 | r" | 32 | r#" |
35 | //- /lib.rs | 33 | //- /lib.rs |
36 | mod n1; | 34 | mod n1; |
37 | 35 | ||
38 | //- /n1.rs | 36 | //- /n1.rs |
39 | mod n2; | 37 | mod n2; |
40 | 38 | ||
41 | //- /n1/n2.rs | 39 | //- /n1/n2.rs |
42 | struct X; | 40 | struct X; |
43 | ", | 41 | "#, |
42 | expect![[r#" | ||
43 | crate | ||
44 | n1: t | ||
45 | |||
46 | crate::n1 | ||
47 | n2: t | ||
48 | |||
49 | crate::n1::n2 | ||
50 | X: t v | ||
51 | "#]], | ||
44 | ); | 52 | ); |
45 | |||
46 | assert_snapshot!(map, @r###" | ||
47 | â‹®crate | ||
48 | â‹®n1: t | ||
49 | â‹® | ||
50 | â‹®crate::n1 | ||
51 | â‹®n2: t | ||
52 | â‹® | ||
53 | â‹®crate::n1::n2 | ||
54 | â‹®X: t v | ||
55 | "###); | ||
56 | } | 53 | } |
57 | 54 | ||
58 | #[test] | 55 | #[test] |
59 | fn nested_module_resolution_2() { | 56 | fn nested_module_resolution_2() { |
60 | let map = def_map( | 57 | check( |
61 | r" | 58 | r#" |
62 | //- /lib.rs | 59 | //- /lib.rs |
63 | mod prelude; | 60 | mod prelude; |
64 | mod iter; | 61 | mod iter; |
65 | 62 | ||
66 | //- /prelude.rs | 63 | //- /prelude.rs |
67 | pub use crate::iter::Iterator; | 64 | pub use crate::iter::Iterator; |
68 | 65 | ||
69 | //- /iter.rs | 66 | //- /iter.rs |
70 | pub use self::traits::Iterator; | 67 | pub use self::traits::Iterator; |
71 | mod traits; | 68 | mod traits; |
72 | 69 | ||
73 | //- /iter/traits.rs | 70 | //- /iter/traits.rs |
74 | pub use self::iterator::Iterator; | 71 | pub use self::iterator::Iterator; |
75 | mod iterator; | 72 | mod iterator; |
76 | 73 | ||
77 | //- /iter/traits/iterator.rs | 74 | //- /iter/traits/iterator.rs |
78 | pub trait Iterator; | 75 | pub trait Iterator; |
79 | ", | 76 | "#, |
77 | expect![[r#" | ||
78 | crate | ||
79 | iter: t | ||
80 | prelude: t | ||
81 | |||
82 | crate::iter | ||
83 | Iterator: t | ||
84 | traits: t | ||
85 | |||
86 | crate::iter::traits | ||
87 | Iterator: t | ||
88 | iterator: t | ||
89 | |||
90 | crate::iter::traits::iterator | ||
91 | Iterator: t | ||
92 | |||
93 | crate::prelude | ||
94 | Iterator: t | ||
95 | "#]], | ||
80 | ); | 96 | ); |
81 | |||
82 | assert_snapshot!(map, @r###" | ||
83 | â‹®crate | ||
84 | â‹®iter: t | ||
85 | â‹®prelude: t | ||
86 | â‹® | ||
87 | â‹®crate::iter | ||
88 | â‹®Iterator: t | ||
89 | â‹®traits: t | ||
90 | â‹® | ||
91 | â‹®crate::iter::traits | ||
92 | â‹®Iterator: t | ||
93 | â‹®iterator: t | ||
94 | â‹® | ||
95 | â‹®crate::iter::traits::iterator | ||
96 | â‹®Iterator: t | ||
97 | â‹® | ||
98 | â‹®crate::prelude | ||
99 | â‹®Iterator: t | ||
100 | "###); | ||
101 | } | 97 | } |
102 | 98 | ||
103 | #[test] | 99 | #[test] |
104 | fn module_resolution_works_for_non_standard_filenames() { | 100 | fn module_resolution_works_for_non_standard_filenames() { |
105 | let map = def_map( | 101 | check( |
106 | " | 102 | r#" |
107 | //- /my_library.rs crate:my_library | 103 | //- /my_library.rs crate:my_library |
108 | mod foo; | 104 | mod foo; |
109 | use self::foo::Bar; | 105 | use self::foo::Bar; |
110 | 106 | ||
111 | //- /foo/mod.rs | 107 | //- /foo/mod.rs |
112 | pub struct Bar; | 108 | pub struct Bar; |
113 | ", | 109 | "#, |
110 | expect![[r#" | ||
111 | crate | ||
112 | Bar: t v | ||
113 | foo: t | ||
114 | |||
115 | crate::foo | ||
116 | Bar: t v | ||
117 | "#]], | ||
114 | ); | 118 | ); |
115 | |||
116 | assert_snapshot!(map, @r###" | ||
117 | â‹®crate | ||
118 | â‹®Bar: t v | ||
119 | â‹®foo: t | ||
120 | â‹® | ||
121 | â‹®crate::foo | ||
122 | â‹®Bar: t v | ||
123 | "###); | ||
124 | } | 119 | } |
125 | 120 | ||
126 | #[test] | 121 | #[test] |
127 | fn module_resolution_works_for_raw_modules() { | 122 | fn module_resolution_works_for_raw_modules() { |
128 | let map = def_map( | 123 | check( |
129 | " | 124 | r#" |
130 | //- /lib.rs | 125 | //- /lib.rs |
131 | mod r#async; | 126 | mod r#async; |
132 | use self::r#async::Bar; | 127 | use self::r#async::Bar; |
133 | 128 | ||
134 | //- /async.rs | 129 | //- /async.rs |
135 | pub struct Bar; | 130 | pub struct Bar; |
136 | ", | 131 | "#, |
132 | expect![[r#" | ||
133 | crate | ||
134 | Bar: t v | ||
135 | async: t | ||
136 | |||
137 | crate::async | ||
138 | Bar: t v | ||
139 | "#]], | ||
137 | ); | 140 | ); |
138 | |||
139 | assert_snapshot!(map, @r###" | ||
140 | â‹®crate | ||
141 | â‹®Bar: t v | ||
142 | â‹®async: t | ||
143 | â‹® | ||
144 | â‹®crate::async | ||
145 | â‹®Bar: t v | ||
146 | "###); | ||
147 | } | 141 | } |
148 | 142 | ||
149 | #[test] | 143 | #[test] |
150 | fn module_resolution_decl_path() { | 144 | fn module_resolution_decl_path() { |
151 | let map = def_map( | 145 | check( |
152 | r###" | 146 | r#" |
153 | //- /lib.rs | 147 | //- /lib.rs |
154 | #[path = "bar/baz/foo.rs"] | 148 | #[path = "bar/baz/foo.rs"] |
155 | mod foo; | 149 | mod foo; |
156 | use self::foo::Bar; | 150 | use self::foo::Bar; |
157 | 151 | ||
158 | //- /bar/baz/foo.rs | 152 | //- /bar/baz/foo.rs |
159 | pub struct Bar; | 153 | pub struct Bar; |
160 | "###, | 154 | "#, |
155 | expect![[r#" | ||
156 | crate | ||
157 | Bar: t v | ||
158 | foo: t | ||
159 | |||
160 | crate::foo | ||
161 | Bar: t v | ||
162 | "#]], | ||
161 | ); | 163 | ); |
162 | |||
163 | assert_snapshot!(map, @r###" | ||
164 | â‹®crate | ||
165 | â‹®Bar: t v | ||
166 | â‹®foo: t | ||
167 | â‹® | ||
168 | â‹®crate::foo | ||
169 | â‹®Bar: t v | ||
170 | "###); | ||
171 | } | 164 | } |
172 | 165 | ||
173 | #[test] | 166 | #[test] |
174 | fn module_resolution_module_with_path_in_mod_rs() { | 167 | fn module_resolution_module_with_path_in_mod_rs() { |
175 | let map = def_map( | 168 | check( |
176 | r###" | 169 | r#" |
177 | //- /main.rs | 170 | //- /main.rs |
178 | mod foo; | 171 | mod foo; |
179 | 172 | ||
180 | //- /foo/mod.rs | 173 | //- /foo/mod.rs |
181 | #[path = "baz.rs"] | 174 | #[path = "baz.rs"] |
182 | pub mod bar; | 175 | pub mod bar; |
183 | 176 | use self::bar::Baz; | |
184 | use self::bar::Baz; | 177 | |
185 | 178 | //- /foo/baz.rs | |
186 | //- /foo/baz.rs | 179 | pub struct Baz; |
187 | pub struct Baz; | 180 | "#, |
188 | "###, | 181 | expect![[r#" |
182 | crate | ||
183 | foo: t | ||
184 | |||
185 | crate::foo | ||
186 | Baz: t v | ||
187 | bar: t | ||
188 | |||
189 | crate::foo::bar | ||
190 | Baz: t v | ||
191 | "#]], | ||
189 | ); | 192 | ); |
190 | |||
191 | assert_snapshot!(map, @r###" | ||
192 | â‹®crate | ||
193 | â‹®foo: t | ||
194 | â‹® | ||
195 | â‹®crate::foo | ||
196 | â‹®Baz: t v | ||
197 | â‹®bar: t | ||
198 | â‹® | ||
199 | â‹®crate::foo::bar | ||
200 | â‹®Baz: t v | ||
201 | "###); | ||
202 | } | 193 | } |
203 | 194 | ||
204 | #[test] | 195 | #[test] |
205 | fn module_resolution_module_with_path_non_crate_root() { | 196 | fn module_resolution_module_with_path_non_crate_root() { |
206 | let map = def_map( | 197 | check( |
207 | r###" | 198 | r#" |
208 | //- /main.rs | 199 | //- /main.rs |
209 | mod foo; | 200 | mod foo; |
210 | 201 | ||
211 | //- /foo.rs | 202 | //- /foo.rs |
212 | #[path = "baz.rs"] | 203 | #[path = "baz.rs"] |
213 | pub mod bar; | 204 | pub mod bar; |
214 | 205 | use self::bar::Baz; | |
215 | use self::bar::Baz; | 206 | |
216 | 207 | //- /baz.rs | |
217 | //- /baz.rs | 208 | pub struct Baz; |
218 | pub struct Baz; | 209 | "#, |
219 | "###, | 210 | expect![[r#" |
211 | crate | ||
212 | foo: t | ||
213 | |||
214 | crate::foo | ||
215 | Baz: t v | ||
216 | bar: t | ||
217 | |||
218 | crate::foo::bar | ||
219 | Baz: t v | ||
220 | "#]], | ||
220 | ); | 221 | ); |
221 | |||
222 | assert_snapshot!(map, @r###" | ||
223 | â‹®crate | ||
224 | â‹®foo: t | ||
225 | â‹® | ||
226 | â‹®crate::foo | ||
227 | â‹®Baz: t v | ||
228 | â‹®bar: t | ||
229 | â‹® | ||
230 | â‹®crate::foo::bar | ||
231 | â‹®Baz: t v | ||
232 | "###); | ||
233 | } | 222 | } |
234 | 223 | ||
235 | #[test] | 224 | #[test] |
236 | fn module_resolution_module_decl_path_super() { | 225 | fn module_resolution_module_decl_path_super() { |
237 | let map = def_map( | 226 | check( |
238 | r###" | 227 | r#" |
239 | //- /main.rs | 228 | //- /main.rs |
240 | #[path = "bar/baz/module.rs"] | 229 | #[path = "bar/baz/module.rs"] |
241 | mod foo; | 230 | mod foo; |
242 | pub struct Baz; | 231 | pub struct Baz; |
243 | 232 | ||
244 | //- /bar/baz/module.rs | 233 | //- /bar/baz/module.rs |
245 | use super::Baz; | 234 | use super::Baz; |
246 | "###, | 235 | "#, |
236 | expect![[r#" | ||
237 | crate | ||
238 | Baz: t v | ||
239 | foo: t | ||
240 | |||
241 | crate::foo | ||
242 | Baz: t v | ||
243 | "#]], | ||
247 | ); | 244 | ); |
248 | |||
249 | assert_snapshot!(map, @r###" | ||
250 | â‹®crate | ||
251 | â‹®Baz: t v | ||
252 | â‹®foo: t | ||
253 | â‹® | ||
254 | â‹®crate::foo | ||
255 | â‹®Baz: t v | ||
256 | "###); | ||
257 | } | 245 | } |
258 | 246 | ||
259 | #[test] | 247 | #[test] |
260 | fn module_resolution_explicit_path_mod_rs() { | 248 | fn module_resolution_explicit_path_mod_rs() { |
261 | let map = def_map( | 249 | check( |
262 | r###" | 250 | r#" |
263 | //- /main.rs | 251 | //- /main.rs |
264 | #[path = "module/mod.rs"] | 252 | #[path = "module/mod.rs"] |
265 | mod foo; | 253 | mod foo; |
266 | 254 | ||
267 | //- /module/mod.rs | 255 | //- /module/mod.rs |
268 | pub struct Baz; | 256 | pub struct Baz; |
269 | "###, | 257 | "#, |
258 | expect![[r#" | ||
259 | crate | ||
260 | foo: t | ||
261 | |||
262 | crate::foo | ||
263 | Baz: t v | ||
264 | "#]], | ||
270 | ); | 265 | ); |
271 | |||
272 | assert_snapshot!(map, @r###" | ||
273 | â‹®crate | ||
274 | â‹®foo: t | ||
275 | â‹® | ||
276 | â‹®crate::foo | ||
277 | â‹®Baz: t v | ||
278 | "###); | ||
279 | } | 266 | } |
280 | 267 | ||
281 | #[test] | 268 | #[test] |
282 | fn module_resolution_relative_path() { | 269 | fn module_resolution_relative_path() { |
283 | let map = def_map( | 270 | check( |
284 | r###" | 271 | r#" |
285 | //- /main.rs | 272 | //- /main.rs |
286 | mod foo; | 273 | mod foo; |
287 | 274 | ||
288 | //- /foo.rs | 275 | //- /foo.rs |
289 | #[path = "./sub.rs"] | 276 | #[path = "./sub.rs"] |
290 | pub mod foo_bar; | 277 | pub mod foo_bar; |
291 | 278 | ||
292 | //- /sub.rs | 279 | //- /sub.rs |
293 | pub struct Baz; | 280 | pub struct Baz; |
294 | "###, | 281 | "#, |
282 | expect![[r#" | ||
283 | crate | ||
284 | foo: t | ||
285 | |||
286 | crate::foo | ||
287 | foo_bar: t | ||
288 | |||
289 | crate::foo::foo_bar | ||
290 | Baz: t v | ||
291 | "#]], | ||
295 | ); | 292 | ); |
296 | |||
297 | assert_snapshot!(map, @r###" | ||
298 | â‹®crate | ||
299 | â‹®foo: t | ||
300 | â‹® | ||
301 | â‹®crate::foo | ||
302 | â‹®foo_bar: t | ||
303 | â‹® | ||
304 | â‹®crate::foo::foo_bar | ||
305 | â‹®Baz: t v | ||
306 | "###); | ||
307 | } | 293 | } |
308 | 294 | ||
309 | #[test] | 295 | #[test] |
310 | fn module_resolution_relative_path_2() { | 296 | fn module_resolution_relative_path_2() { |
311 | let map = def_map( | 297 | check( |
312 | r###" | 298 | r#" |
313 | //- /main.rs | 299 | //- /main.rs |
314 | mod foo; | 300 | mod foo; |
315 | 301 | ||
316 | //- /foo/mod.rs | 302 | //- /foo/mod.rs |
317 | #[path="../sub.rs"] | 303 | #[path="../sub.rs"] |
318 | pub mod foo_bar; | 304 | pub mod foo_bar; |
319 | 305 | ||
320 | //- /sub.rs | 306 | //- /sub.rs |
321 | pub struct Baz; | 307 | pub struct Baz; |
322 | "###, | 308 | "#, |
309 | expect![[r#" | ||
310 | crate | ||
311 | foo: t | ||
312 | |||
313 | crate::foo | ||
314 | foo_bar: t | ||
315 | |||
316 | crate::foo::foo_bar | ||
317 | Baz: t v | ||
318 | "#]], | ||
323 | ); | 319 | ); |
324 | |||
325 | assert_snapshot!(map, @r###" | ||
326 | â‹®crate | ||
327 | â‹®foo: t | ||
328 | â‹® | ||
329 | â‹®crate::foo | ||
330 | â‹®foo_bar: t | ||
331 | â‹® | ||
332 | â‹®crate::foo::foo_bar | ||
333 | â‹®Baz: t v | ||
334 | "###); | ||
335 | } | 320 | } |
336 | 321 | ||
337 | #[test] | 322 | #[test] |
338 | fn module_resolution_relative_path_outside_root() { | 323 | fn module_resolution_relative_path_outside_root() { |
339 | let map = def_map( | 324 | check( |
340 | r###" | 325 | r#" |
341 | //- /main.rs | 326 | //- /main.rs |
342 | 327 | #[path="../../../../../outside.rs"] | |
343 | #[path="../../../../../outside.rs"] | 328 | mod foo; |
344 | mod foo; | 329 | "#, |
345 | "###, | 330 | expect![[r#" |
331 | crate | ||
332 | "#]], | ||
346 | ); | 333 | ); |
347 | |||
348 | assert_snapshot!(map, @r###" | ||
349 | â‹®crate | ||
350 | "###); | ||
351 | } | 334 | } |
352 | 335 | ||
353 | #[test] | 336 | #[test] |
354 | fn module_resolution_explicit_path_mod_rs_2() { | 337 | fn module_resolution_explicit_path_mod_rs_2() { |
355 | let map = def_map( | 338 | check( |
356 | r###" | 339 | r#" |
357 | //- /main.rs | 340 | //- /main.rs |
358 | #[path = "module/bar/mod.rs"] | 341 | #[path = "module/bar/mod.rs"] |
359 | mod foo; | 342 | mod foo; |
360 | 343 | ||
361 | //- /module/bar/mod.rs | 344 | //- /module/bar/mod.rs |
362 | pub struct Baz; | 345 | pub struct Baz; |
363 | "###, | 346 | "#, |
347 | expect![[r#" | ||
348 | crate | ||
349 | foo: t | ||
350 | |||
351 | crate::foo | ||
352 | Baz: t v | ||
353 | "#]], | ||
364 | ); | 354 | ); |
365 | |||
366 | assert_snapshot!(map, @r###" | ||
367 | â‹®crate | ||
368 | â‹®foo: t | ||
369 | â‹® | ||
370 | â‹®crate::foo | ||
371 | â‹®Baz: t v | ||
372 | "###); | ||
373 | } | 355 | } |
374 | 356 | ||
375 | #[test] | 357 | #[test] |
376 | fn module_resolution_explicit_path_mod_rs_with_win_separator() { | 358 | fn module_resolution_explicit_path_mod_rs_with_win_separator() { |
377 | let map = def_map( | 359 | check( |
378 | r###" | 360 | r#" |
379 | //- /main.rs | 361 | //- /main.rs |
380 | #[path = "module\bar\mod.rs"] | 362 | #[path = "module\bar\mod.rs"] |
381 | mod foo; | 363 | mod foo; |
382 | 364 | ||
383 | //- /module/bar/mod.rs | 365 | //- /module/bar/mod.rs |
384 | pub struct Baz; | 366 | pub struct Baz; |
385 | "###, | 367 | "#, |
368 | expect![[r#" | ||
369 | crate | ||
370 | foo: t | ||
371 | |||
372 | crate::foo | ||
373 | Baz: t v | ||
374 | "#]], | ||
386 | ); | 375 | ); |
387 | |||
388 | assert_snapshot!(map, @r###" | ||
389 | â‹®crate | ||
390 | â‹®foo: t | ||
391 | â‹® | ||
392 | â‹®crate::foo | ||
393 | â‹®Baz: t v | ||
394 | "###); | ||
395 | } | 376 | } |
396 | 377 | ||
397 | #[test] | 378 | #[test] |
398 | fn module_resolution_decl_inside_inline_module_with_path_attribute() { | 379 | fn module_resolution_decl_inside_inline_module_with_path_attribute() { |
399 | let map = def_map( | 380 | check( |
400 | r###" | 381 | r#" |
401 | //- /main.rs | 382 | //- /main.rs |
402 | #[path = "models"] | 383 | #[path = "models"] |
403 | mod foo { | 384 | mod foo { mod bar; } |
404 | mod bar; | 385 | |
405 | } | 386 | //- /models/bar.rs |
406 | 387 | pub struct Baz; | |
407 | //- /models/bar.rs | 388 | "#, |
408 | pub struct Baz; | 389 | expect![[r#" |
409 | "###, | 390 | crate |
391 | foo: t | ||
392 | |||
393 | crate::foo | ||
394 | bar: t | ||
395 | |||
396 | crate::foo::bar | ||
397 | Baz: t v | ||
398 | "#]], | ||
410 | ); | 399 | ); |
411 | |||
412 | assert_snapshot!(map, @r###" | ||
413 | â‹®crate | ||
414 | â‹®foo: t | ||
415 | â‹® | ||
416 | â‹®crate::foo | ||
417 | â‹®bar: t | ||
418 | â‹® | ||
419 | â‹®crate::foo::bar | ||
420 | â‹®Baz: t v | ||
421 | "###); | ||
422 | } | 400 | } |
423 | 401 | ||
424 | #[test] | 402 | #[test] |
425 | fn module_resolution_decl_inside_inline_module() { | 403 | fn module_resolution_decl_inside_inline_module() { |
426 | let map = def_map( | 404 | check( |
427 | r###" | 405 | r#" |
428 | //- /main.rs | 406 | //- /main.rs |
429 | mod foo { | 407 | mod foo { mod bar; } |
430 | mod bar; | 408 | |
431 | } | 409 | //- /foo/bar.rs |
432 | 410 | pub struct Baz; | |
433 | //- /foo/bar.rs | 411 | "#, |
434 | pub struct Baz; | 412 | expect![[r#" |
435 | "###, | 413 | crate |
414 | foo: t | ||
415 | |||
416 | crate::foo | ||
417 | bar: t | ||
418 | |||
419 | crate::foo::bar | ||
420 | Baz: t v | ||
421 | "#]], | ||
436 | ); | 422 | ); |
437 | |||
438 | assert_snapshot!(map, @r###" | ||
439 | â‹®crate | ||
440 | â‹®foo: t | ||
441 | â‹® | ||
442 | â‹®crate::foo | ||
443 | â‹®bar: t | ||
444 | â‹® | ||
445 | â‹®crate::foo::bar | ||
446 | â‹®Baz: t v | ||
447 | "###); | ||
448 | } | 423 | } |
449 | 424 | ||
450 | #[test] | 425 | #[test] |
451 | fn module_resolution_decl_inside_inline_module_2_with_path_attribute() { | 426 | fn module_resolution_decl_inside_inline_module_2_with_path_attribute() { |
452 | let map = def_map( | 427 | check( |
453 | r###" | 428 | r#" |
454 | //- /main.rs | 429 | //- /main.rs |
455 | #[path = "models/db"] | 430 | #[path = "models/db"] |
456 | mod foo { | 431 | mod foo { mod bar; } |
457 | mod bar; | 432 | |
458 | } | 433 | //- /models/db/bar.rs |
459 | 434 | pub struct Baz; | |
460 | //- /models/db/bar.rs | 435 | "#, |
461 | pub struct Baz; | 436 | expect![[r#" |
462 | "###, | 437 | crate |
438 | foo: t | ||
439 | |||
440 | crate::foo | ||
441 | bar: t | ||
442 | |||
443 | crate::foo::bar | ||
444 | Baz: t v | ||
445 | "#]], | ||
463 | ); | 446 | ); |
464 | |||
465 | assert_snapshot!(map, @r###" | ||
466 | â‹®crate | ||
467 | â‹®foo: t | ||
468 | â‹® | ||
469 | â‹®crate::foo | ||
470 | â‹®bar: t | ||
471 | â‹® | ||
472 | â‹®crate::foo::bar | ||
473 | â‹®Baz: t v | ||
474 | "###); | ||
475 | } | 447 | } |
476 | 448 | ||
477 | #[test] | 449 | #[test] |
478 | fn module_resolution_decl_inside_inline_module_3() { | 450 | fn module_resolution_decl_inside_inline_module_3() { |
479 | let map = def_map( | 451 | check( |
480 | r###" | 452 | r#" |
481 | //- /main.rs | 453 | //- /main.rs |
482 | #[path = "models/db"] | 454 | #[path = "models/db"] |
483 | mod foo { | 455 | mod foo { |
484 | #[path = "users.rs"] | 456 | #[path = "users.rs"] |
485 | mod bar; | 457 | mod bar; |
486 | } | 458 | } |
487 | |||
488 | //- /models/db/users.rs | ||
489 | pub struct Baz; | ||
490 | "###, | ||
491 | ); | ||
492 | 459 | ||
493 | assert_snapshot!(map, @r###" | 460 | //- /models/db/users.rs |
494 | â‹®crate | 461 | pub struct Baz; |
495 | â‹®foo: t | 462 | "#, |
496 | â‹® | 463 | expect![[r#" |
497 | â‹®crate::foo | 464 | crate |
498 | â‹®bar: t | 465 | foo: t |
499 | â‹® | 466 | |
500 | â‹®crate::foo::bar | 467 | crate::foo |
501 | â‹®Baz: t v | 468 | bar: t |
502 | "###); | 469 | |
470 | crate::foo::bar | ||
471 | Baz: t v | ||
472 | "#]], | ||
473 | ); | ||
503 | } | 474 | } |
504 | 475 | ||
505 | #[test] | 476 | #[test] |
506 | fn module_resolution_decl_inside_inline_module_empty_path() { | 477 | fn module_resolution_decl_inside_inline_module_empty_path() { |
507 | let map = def_map( | 478 | check( |
508 | r###" | 479 | r#" |
509 | //- /main.rs | 480 | //- /main.rs |
510 | #[path = ""] | 481 | #[path = ""] |
511 | mod foo { | 482 | mod foo { |
512 | #[path = "users.rs"] | 483 | #[path = "users.rs"] |
513 | mod bar; | 484 | mod bar; |
514 | } | 485 | } |
515 | 486 | ||
516 | //- /users.rs | 487 | //- /users.rs |
517 | pub struct Baz; | 488 | pub struct Baz; |
518 | "###, | 489 | "#, |
519 | ); | 490 | expect![[r#" |
491 | crate | ||
492 | foo: t | ||
520 | 493 | ||
521 | assert_snapshot!(map, @r###" | 494 | crate::foo |
522 | â‹®crate | 495 | bar: t |
523 | â‹®foo: t | 496 | |
524 | â‹® | 497 | crate::foo::bar |
525 | â‹®crate::foo | 498 | Baz: t v |
526 | â‹®bar: t | 499 | "#]], |
527 | â‹® | 500 | ); |
528 | â‹®crate::foo::bar | ||
529 | â‹®Baz: t v | ||
530 | "###); | ||
531 | } | 501 | } |
532 | 502 | ||
533 | #[test] | 503 | #[test] |
534 | fn module_resolution_decl_empty_path() { | 504 | fn module_resolution_decl_empty_path() { |
535 | let map = def_map( | 505 | check( |
536 | r###" | 506 | r#" |
537 | //- /main.rs | 507 | //- /main.rs |
538 | #[path = ""] // Should try to read `/` (a directory) | 508 | #[path = ""] // Should try to read `/` (a directory) |
539 | mod foo; | 509 | mod foo; |
540 | 510 | ||
541 | //- /foo.rs | 511 | //- /foo.rs |
542 | pub struct Baz; | 512 | pub struct Baz; |
543 | "###, | 513 | "#, |
514 | expect![[r#" | ||
515 | crate | ||
516 | "#]], | ||
544 | ); | 517 | ); |
545 | |||
546 | assert_snapshot!(map, @r###" | ||
547 | â‹®crate | ||
548 | "###); | ||
549 | } | 518 | } |
550 | 519 | ||
551 | #[test] | 520 | #[test] |
552 | fn module_resolution_decl_inside_inline_module_relative_path() { | 521 | fn module_resolution_decl_inside_inline_module_relative_path() { |
553 | let map = def_map( | 522 | check( |
554 | r###" | 523 | r#" |
555 | //- /main.rs | 524 | //- /main.rs |
556 | #[path = "./models"] | 525 | #[path = "./models"] |
557 | mod foo { | 526 | mod foo { mod bar; } |
558 | mod bar; | 527 | |
559 | } | 528 | //- /models/bar.rs |
560 | 529 | pub struct Baz; | |
561 | //- /models/bar.rs | 530 | "#, |
562 | pub struct Baz; | 531 | expect![[r#" |
563 | "###, | 532 | crate |
533 | foo: t | ||
534 | |||
535 | crate::foo | ||
536 | bar: t | ||
537 | |||
538 | crate::foo::bar | ||
539 | Baz: t v | ||
540 | "#]], | ||
564 | ); | 541 | ); |
565 | |||
566 | assert_snapshot!(map, @r###" | ||
567 | â‹®crate | ||
568 | â‹®foo: t | ||
569 | â‹® | ||
570 | â‹®crate::foo | ||
571 | â‹®bar: t | ||
572 | â‹® | ||
573 | â‹®crate::foo::bar | ||
574 | â‹®Baz: t v | ||
575 | "###); | ||
576 | } | 542 | } |
577 | 543 | ||
578 | #[test] | 544 | #[test] |
579 | fn module_resolution_decl_inside_inline_module_in_crate_root() { | 545 | fn module_resolution_decl_inside_inline_module_in_crate_root() { |
580 | let map = def_map( | 546 | check( |
581 | r###" | 547 | r#" |
582 | //- /main.rs | 548 | //- /main.rs |
583 | mod foo { | 549 | mod foo { |
584 | #[path = "baz.rs"] | 550 | #[path = "baz.rs"] |
585 | mod bar; | 551 | mod bar; |
586 | } | 552 | } |
587 | use self::foo::bar::Baz; | 553 | use self::foo::bar::Baz; |
588 | 554 | ||
589 | //- /foo/baz.rs | 555 | //- /foo/baz.rs |
590 | pub struct Baz; | 556 | pub struct Baz; |
591 | "###, | 557 | "#, |
558 | expect![[r#" | ||
559 | crate | ||
560 | Baz: t v | ||
561 | foo: t | ||
562 | |||
563 | crate::foo | ||
564 | bar: t | ||
565 | |||
566 | crate::foo::bar | ||
567 | Baz: t v | ||
568 | "#]], | ||
592 | ); | 569 | ); |
593 | |||
594 | assert_snapshot!(map, @r###" | ||
595 | â‹®crate | ||
596 | â‹®Baz: t v | ||
597 | â‹®foo: t | ||
598 | â‹® | ||
599 | â‹®crate::foo | ||
600 | â‹®bar: t | ||
601 | â‹® | ||
602 | â‹®crate::foo::bar | ||
603 | â‹®Baz: t v | ||
604 | "###); | ||
605 | } | 570 | } |
606 | 571 | ||
607 | #[test] | 572 | #[test] |
608 | fn module_resolution_decl_inside_inline_module_in_mod_rs() { | 573 | fn module_resolution_decl_inside_inline_module_in_mod_rs() { |
609 | let map = def_map( | 574 | check( |
610 | r###" | 575 | r#" |
611 | //- /main.rs | 576 | //- /main.rs |
612 | mod foo; | 577 | mod foo; |
578 | |||
579 | //- /foo/mod.rs | ||
580 | mod bar { | ||
581 | #[path = "qwe.rs"] | ||
582 | pub mod baz; | ||
583 | } | ||
584 | use self::bar::baz::Baz; | ||
613 | 585 | ||
614 | //- /foo/mod.rs | 586 | //- /foo/bar/qwe.rs |
615 | mod bar { | 587 | pub struct Baz; |
616 | #[path = "qwe.rs"] | 588 | "#, |
617 | pub mod baz; | 589 | expect![[r#" |
618 | } | 590 | crate |
619 | use self::bar::baz::Baz; | 591 | foo: t |
620 | 592 | ||
621 | //- /foo/bar/qwe.rs | 593 | crate::foo |
622 | pub struct Baz; | 594 | Baz: t v |
623 | "###, | 595 | bar: t |
624 | ); | 596 | |
597 | crate::foo::bar | ||
598 | baz: t | ||
625 | 599 | ||
626 | assert_snapshot!(map, @r###" | 600 | crate::foo::bar::baz |
627 | â‹®crate | 601 | Baz: t v |
628 | â‹®foo: t | 602 | "#]], |
629 | â‹® | 603 | ); |
630 | â‹®crate::foo | ||
631 | â‹®Baz: t v | ||
632 | â‹®bar: t | ||
633 | â‹® | ||
634 | â‹®crate::foo::bar | ||
635 | â‹®baz: t | ||
636 | â‹® | ||
637 | â‹®crate::foo::bar::baz | ||
638 | â‹®Baz: t v | ||
639 | "###); | ||
640 | } | 604 | } |
641 | 605 | ||
642 | #[test] | 606 | #[test] |
643 | fn module_resolution_decl_inside_inline_module_in_non_crate_root() { | 607 | fn module_resolution_decl_inside_inline_module_in_non_crate_root() { |
644 | let map = def_map( | 608 | check( |
645 | r###" | 609 | r#" |
646 | //- /main.rs | 610 | //- /main.rs |
647 | mod foo; | 611 | mod foo; |
612 | |||
613 | //- /foo.rs | ||
614 | mod bar { | ||
615 | #[path = "qwe.rs"] | ||
616 | pub mod baz; | ||
617 | } | ||
618 | use self::bar::baz::Baz; | ||
648 | 619 | ||
649 | //- /foo.rs | 620 | //- /foo/bar/qwe.rs |
650 | mod bar { | 621 | pub struct Baz; |
651 | #[path = "qwe.rs"] | 622 | "#, |
652 | pub mod baz; | 623 | expect![[r#" |
653 | } | 624 | crate |
654 | use self::bar::baz::Baz; | 625 | foo: t |
655 | 626 | ||
656 | //- /foo/bar/qwe.rs | 627 | crate::foo |
657 | pub struct Baz; | 628 | Baz: t v |
658 | "###, | 629 | bar: t |
659 | ); | ||
660 | 630 | ||
661 | assert_snapshot!(map, @r###" | 631 | crate::foo::bar |
662 | â‹®crate | 632 | baz: t |
663 | â‹®foo: t | 633 | |
664 | â‹® | 634 | crate::foo::bar::baz |
665 | â‹®crate::foo | 635 | Baz: t v |
666 | â‹®Baz: t v | 636 | "#]], |
667 | â‹®bar: t | 637 | ); |
668 | â‹® | ||
669 | â‹®crate::foo::bar | ||
670 | â‹®baz: t | ||
671 | â‹® | ||
672 | â‹®crate::foo::bar::baz | ||
673 | â‹®Baz: t v | ||
674 | "###); | ||
675 | } | 638 | } |
676 | 639 | ||
677 | #[test] | 640 | #[test] |
678 | fn module_resolution_decl_inside_inline_module_in_non_crate_root_2() { | 641 | fn module_resolution_decl_inside_inline_module_in_non_crate_root_2() { |
679 | let map = def_map( | 642 | check( |
680 | r###" | 643 | r#" |
681 | //- /main.rs | 644 | //- /main.rs |
682 | mod foo; | 645 | mod foo; |
646 | |||
647 | //- /foo.rs | ||
648 | #[path = "bar"] | ||
649 | mod bar { | ||
650 | pub mod baz; | ||
651 | } | ||
652 | use self::bar::baz::Baz; | ||
683 | 653 | ||
684 | //- /foo.rs | 654 | //- /bar/baz.rs |
685 | #[path = "bar"] | 655 | pub struct Baz; |
686 | mod bar { | 656 | "#, |
687 | pub mod baz; | 657 | expect![[r#" |
688 | } | 658 | crate |
689 | use self::bar::baz::Baz; | 659 | foo: t |
690 | |||
691 | //- /bar/baz.rs | ||
692 | pub struct Baz; | ||
693 | "###, | ||
694 | ); | ||
695 | 660 | ||
696 | assert_snapshot!(map, @r###" | 661 | crate::foo |
697 | â‹®crate | 662 | Baz: t v |
698 | â‹®foo: t | 663 | bar: t |
699 | â‹® | 664 | |
700 | â‹®crate::foo | 665 | crate::foo::bar |
701 | â‹®Baz: t v | 666 | baz: t |
702 | â‹®bar: t | 667 | |
703 | â‹® | 668 | crate::foo::bar::baz |
704 | â‹®crate::foo::bar | 669 | Baz: t v |
705 | â‹®baz: t | 670 | "#]], |
706 | â‹® | 671 | ); |
707 | â‹®crate::foo::bar::baz | ||
708 | â‹®Baz: t v | ||
709 | "###); | ||
710 | } | 672 | } |
711 | 673 | ||
712 | #[test] | 674 | #[test] |
@@ -749,91 +711,88 @@ fn unresolved_module_diagnostics() { | |||
749 | 711 | ||
750 | #[test] | 712 | #[test] |
751 | fn module_resolution_decl_inside_module_in_non_crate_root_2() { | 713 | fn module_resolution_decl_inside_module_in_non_crate_root_2() { |
752 | let map = def_map( | 714 | check( |
753 | r###" | 715 | r#" |
754 | //- /main.rs | 716 | //- /main.rs |
755 | #[path="module/m2.rs"] | 717 | #[path="module/m2.rs"] |
756 | mod module; | 718 | mod module; |
757 | 719 | ||
758 | //- /module/m2.rs | 720 | //- /module/m2.rs |
759 | pub mod submod; | 721 | pub mod submod; |
760 | 722 | ||
761 | //- /module/submod.rs | 723 | //- /module/submod.rs |
762 | pub struct Baz; | 724 | pub struct Baz; |
763 | "###, | 725 | "#, |
726 | expect![[r#" | ||
727 | crate | ||
728 | module: t | ||
729 | |||
730 | crate::module | ||
731 | submod: t | ||
732 | |||
733 | crate::module::submod | ||
734 | Baz: t v | ||
735 | "#]], | ||
764 | ); | 736 | ); |
765 | |||
766 | assert_snapshot!(map, @r###" | ||
767 | â‹®crate | ||
768 | â‹®module: t | ||
769 | â‹® | ||
770 | â‹®crate::module | ||
771 | â‹®submod: t | ||
772 | â‹® | ||
773 | â‹®crate::module::submod | ||
774 | â‹®Baz: t v | ||
775 | "###); | ||
776 | } | 737 | } |
777 | 738 | ||
778 | #[test] | 739 | #[test] |
779 | fn nested_out_of_line_module() { | 740 | fn nested_out_of_line_module() { |
780 | let map = def_map( | 741 | check( |
781 | r###" | 742 | r#" |
782 | //- /lib.rs | 743 | //- /lib.rs |
783 | mod a { | 744 | mod a { |
784 | mod b { | 745 | mod b { |
785 | mod c; | 746 | mod c; |
786 | } | 747 | } |
787 | } | 748 | } |
788 | |||
789 | //- /a/b/c.rs | ||
790 | struct X; | ||
791 | "###, | ||
792 | ); | ||
793 | 749 | ||
794 | assert_snapshot!(map, @r###" | 750 | //- /a/b/c.rs |
795 | â‹®crate | 751 | struct X; |
796 | â‹®a: t | 752 | "#, |
797 | â‹® | 753 | expect![[r#" |
798 | â‹®crate::a | 754 | crate |
799 | â‹®b: t | 755 | a: t |
800 | â‹® | 756 | |
801 | â‹®crate::a::b | 757 | crate::a |
802 | â‹®c: t | 758 | b: t |
803 | â‹® | 759 | |
804 | â‹®crate::a::b::c | 760 | crate::a::b |
805 | â‹®X: t v | 761 | c: t |
806 | "###); | 762 | |
763 | crate::a::b::c | ||
764 | X: t v | ||
765 | "#]], | ||
766 | ); | ||
807 | } | 767 | } |
808 | 768 | ||
809 | #[test] | 769 | #[test] |
810 | fn nested_out_of_line_module_with_path() { | 770 | fn nested_out_of_line_module_with_path() { |
811 | let map = def_map( | 771 | check( |
812 | r###" | 772 | r#" |
813 | //- /lib.rs | 773 | //- /lib.rs |
814 | mod a { | 774 | mod a { |
815 | #[path = "d/e"] | 775 | #[path = "d/e"] |
816 | mod b { | 776 | mod b { |
817 | mod c; | 777 | mod c; |
818 | } | 778 | } |
819 | } | 779 | } |
820 | 780 | ||
821 | //- /a/d/e/c.rs | 781 | //- /a/d/e/c.rs |
822 | struct X; | 782 | struct X; |
823 | "###, | 783 | "#, |
824 | ); | 784 | expect![[r#" |
785 | crate | ||
786 | a: t | ||
825 | 787 | ||
826 | assert_snapshot!(map, @r###" | 788 | crate::a |
827 | â‹®crate | 789 | b: t |
828 | â‹®a: t | 790 | |
829 | â‹® | 791 | crate::a::b |
830 | â‹®crate::a | 792 | c: t |
831 | â‹®b: t | 793 | |
832 | â‹® | 794 | crate::a::b::c |
833 | â‹®crate::a::b | 795 | X: t v |
834 | â‹®c: t | 796 | "#]], |
835 | â‹® | 797 | ); |
836 | â‹®crate::a::b::c | ||
837 | â‹®X: t v | ||
838 | "###); | ||
839 | } | 798 | } |