diff options
author | Aleksey Kladov <[email protected]> | 2019-11-03 20:35:48 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-03 20:35:48 +0000 |
commit | 6fba51c5fc05264abcbf971dcf28142746588d74 (patch) | |
tree | edbdbf98b279802ee8dc03f35e941943e1e20e10 /crates/ra_hir/src | |
parent | 0933d914a37c4ab57fda6fe95464d194dab6f80c (diff) |
move crate_def_map tests to hir_def
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 573 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests/globs.rs | 118 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests/incremental.rs | 140 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests/macros.rs | 635 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests/mod_resolution.rs | 759 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests/primitives.rs | 24 |
7 files changed, 0 insertions, 2252 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index bb775cfc9..875addc84 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -47,9 +47,6 @@ | |||
47 | //! path and, upon success, we run macro expansion and "collect module" phase | 47 | //! path and, upon success, we run macro expansion and "collect module" phase |
48 | //! on the result | 48 | //! on the result |
49 | 49 | ||
50 | #[cfg(test)] | ||
51 | mod tests; | ||
52 | |||
53 | pub use hir_def::nameres::{ | 50 | pub use hir_def::nameres::{ |
54 | per_ns::{Namespace, PerNs}, | 51 | per_ns::{Namespace, PerNs}, |
55 | raw::ImportId, | 52 | raw::ImportId, |
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs deleted file mode 100644 index 02db91a86..000000000 --- a/crates/ra_hir/src/nameres/tests.rs +++ /dev/null | |||
@@ -1,573 +0,0 @@ | |||
1 | mod macros; | ||
2 | mod globs; | ||
3 | mod incremental; | ||
4 | mod primitives; | ||
5 | mod mod_resolution; | ||
6 | |||
7 | use std::sync::Arc; | ||
8 | |||
9 | use hir_def::{db::DefDatabase2, nameres::*, CrateModuleId}; | ||
10 | use insta::assert_snapshot; | ||
11 | use ra_db::SourceDatabase; | ||
12 | // use test_utils::covers; | ||
13 | |||
14 | use crate::mock::{CrateGraphFixture, MockDatabase}; | ||
15 | |||
16 | fn compute_crate_def_map(fixture: &str, graph: Option<CrateGraphFixture>) -> Arc<CrateDefMap> { | ||
17 | let mut db = MockDatabase::with_files(fixture); | ||
18 | if let Some(graph) = graph { | ||
19 | db.set_crate_graph_from_fixture(graph); | ||
20 | } | ||
21 | let krate = db.crate_graph().iter().next().unwrap(); | ||
22 | db.crate_def_map(krate) | ||
23 | } | ||
24 | |||
25 | fn render_crate_def_map(map: &CrateDefMap) -> String { | ||
26 | let mut buf = String::new(); | ||
27 | go(&mut buf, map, "\ncrate", map.root()); | ||
28 | return buf.trim().to_string(); | ||
29 | |||
30 | fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: CrateModuleId) { | ||
31 | *buf += path; | ||
32 | *buf += "\n"; | ||
33 | |||
34 | let mut entries = map.modules[module] | ||
35 | .scope | ||
36 | .items | ||
37 | .iter() | ||
38 | .map(|(name, res)| (name, res.def)) | ||
39 | .collect::<Vec<_>>(); | ||
40 | entries.sort_by_key(|(name, _)| *name); | ||
41 | |||
42 | for (name, res) in entries { | ||
43 | *buf += &format!("{}:", name); | ||
44 | |||
45 | if res.types.is_some() { | ||
46 | *buf += " t"; | ||
47 | } | ||
48 | if res.values.is_some() { | ||
49 | *buf += " v"; | ||
50 | } | ||
51 | if res.macros.is_some() { | ||
52 | *buf += " m"; | ||
53 | } | ||
54 | if res.is_none() { | ||
55 | *buf += " _"; | ||
56 | } | ||
57 | |||
58 | *buf += "\n"; | ||
59 | } | ||
60 | |||
61 | for (name, child) in map.modules[module].children.iter() { | ||
62 | let path = path.to_string() + &format!("::{}", name); | ||
63 | go(buf, map, &path, *child); | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | |||
68 | fn def_map(fixtute: &str) -> String { | ||
69 | let dm = compute_crate_def_map(fixtute, None); | ||
70 | render_crate_def_map(&dm) | ||
71 | } | ||
72 | |||
73 | fn def_map_with_crate_graph(fixture: &str, graph: CrateGraphFixture) -> String { | ||
74 | let dm = compute_crate_def_map(fixture, Some(graph)); | ||
75 | render_crate_def_map(&dm) | ||
76 | } | ||
77 | |||
78 | #[test] | ||
79 | fn crate_def_map_smoke_test() { | ||
80 | let map = def_map( | ||
81 | " | ||
82 | //- /lib.rs | ||
83 | mod foo; | ||
84 | struct S; | ||
85 | use crate::foo::bar::E; | ||
86 | use self::E::V; | ||
87 | |||
88 | //- /foo/mod.rs | ||
89 | pub mod bar; | ||
90 | fn f() {} | ||
91 | |||
92 | //- /foo/bar.rs | ||
93 | pub struct Baz; | ||
94 | enum E { V } | ||
95 | ", | ||
96 | ); | ||
97 | assert_snapshot!(map, @r###" | ||
98 | ⋮crate | ||
99 | ⋮E: t | ||
100 | ⋮S: t v | ||
101 | ⋮V: t v | ||
102 | ⋮foo: t | ||
103 | ⋮ | ||
104 | ⋮crate::foo | ||
105 | ⋮bar: t | ||
106 | ⋮f: v | ||
107 | ⋮ | ||
108 | ⋮crate::foo::bar | ||
109 | ⋮Baz: t v | ||
110 | ⋮E: t | ||
111 | "###) | ||
112 | } | ||
113 | |||
114 | #[test] | ||
115 | fn bogus_paths() { | ||
116 | // covers!(bogus_paths); | ||
117 | let map = def_map( | ||
118 | " | ||
119 | //- /lib.rs | ||
120 | mod foo; | ||
121 | struct S; | ||
122 | use self; | ||
123 | |||
124 | //- /foo/mod.rs | ||
125 | use super; | ||
126 | use crate; | ||
127 | |||
128 | ", | ||
129 | ); | ||
130 | assert_snapshot!(map, @r###" | ||
131 | ⋮crate | ||
132 | ⋮S: t v | ||
133 | ⋮foo: t | ||
134 | ⋮ | ||
135 | ⋮crate::foo | ||
136 | "### | ||
137 | ) | ||
138 | } | ||
139 | |||
140 | #[test] | ||
141 | fn use_as() { | ||
142 | let map = def_map( | ||
143 | " | ||
144 | //- /lib.rs | ||
145 | mod foo; | ||
146 | |||
147 | use crate::foo::Baz as Foo; | ||
148 | |||
149 | //- /foo/mod.rs | ||
150 | pub struct Baz; | ||
151 | ", | ||
152 | ); | ||
153 | assert_snapshot!(map, | ||
154 | @r###" | ||
155 | ⋮crate | ||
156 | ⋮Foo: t v | ||
157 | ⋮foo: t | ||
158 | ⋮ | ||
159 | ⋮crate::foo | ||
160 | ⋮Baz: t v | ||
161 | "### | ||
162 | ); | ||
163 | } | ||
164 | |||
165 | #[test] | ||
166 | fn use_trees() { | ||
167 | let map = def_map( | ||
168 | " | ||
169 | //- /lib.rs | ||
170 | mod foo; | ||
171 | |||
172 | use crate::foo::bar::{Baz, Quux}; | ||
173 | |||
174 | //- /foo/mod.rs | ||
175 | pub mod bar; | ||
176 | |||
177 | //- /foo/bar.rs | ||
178 | pub struct Baz; | ||
179 | pub enum Quux {}; | ||
180 | ", | ||
181 | ); | ||
182 | assert_snapshot!(map, @r###" | ||
183 | ⋮crate | ||
184 | ⋮Baz: t v | ||
185 | ⋮Quux: t | ||
186 | ⋮foo: t | ||
187 | ⋮ | ||
188 | ⋮crate::foo | ||
189 | ⋮bar: t | ||
190 | ⋮ | ||
191 | ⋮crate::foo::bar | ||
192 | ⋮Baz: t v | ||
193 | ⋮Quux: t | ||
194 | "###); | ||
195 | } | ||
196 | |||
197 | #[test] | ||
198 | fn re_exports() { | ||
199 | let map = def_map( | ||
200 | " | ||
201 | //- /lib.rs | ||
202 | mod foo; | ||
203 | |||
204 | use self::foo::Baz; | ||
205 | |||
206 | //- /foo/mod.rs | ||
207 | pub mod bar; | ||
208 | |||
209 | pub use self::bar::Baz; | ||
210 | |||
211 | //- /foo/bar.rs | ||
212 | pub struct Baz; | ||
213 | ", | ||
214 | ); | ||
215 | assert_snapshot!(map, @r###" | ||
216 | ⋮crate | ||
217 | ⋮Baz: t v | ||
218 | ⋮foo: t | ||
219 | ⋮ | ||
220 | ⋮crate::foo | ||
221 | ⋮Baz: t v | ||
222 | ⋮bar: t | ||
223 | ⋮ | ||
224 | ⋮crate::foo::bar | ||
225 | ⋮Baz: t v | ||
226 | "###); | ||
227 | } | ||
228 | |||
229 | #[test] | ||
230 | fn std_prelude() { | ||
231 | // covers!(std_prelude); | ||
232 | let map = def_map_with_crate_graph( | ||
233 | " | ||
234 | //- /main.rs | ||
235 | use Foo::*; | ||
236 | |||
237 | //- /lib.rs | ||
238 | mod prelude; | ||
239 | #[prelude_import] | ||
240 | use prelude::*; | ||
241 | |||
242 | //- /prelude.rs | ||
243 | pub enum Foo { Bar, Baz }; | ||
244 | ", | ||
245 | crate_graph! { | ||
246 | "main": ("/main.rs", ["test_crate"]), | ||
247 | "test_crate": ("/lib.rs", []), | ||
248 | }, | ||
249 | ); | ||
250 | assert_snapshot!(map, @r###" | ||
251 | ⋮crate | ||
252 | ⋮Bar: t v | ||
253 | ⋮Baz: t v | ||
254 | "###); | ||
255 | } | ||
256 | |||
257 | #[test] | ||
258 | fn can_import_enum_variant() { | ||
259 | // covers!(can_import_enum_variant); | ||
260 | let map = def_map( | ||
261 | " | ||
262 | //- /lib.rs | ||
263 | enum E { V } | ||
264 | use self::E::V; | ||
265 | ", | ||
266 | ); | ||
267 | assert_snapshot!(map, @r###" | ||
268 | ⋮crate | ||
269 | ⋮E: t | ||
270 | ⋮V: t v | ||
271 | "### | ||
272 | ); | ||
273 | } | ||
274 | |||
275 | #[test] | ||
276 | fn edition_2015_imports() { | ||
277 | let map = def_map_with_crate_graph( | ||
278 | " | ||
279 | //- /main.rs | ||
280 | mod foo; | ||
281 | mod bar; | ||
282 | |||
283 | //- /bar.rs | ||
284 | struct Bar; | ||
285 | |||
286 | //- /foo.rs | ||
287 | use bar::Bar; | ||
288 | use other_crate::FromLib; | ||
289 | |||
290 | //- /lib.rs | ||
291 | struct FromLib; | ||
292 | ", | ||
293 | crate_graph! { | ||
294 | "main": ("/main.rs", "2015", ["other_crate"]), | ||
295 | "other_crate": ("/lib.rs", "2018", []), | ||
296 | }, | ||
297 | ); | ||
298 | |||
299 | assert_snapshot!(map, @r###" | ||
300 | ⋮crate | ||
301 | ⋮bar: t | ||
302 | ⋮foo: t | ||
303 | ⋮ | ||
304 | ⋮crate::bar | ||
305 | ⋮Bar: t v | ||
306 | ⋮ | ||
307 | ⋮crate::foo | ||
308 | ⋮Bar: t v | ||
309 | ⋮FromLib: t v | ||
310 | "###); | ||
311 | } | ||
312 | |||
313 | #[test] | ||
314 | fn item_map_using_self() { | ||
315 | let map = def_map( | ||
316 | " | ||
317 | //- /lib.rs | ||
318 | mod foo; | ||
319 | use crate::foo::bar::Baz::{self}; | ||
320 | //- /foo/mod.rs | ||
321 | pub mod bar; | ||
322 | //- /foo/bar.rs | ||
323 | pub struct Baz; | ||
324 | ", | ||
325 | ); | ||
326 | assert_snapshot!(map, @r###" | ||
327 | ⋮crate | ||
328 | ⋮Baz: t v | ||
329 | ⋮foo: t | ||
330 | ⋮ | ||
331 | ⋮crate::foo | ||
332 | ⋮bar: t | ||
333 | ⋮ | ||
334 | ⋮crate::foo::bar | ||
335 | ⋮Baz: t v | ||
336 | "###); | ||
337 | } | ||
338 | |||
339 | #[test] | ||
340 | fn item_map_across_crates() { | ||
341 | let map = def_map_with_crate_graph( | ||
342 | " | ||
343 | //- /main.rs | ||
344 | use test_crate::Baz; | ||
345 | |||
346 | //- /lib.rs | ||
347 | pub struct Baz; | ||
348 | ", | ||
349 | crate_graph! { | ||
350 | "main": ("/main.rs", ["test_crate"]), | ||
351 | "test_crate": ("/lib.rs", []), | ||
352 | }, | ||
353 | ); | ||
354 | |||
355 | assert_snapshot!(map, @r###" | ||
356 | ⋮crate | ||
357 | ⋮Baz: t v | ||
358 | "###); | ||
359 | } | ||
360 | |||
361 | #[test] | ||
362 | fn extern_crate_rename() { | ||
363 | let map = def_map_with_crate_graph( | ||
364 | " | ||
365 | //- /main.rs | ||
366 | extern crate alloc as alloc_crate; | ||
367 | |||
368 | mod alloc; | ||
369 | mod sync; | ||
370 | |||
371 | //- /sync.rs | ||
372 | use alloc_crate::Arc; | ||
373 | |||
374 | //- /lib.rs | ||
375 | struct Arc; | ||
376 | ", | ||
377 | crate_graph! { | ||
378 | "main": ("/main.rs", ["alloc"]), | ||
379 | "alloc": ("/lib.rs", []), | ||
380 | }, | ||
381 | ); | ||
382 | |||
383 | assert_snapshot!(map, @r###" | ||
384 | ⋮crate | ||
385 | ⋮alloc_crate: t | ||
386 | ⋮sync: t | ||
387 | ⋮ | ||
388 | ⋮crate::sync | ||
389 | ⋮Arc: t v | ||
390 | "###); | ||
391 | } | ||
392 | |||
393 | #[test] | ||
394 | fn extern_crate_rename_2015_edition() { | ||
395 | let map = def_map_with_crate_graph( | ||
396 | " | ||
397 | //- /main.rs | ||
398 | extern crate alloc as alloc_crate; | ||
399 | |||
400 | mod alloc; | ||
401 | mod sync; | ||
402 | |||
403 | //- /sync.rs | ||
404 | use alloc_crate::Arc; | ||
405 | |||
406 | //- /lib.rs | ||
407 | struct Arc; | ||
408 | ", | ||
409 | crate_graph! { | ||
410 | "main": ("/main.rs", "2015", ["alloc"]), | ||
411 | "alloc": ("/lib.rs", []), | ||
412 | }, | ||
413 | ); | ||
414 | |||
415 | assert_snapshot!(map, | ||
416 | @r###" | ||
417 | ⋮crate | ||
418 | ⋮alloc_crate: t | ||
419 | ⋮sync: t | ||
420 | ⋮ | ||
421 | ⋮crate::sync | ||
422 | ⋮Arc: t v | ||
423 | "### | ||
424 | ); | ||
425 | } | ||
426 | |||
427 | #[test] | ||
428 | fn import_across_source_roots() { | ||
429 | let map = def_map_with_crate_graph( | ||
430 | " | ||
431 | //- /lib.rs | ||
432 | pub mod a { | ||
433 | pub mod b { | ||
434 | pub struct C; | ||
435 | } | ||
436 | } | ||
437 | |||
438 | //- root /main/ | ||
439 | |||
440 | //- /main/main.rs | ||
441 | use test_crate::a::b::C; | ||
442 | ", | ||
443 | crate_graph! { | ||
444 | "main": ("/main/main.rs", ["test_crate"]), | ||
445 | "test_crate": ("/lib.rs", []), | ||
446 | }, | ||
447 | ); | ||
448 | |||
449 | assert_snapshot!(map, @r###" | ||
450 | ⋮crate | ||
451 | ⋮C: t v | ||
452 | "###); | ||
453 | } | ||
454 | |||
455 | #[test] | ||
456 | fn reexport_across_crates() { | ||
457 | let map = def_map_with_crate_graph( | ||
458 | " | ||
459 | //- /main.rs | ||
460 | use test_crate::Baz; | ||
461 | |||
462 | //- /lib.rs | ||
463 | pub use foo::Baz; | ||
464 | |||
465 | mod foo; | ||
466 | |||
467 | //- /foo.rs | ||
468 | pub struct Baz; | ||
469 | ", | ||
470 | crate_graph! { | ||
471 | "main": ("/main.rs", ["test_crate"]), | ||
472 | "test_crate": ("/lib.rs", []), | ||
473 | }, | ||
474 | ); | ||
475 | |||
476 | assert_snapshot!(map, @r###" | ||
477 | ⋮crate | ||
478 | ⋮Baz: t v | ||
479 | "###); | ||
480 | } | ||
481 | |||
482 | #[test] | ||
483 | fn values_dont_shadow_extern_crates() { | ||
484 | let map = def_map_with_crate_graph( | ||
485 | " | ||
486 | //- /main.rs | ||
487 | fn foo() {} | ||
488 | use foo::Bar; | ||
489 | |||
490 | //- /foo/lib.rs | ||
491 | pub struct Bar; | ||
492 | ", | ||
493 | crate_graph! { | ||
494 | "main": ("/main.rs", ["foo"]), | ||
495 | "foo": ("/foo/lib.rs", []), | ||
496 | }, | ||
497 | ); | ||
498 | |||
499 | assert_snapshot!(map, @r###" | ||
500 | ⋮crate | ||
501 | ⋮Bar: t v | ||
502 | ⋮foo: v | ||
503 | "###); | ||
504 | } | ||
505 | |||
506 | #[test] | ||
507 | fn cfg_not_test() { | ||
508 | let map = def_map_with_crate_graph( | ||
509 | r#" | ||
510 | //- /main.rs | ||
511 | use {Foo, Bar, Baz}; | ||
512 | //- /lib.rs | ||
513 | #[prelude_import] | ||
514 | pub use self::prelude::*; | ||
515 | mod prelude { | ||
516 | #[cfg(test)] | ||
517 | pub struct Foo; | ||
518 | #[cfg(not(test))] | ||
519 | pub struct Bar; | ||
520 | #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))] | ||
521 | pub struct Baz; | ||
522 | } | ||
523 | "#, | ||
524 | crate_graph! { | ||
525 | "main": ("/main.rs", ["std"]), | ||
526 | "std": ("/lib.rs", []), | ||
527 | }, | ||
528 | ); | ||
529 | |||
530 | assert_snapshot!(map, @r###" | ||
531 | ⋮crate | ||
532 | ⋮Bar: t v | ||
533 | ⋮Baz: _ | ||
534 | ⋮Foo: _ | ||
535 | "###); | ||
536 | } | ||
537 | |||
538 | #[test] | ||
539 | fn cfg_test() { | ||
540 | let map = def_map_with_crate_graph( | ||
541 | r#" | ||
542 | //- /main.rs | ||
543 | use {Foo, Bar, Baz}; | ||
544 | //- /lib.rs | ||
545 | #[prelude_import] | ||
546 | pub use self::prelude::*; | ||
547 | mod prelude { | ||
548 | #[cfg(test)] | ||
549 | pub struct Foo; | ||
550 | #[cfg(not(test))] | ||
551 | pub struct Bar; | ||
552 | #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))] | ||
553 | pub struct Baz; | ||
554 | } | ||
555 | "#, | ||
556 | crate_graph! { | ||
557 | "main": ("/main.rs", ["std"]), | ||
558 | "std": ("/lib.rs", [], cfg = { | ||
559 | "test", | ||
560 | "feature" = "foo", | ||
561 | "feature" = "bar", | ||
562 | "opt" = "42", | ||
563 | }), | ||
564 | }, | ||
565 | ); | ||
566 | |||
567 | assert_snapshot!(map, @r###" | ||
568 | ⋮crate | ||
569 | ⋮Bar: _ | ||
570 | ⋮Baz: t v | ||
571 | ⋮Foo: t v | ||
572 | "###); | ||
573 | } | ||
diff --git a/crates/ra_hir/src/nameres/tests/globs.rs b/crates/ra_hir/src/nameres/tests/globs.rs deleted file mode 100644 index b3e4d8d94..000000000 --- a/crates/ra_hir/src/nameres/tests/globs.rs +++ /dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | use super::*; | ||
2 | |||
3 | #[test] | ||
4 | fn glob_1() { | ||
5 | let map = def_map( | ||
6 | " | ||
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 | ); | ||
20 | assert_snapshot!(map, @r###" | ||
21 | ⋮crate | ||
22 | ⋮Baz: t v | ||
23 | ⋮Foo: t v | ||
24 | ⋮bar: t | ||
25 | ⋮foo: t | ||
26 | ⋮ | ||
27 | ⋮crate::foo | ||
28 | ⋮Baz: t v | ||
29 | ⋮Foo: t v | ||
30 | ⋮bar: t | ||
31 | ⋮ | ||
32 | ⋮crate::foo::bar | ||
33 | ⋮Baz: t v | ||
34 | "### | ||
35 | ); | ||
36 | } | ||
37 | |||
38 | #[test] | ||
39 | fn glob_2() { | ||
40 | let map = def_map( | ||
41 | " | ||
42 | //- /lib.rs | ||
43 | mod foo; | ||
44 | use foo::*; | ||
45 | |||
46 | //- /foo/mod.rs | ||
47 | pub mod bar; | ||
48 | pub use self::bar::*; | ||
49 | pub struct Foo; | ||
50 | |||
51 | //- /foo/bar.rs | ||
52 | pub struct Baz; | ||
53 | pub use super::*; | ||
54 | ", | ||
55 | ); | ||
56 | assert_snapshot!(map, @r###" | ||
57 | ⋮crate | ||
58 | ⋮Baz: t v | ||
59 | ⋮Foo: t v | ||
60 | ⋮bar: t | ||
61 | ⋮foo: t | ||
62 | ⋮ | ||
63 | ⋮crate::foo | ||
64 | ⋮Baz: t v | ||
65 | ⋮Foo: t v | ||
66 | ⋮bar: t | ||
67 | ⋮ | ||
68 | ⋮crate::foo::bar | ||
69 | ⋮Baz: t v | ||
70 | ⋮Foo: t v | ||
71 | ⋮bar: t | ||
72 | "### | ||
73 | ); | ||
74 | } | ||
75 | |||
76 | #[test] | ||
77 | fn glob_across_crates() { | ||
78 | // covers!(glob_across_crates); | ||
79 | let map = def_map_with_crate_graph( | ||
80 | " | ||
81 | //- /main.rs | ||
82 | use test_crate::*; | ||
83 | |||
84 | //- /lib.rs | ||
85 | pub struct Baz; | ||
86 | ", | ||
87 | crate_graph! { | ||
88 | "main": ("/main.rs", ["test_crate"]), | ||
89 | "test_crate": ("/lib.rs", []), | ||
90 | }, | ||
91 | ); | ||
92 | assert_snapshot!(map, @r###" | ||
93 | ⋮crate | ||
94 | ⋮Baz: t v | ||
95 | "### | ||
96 | ); | ||
97 | } | ||
98 | |||
99 | #[test] | ||
100 | fn glob_enum() { | ||
101 | // covers!(glob_enum); | ||
102 | let map = def_map( | ||
103 | " | ||
104 | //- /lib.rs | ||
105 | enum Foo { | ||
106 | Bar, Baz | ||
107 | } | ||
108 | use self::Foo::*; | ||
109 | ", | ||
110 | ); | ||
111 | assert_snapshot!(map, @r###" | ||
112 | ⋮crate | ||
113 | ⋮Bar: t v | ||
114 | ⋮Baz: t v | ||
115 | ⋮Foo: t | ||
116 | "### | ||
117 | ); | ||
118 | } | ||
diff --git a/crates/ra_hir/src/nameres/tests/incremental.rs b/crates/ra_hir/src/nameres/tests/incremental.rs deleted file mode 100644 index 723ece7b0..000000000 --- a/crates/ra_hir/src/nameres/tests/incremental.rs +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
3 | use ra_db::{SourceDatabase, SourceDatabaseExt}; | ||
4 | |||
5 | use super::*; | ||
6 | |||
7 | fn check_def_map_is_not_recomputed(initial: &str, file_change: &str) { | ||
8 | let (mut db, pos) = MockDatabase::with_position(initial); | ||
9 | let krate = db.crate_graph().iter().next().unwrap(); | ||
10 | { | ||
11 | let events = db.log_executed(|| { | ||
12 | db.crate_def_map(krate); | ||
13 | }); | ||
14 | assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) | ||
15 | } | ||
16 | db.set_file_text(pos.file_id, Arc::new(file_change.to_string())); | ||
17 | |||
18 | { | ||
19 | let events = db.log_executed(|| { | ||
20 | db.crate_def_map(krate); | ||
21 | }); | ||
22 | assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) | ||
23 | } | ||
24 | } | ||
25 | |||
26 | #[test] | ||
27 | fn typing_inside_a_function_should_not_invalidate_def_map() { | ||
28 | check_def_map_is_not_recomputed( | ||
29 | " | ||
30 | //- /lib.rs | ||
31 | mod foo;<|> | ||
32 | |||
33 | use crate::foo::bar::Baz; | ||
34 | |||
35 | fn foo() -> i32 { | ||
36 | 1 + 1 | ||
37 | } | ||
38 | //- /foo/mod.rs | ||
39 | pub mod bar; | ||
40 | |||
41 | //- /foo/bar.rs | ||
42 | pub struct Baz; | ||
43 | ", | ||
44 | " | ||
45 | mod foo; | ||
46 | |||
47 | use crate::foo::bar::Baz; | ||
48 | |||
49 | fn foo() -> i32 { 92 } | ||
50 | ", | ||
51 | ); | ||
52 | } | ||
53 | |||
54 | #[test] | ||
55 | fn adding_inner_items_should_not_invalidate_def_map() { | ||
56 | check_def_map_is_not_recomputed( | ||
57 | " | ||
58 | //- /lib.rs | ||
59 | struct S { a: i32} | ||
60 | enum E { A } | ||
61 | trait T { | ||
62 | fn a() {} | ||
63 | } | ||
64 | mod foo;<|> | ||
65 | impl S { | ||
66 | fn a() {} | ||
67 | } | ||
68 | use crate::foo::bar::Baz; | ||
69 | //- /foo/mod.rs | ||
70 | pub mod bar; | ||
71 | |||
72 | //- /foo/bar.rs | ||
73 | pub struct Baz; | ||
74 | ", | ||
75 | " | ||
76 | struct S { a: i32, b: () } | ||
77 | enum E { A, B } | ||
78 | trait T { | ||
79 | fn a() {} | ||
80 | fn b() {} | ||
81 | } | ||
82 | mod foo;<|> | ||
83 | impl S { | ||
84 | fn a() {} | ||
85 | fn b() {} | ||
86 | } | ||
87 | use crate::foo::bar::Baz; | ||
88 | ", | ||
89 | ); | ||
90 | } | ||
91 | |||
92 | #[test] | ||
93 | fn typing_inside_a_macro_should_not_invalidate_def_map() { | ||
94 | let (mut db, pos) = MockDatabase::with_position( | ||
95 | " | ||
96 | //- /lib.rs | ||
97 | macro_rules! m { | ||
98 | ($ident:ident) => { | ||
99 | fn f() { | ||
100 | $ident + $ident; | ||
101 | }; | ||
102 | } | ||
103 | } | ||
104 | mod foo; | ||
105 | |||
106 | //- /foo/mod.rs | ||
107 | pub mod bar; | ||
108 | |||
109 | //- /foo/bar.rs | ||
110 | <|> | ||
111 | m!(X); | ||
112 | ", | ||
113 | ); | ||
114 | { | ||
115 | let events = db.log_executed(|| { | ||
116 | let src = crate::Source { | ||
117 | file_id: pos.file_id.into(), | ||
118 | ast: crate::ModuleSource::new(&db, Some(pos.file_id), None), | ||
119 | }; | ||
120 | let module = crate::Module::from_definition(&db, src).unwrap(); | ||
121 | let decls = module.declarations(&db); | ||
122 | assert_eq!(decls.len(), 18); | ||
123 | }); | ||
124 | assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) | ||
125 | } | ||
126 | db.set_file_text(pos.file_id, Arc::new("m!(Y);".to_string())); | ||
127 | |||
128 | { | ||
129 | let events = db.log_executed(|| { | ||
130 | let src = crate::Source { | ||
131 | file_id: pos.file_id.into(), | ||
132 | ast: crate::ModuleSource::new(&db, Some(pos.file_id), None), | ||
133 | }; | ||
134 | let module = crate::Module::from_definition(&db, src).unwrap(); | ||
135 | let decls = module.declarations(&db); | ||
136 | assert_eq!(decls.len(), 18); | ||
137 | }); | ||
138 | assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) | ||
139 | } | ||
140 | } | ||
diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs deleted file mode 100644 index 78bb0eb0d..000000000 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ /dev/null | |||
@@ -1,635 +0,0 @@ | |||
1 | use super::*; | ||
2 | |||
3 | #[test] | ||
4 | fn macro_rules_are_globally_visible() { | ||
5 | let map = def_map( | ||
6 | " | ||
7 | //- /lib.rs | ||
8 | macro_rules! structs { | ||
9 | ($($i:ident),*) => { | ||
10 | $(struct $i { field: u32 } )* | ||
11 | } | ||
12 | } | ||
13 | structs!(Foo); | ||
14 | mod nested; | ||
15 | |||
16 | //- /nested.rs | ||
17 | structs!(Bar, Baz); | ||
18 | ", | ||
19 | ); | ||
20 | assert_snapshot!(map, @r###" | ||
21 | ⋮crate | ||
22 | ⋮Foo: t v | ||
23 | ⋮nested: t | ||
24 | ⋮ | ||
25 | ⋮crate::nested | ||
26 | ⋮Bar: t v | ||
27 | ⋮Baz: t v | ||
28 | "###); | ||
29 | } | ||
30 | |||
31 | #[test] | ||
32 | fn macro_rules_can_define_modules() { | ||
33 | let map = def_map( | ||
34 | " | ||
35 | //- /lib.rs | ||
36 | macro_rules! m { | ||
37 | ($name:ident) => { mod $name; } | ||
38 | } | ||
39 | m!(n1); | ||
40 | |||
41 | mod m { | ||
42 | m!(n3) | ||
43 | } | ||
44 | |||
45 | //- /n1.rs | ||
46 | m!(n2) | ||
47 | //- /n1/n2.rs | ||
48 | struct X; | ||
49 | //- /m/n3.rs | ||
50 | struct Y; | ||
51 | ", | ||
52 | ); | ||
53 | assert_snapshot!(map, @r###" | ||
54 | crate | ||
55 | m: t | ||
56 | n1: t | ||
57 | |||
58 | crate::m | ||
59 | n3: t | ||
60 | |||
61 | crate::m::n3 | ||
62 | Y: t v | ||
63 | |||
64 | crate::n1 | ||
65 | n2: t | ||
66 | |||
67 | crate::n1::n2 | ||
68 | X: t v | ||
69 | "###); | ||
70 | } | ||
71 | |||
72 | #[test] | ||
73 | fn macro_rules_from_other_crates_are_visible() { | ||
74 | let map = def_map_with_crate_graph( | ||
75 | " | ||
76 | //- /main.rs | ||
77 | foo::structs!(Foo, Bar) | ||
78 | mod bar; | ||
79 | |||
80 | //- /bar.rs | ||
81 | use crate::*; | ||
82 | |||
83 | //- /lib.rs | ||
84 | #[macro_export] | ||
85 | macro_rules! structs { | ||
86 | ($($i:ident),*) => { | ||
87 | $(struct $i { field: u32 } )* | ||
88 | } | ||
89 | } | ||
90 | ", | ||
91 | crate_graph! { | ||
92 | "main": ("/main.rs", ["foo"]), | ||
93 | "foo": ("/lib.rs", []), | ||
94 | }, | ||
95 | ); | ||
96 | assert_snapshot!(map, @r###" | ||
97 | ⋮crate | ||
98 | ⋮Bar: t v | ||
99 | ⋮Foo: t v | ||
100 | ⋮bar: t | ||
101 | ⋮ | ||
102 | ⋮crate::bar | ||
103 | ⋮Bar: t v | ||
104 | ⋮Foo: t v | ||
105 | ⋮bar: t | ||
106 | "###); | ||
107 | } | ||
108 | |||
109 | #[test] | ||
110 | fn macro_rules_export_with_local_inner_macros_are_visible() { | ||
111 | let map = def_map_with_crate_graph( | ||
112 | " | ||
113 | //- /main.rs | ||
114 | foo::structs!(Foo, Bar) | ||
115 | mod bar; | ||
116 | |||
117 | //- /bar.rs | ||
118 | use crate::*; | ||
119 | |||
120 | //- /lib.rs | ||
121 | #[macro_export(local_inner_macros)] | ||
122 | macro_rules! structs { | ||
123 | ($($i:ident),*) => { | ||
124 | $(struct $i { field: u32 } )* | ||
125 | } | ||
126 | } | ||
127 | ", | ||
128 | crate_graph! { | ||
129 | "main": ("/main.rs", ["foo"]), | ||
130 | "foo": ("/lib.rs", []), | ||
131 | }, | ||
132 | ); | ||
133 | assert_snapshot!(map, @r###" | ||
134 | ⋮crate | ||
135 | ⋮Bar: t v | ||
136 | ⋮Foo: t v | ||
137 | ⋮bar: t | ||
138 | ⋮ | ||
139 | ⋮crate::bar | ||
140 | ⋮Bar: t v | ||
141 | ⋮Foo: t v | ||
142 | ⋮bar: t | ||
143 | "###); | ||
144 | } | ||
145 | |||
146 | #[test] | ||
147 | fn unexpanded_macro_should_expand_by_fixedpoint_loop() { | ||
148 | let map = def_map_with_crate_graph( | ||
149 | " | ||
150 | //- /main.rs | ||
151 | macro_rules! baz { | ||
152 | () => { | ||
153 | use foo::bar; | ||
154 | } | ||
155 | } | ||
156 | |||
157 | foo!(); | ||
158 | bar!(); | ||
159 | baz!(); | ||
160 | |||
161 | //- /lib.rs | ||
162 | #[macro_export] | ||
163 | macro_rules! foo { | ||
164 | () => { | ||
165 | struct Foo { field: u32 } | ||
166 | } | ||
167 | } | ||
168 | #[macro_export] | ||
169 | macro_rules! bar { | ||
170 | () => { | ||
171 | use foo::foo; | ||
172 | } | ||
173 | } | ||
174 | ", | ||
175 | crate_graph! { | ||
176 | "main": ("/main.rs", ["foo"]), | ||
177 | "foo": ("/lib.rs", []), | ||
178 | }, | ||
179 | ); | ||
180 | assert_snapshot!(map, @r###" | ||
181 | ⋮crate | ||
182 | ⋮Foo: t v | ||
183 | ⋮bar: m | ||
184 | ⋮foo: m | ||
185 | "###); | ||
186 | } | ||
187 | |||
188 | #[test] | ||
189 | fn macro_rules_from_other_crates_are_visible_with_macro_use() { | ||
190 | // covers!(macro_rules_from_other_crates_are_visible_with_macro_use); | ||
191 | let map = def_map_with_crate_graph( | ||
192 | " | ||
193 | //- /main.rs | ||
194 | structs!(Foo); | ||
195 | structs_priv!(Bar); | ||
196 | structs_not_exported!(MacroNotResolved1); | ||
197 | crate::structs!(MacroNotResolved2); | ||
198 | |||
199 | mod bar; | ||
200 | |||
201 | #[macro_use] | ||
202 | extern crate foo; | ||
203 | |||
204 | //- /bar.rs | ||
205 | structs!(Baz); | ||
206 | crate::structs!(MacroNotResolved3); | ||
207 | |||
208 | //- /lib.rs | ||
209 | #[macro_export] | ||
210 | macro_rules! structs { | ||
211 | ($i:ident) => { struct $i; } | ||
212 | } | ||
213 | |||
214 | macro_rules! structs_not_exported { | ||
215 | ($i:ident) => { struct $i; } | ||
216 | } | ||
217 | |||
218 | mod priv_mod { | ||
219 | #[macro_export] | ||
220 | macro_rules! structs_priv { | ||
221 | ($i:ident) => { struct $i; } | ||
222 | } | ||
223 | } | ||
224 | ", | ||
225 | crate_graph! { | ||
226 | "main": ("/main.rs", ["foo"]), | ||
227 | "foo": ("/lib.rs", []), | ||
228 | }, | ||
229 | ); | ||
230 | assert_snapshot!(map, @r###" | ||
231 | ⋮crate | ||
232 | ⋮Bar: t v | ||
233 | ⋮Foo: t v | ||
234 | ⋮bar: t | ||
235 | ⋮foo: t | ||
236 | ⋮ | ||
237 | ⋮crate::bar | ||
238 | ⋮Baz: t v | ||
239 | "###); | ||
240 | } | ||
241 | |||
242 | #[test] | ||
243 | fn prelude_is_macro_use() { | ||
244 | // covers!(prelude_is_macro_use); | ||
245 | let map = def_map_with_crate_graph( | ||
246 | " | ||
247 | //- /main.rs | ||
248 | structs!(Foo); | ||
249 | structs_priv!(Bar); | ||
250 | structs_outside!(Out); | ||
251 | crate::structs!(MacroNotResolved2); | ||
252 | |||
253 | mod bar; | ||
254 | |||
255 | //- /bar.rs | ||
256 | structs!(Baz); | ||
257 | crate::structs!(MacroNotResolved3); | ||
258 | |||
259 | //- /lib.rs | ||
260 | #[prelude_import] | ||
261 | use self::prelude::*; | ||
262 | |||
263 | mod prelude { | ||
264 | #[macro_export] | ||
265 | macro_rules! structs { | ||
266 | ($i:ident) => { struct $i; } | ||
267 | } | ||
268 | |||
269 | mod priv_mod { | ||
270 | #[macro_export] | ||
271 | macro_rules! structs_priv { | ||
272 | ($i:ident) => { struct $i; } | ||
273 | } | ||
274 | } | ||
275 | } | ||
276 | |||
277 | #[macro_export] | ||
278 | macro_rules! structs_outside { | ||
279 | ($i:ident) => { struct $i; } | ||
280 | } | ||
281 | ", | ||
282 | crate_graph! { | ||
283 | "main": ("/main.rs", ["foo"]), | ||
284 | "foo": ("/lib.rs", []), | ||
285 | }, | ||
286 | ); | ||
287 | assert_snapshot!(map, @r###" | ||
288 | ⋮crate | ||
289 | ⋮Bar: t v | ||
290 | ⋮Foo: t v | ||
291 | ⋮Out: t v | ||
292 | ⋮bar: t | ||
293 | ⋮ | ||
294 | ⋮crate::bar | ||
295 | ⋮Baz: t v | ||
296 | "###); | ||
297 | } | ||
298 | |||
299 | #[test] | ||
300 | fn prelude_cycle() { | ||
301 | let map = def_map( | ||
302 | " | ||
303 | //- /lib.rs | ||
304 | #[prelude_import] | ||
305 | use self::prelude::*; | ||
306 | |||
307 | declare_mod!(); | ||
308 | |||
309 | mod prelude { | ||
310 | macro_rules! declare_mod { | ||
311 | () => (mod foo {}) | ||
312 | } | ||
313 | } | ||
314 | ", | ||
315 | ); | ||
316 | assert_snapshot!(map, @r###" | ||
317 | ⋮crate | ||
318 | ⋮prelude: t | ||
319 | ⋮ | ||
320 | ⋮crate::prelude | ||
321 | "###); | ||
322 | } | ||
323 | |||
324 | #[test] | ||
325 | fn plain_macros_are_legacy_textual_scoped() { | ||
326 | let map = def_map( | ||
327 | r#" | ||
328 | //- /main.rs | ||
329 | mod m1; | ||
330 | bar!(NotFoundNotMacroUse); | ||
331 | |||
332 | mod m2 { | ||
333 | foo!(NotFoundBeforeInside2); | ||
334 | } | ||
335 | |||
336 | macro_rules! foo { | ||
337 | ($x:ident) => { struct $x; } | ||
338 | } | ||
339 | foo!(Ok); | ||
340 | |||
341 | mod m3; | ||
342 | foo!(OkShadowStop); | ||
343 | bar!(NotFoundMacroUseStop); | ||
344 | |||
345 | #[macro_use] | ||
346 | mod m5 { | ||
347 | #[macro_use] | ||
348 | mod m6 { | ||
349 | macro_rules! foo { | ||
350 | ($x:ident) => { fn $x() {} } | ||
351 | } | ||
352 | } | ||
353 | } | ||
354 | foo!(ok_double_macro_use_shadow); | ||
355 | |||
356 | baz!(NotFoundBefore); | ||
357 | #[macro_use] | ||
358 | mod m7 { | ||
359 | macro_rules! baz { | ||
360 | ($x:ident) => { struct $x; } | ||
361 | } | ||
362 | } | ||
363 | baz!(OkAfter); | ||
364 | |||
365 | //- /m1.rs | ||
366 | foo!(NotFoundBeforeInside1); | ||
367 | macro_rules! bar { | ||
368 | ($x:ident) => { struct $x; } | ||
369 | } | ||
370 | |||
371 | //- /m3/mod.rs | ||
372 | foo!(OkAfterInside); | ||
373 | macro_rules! foo { | ||
374 | ($x:ident) => { fn $x() {} } | ||
375 | } | ||
376 | foo!(ok_shadow); | ||
377 | |||
378 | #[macro_use] | ||
379 | mod m4; | ||
380 | bar!(OkMacroUse); | ||
381 | |||
382 | //- /m3/m4.rs | ||
383 | foo!(ok_shadow_deep); | ||
384 | macro_rules! bar { | ||
385 | ($x:ident) => { struct $x; } | ||
386 | } | ||
387 | "#, | ||
388 | ); | ||
389 | assert_snapshot!(map, @r###" | ||
390 | ⋮crate | ||
391 | ⋮Ok: t v | ||
392 | ⋮OkAfter: t v | ||
393 | ⋮OkShadowStop: t v | ||
394 | ⋮m1: t | ||
395 | ⋮m2: t | ||
396 | ⋮m3: t | ||
397 | ⋮m5: t | ||
398 | ⋮m7: t | ||
399 | ⋮ok_double_macro_use_shadow: v | ||
400 | ⋮ | ||
401 | ⋮crate::m7 | ||
402 | ⋮ | ||
403 | ⋮crate::m1 | ||
404 | ⋮ | ||
405 | ⋮crate::m5 | ||
406 | ⋮m6: t | ||
407 | ⋮ | ||
408 | ⋮crate::m5::m6 | ||
409 | ⋮ | ||
410 | ⋮crate::m2 | ||
411 | ⋮ | ||
412 | ⋮crate::m3 | ||
413 | ⋮OkAfterInside: t v | ||
414 | ⋮OkMacroUse: t v | ||
415 | ⋮m4: t | ||
416 | ⋮ok_shadow: v | ||
417 | ⋮ | ||
418 | ⋮crate::m3::m4 | ||
419 | ⋮ok_shadow_deep: v | ||
420 | "###); | ||
421 | } | ||
422 | |||
423 | #[test] | ||
424 | fn type_value_macro_live_in_different_scopes() { | ||
425 | let map = def_map( | ||
426 | " | ||
427 | //- /main.rs | ||
428 | #[macro_export] | ||
429 | macro_rules! foo { | ||
430 | ($x:ident) => { type $x = (); } | ||
431 | } | ||
432 | |||
433 | foo!(foo); | ||
434 | use foo as bar; | ||
435 | |||
436 | use self::foo as baz; | ||
437 | fn baz() {} | ||
438 | ", | ||
439 | ); | ||
440 | assert_snapshot!(map, @r###" | ||
441 | ⋮crate | ||
442 | ⋮bar: t m | ||
443 | ⋮baz: t v m | ||
444 | ⋮foo: t m | ||
445 | "###); | ||
446 | } | ||
447 | |||
448 | #[test] | ||
449 | fn macro_use_can_be_aliased() { | ||
450 | let map = def_map_with_crate_graph( | ||
451 | " | ||
452 | //- /main.rs | ||
453 | #[macro_use] | ||
454 | extern crate foo; | ||
455 | |||
456 | foo!(Direct); | ||
457 | bar!(Alias); | ||
458 | |||
459 | //- /lib.rs | ||
460 | use crate::foo as bar; | ||
461 | |||
462 | mod m { | ||
463 | #[macro_export] | ||
464 | macro_rules! foo { | ||
465 | ($x:ident) => { struct $x; } | ||
466 | } | ||
467 | } | ||
468 | ", | ||
469 | crate_graph! { | ||
470 | "main": ("/main.rs", ["foo"]), | ||
471 | "foo": ("/lib.rs", []), | ||
472 | }, | ||
473 | ); | ||
474 | assert_snapshot!(map, @r###" | ||
475 | ⋮crate | ||
476 | ⋮Alias: t v | ||
477 | ⋮Direct: t v | ||
478 | ⋮foo: t | ||
479 | "###); | ||
480 | } | ||
481 | |||
482 | #[test] | ||
483 | fn path_qualified_macros() { | ||
484 | let map = def_map( | ||
485 | " | ||
486 | //- /main.rs | ||
487 | macro_rules! foo { | ||
488 | ($x:ident) => { struct $x; } | ||
489 | } | ||
490 | |||
491 | crate::foo!(NotResolved); | ||
492 | |||
493 | crate::bar!(OkCrate); | ||
494 | bar!(OkPlain); | ||
495 | alias1!(NotHere); | ||
496 | m::alias1!(OkAliasPlain); | ||
497 | m::alias2!(OkAliasSuper); | ||
498 | m::alias3!(OkAliasCrate); | ||
499 | not_found!(NotFound); | ||
500 | |||
501 | mod m { | ||
502 | #[macro_export] | ||
503 | macro_rules! bar { | ||
504 | ($x:ident) => { struct $x; } | ||
505 | } | ||
506 | |||
507 | pub use bar as alias1; | ||
508 | pub use super::bar as alias2; | ||
509 | pub use crate::bar as alias3; | ||
510 | pub use self::bar as not_found; | ||
511 | } | ||
512 | ", | ||
513 | ); | ||
514 | assert_snapshot!(map, @r###" | ||
515 | ⋮crate | ||
516 | ⋮OkAliasCrate: t v | ||
517 | ⋮OkAliasPlain: t v | ||
518 | ⋮OkAliasSuper: t v | ||
519 | ⋮OkCrate: t v | ||
520 | ⋮OkPlain: t v | ||
521 | ⋮bar: m | ||
522 | ⋮m: t | ||
523 | ⋮ | ||
524 | ⋮crate::m | ||
525 | ⋮alias1: m | ||
526 | ⋮alias2: m | ||
527 | ⋮alias3: m | ||
528 | ⋮not_found: _ | ||
529 | "###); | ||
530 | } | ||
531 | |||
532 | #[test] | ||
533 | fn macro_dollar_crate_is_correct_in_item() { | ||
534 | // covers!(macro_dollar_crate_self); | ||
535 | // covers!(macro_dollar_crate_other); | ||
536 | let map = def_map_with_crate_graph( | ||
537 | " | ||
538 | //- /main.rs | ||
539 | #[macro_use] | ||
540 | extern crate foo; | ||
541 | |||
542 | #[macro_use] | ||
543 | mod m { | ||
544 | macro_rules! current { | ||
545 | () => { | ||
546 | use $crate::Foo as FooSelf; | ||
547 | } | ||
548 | } | ||
549 | } | ||
550 | |||
551 | struct Foo; | ||
552 | |||
553 | current!(); | ||
554 | not_current1!(); | ||
555 | foo::not_current2!(); | ||
556 | |||
557 | //- /lib.rs | ||
558 | mod m { | ||
559 | #[macro_export] | ||
560 | macro_rules! not_current1 { | ||
561 | () => { | ||
562 | use $crate::Bar; | ||
563 | } | ||
564 | } | ||
565 | } | ||
566 | |||
567 | #[macro_export] | ||
568 | macro_rules! not_current2 { | ||
569 | () => { | ||
570 | use $crate::Baz; | ||
571 | } | ||
572 | } | ||
573 | |||
574 | struct Bar; | ||
575 | struct Baz; | ||
576 | ", | ||
577 | crate_graph! { | ||
578 | "main": ("/main.rs", ["foo"]), | ||
579 | "foo": ("/lib.rs", []), | ||
580 | }, | ||
581 | ); | ||
582 | assert_snapshot!(map, @r###" | ||
583 | ⋮crate | ||
584 | ⋮Bar: t v | ||
585 | ⋮Baz: t v | ||
586 | ⋮Foo: t v | ||
587 | ⋮FooSelf: t v | ||
588 | ⋮foo: t | ||
589 | ⋮m: t | ||
590 | ⋮ | ||
591 | ⋮crate::m | ||
592 | "###); | ||
593 | } | ||
594 | |||
595 | #[test] | ||
596 | fn macro_dollar_crate_is_correct_in_indirect_deps() { | ||
597 | // covers!(macro_dollar_crate_other); | ||
598 | // From std | ||
599 | let map = def_map_with_crate_graph( | ||
600 | r#" | ||
601 | //- /main.rs | ||
602 | foo!(); | ||
603 | |||
604 | //- /std.rs | ||
605 | #[prelude_import] | ||
606 | use self::prelude::*; | ||
607 | |||
608 | pub use core::foo; | ||
609 | |||
610 | mod prelude {} | ||
611 | |||
612 | #[macro_use] | ||
613 | mod std_macros; | ||
614 | |||
615 | //- /core.rs | ||
616 | #[macro_export] | ||
617 | macro_rules! foo { | ||
618 | () => { | ||
619 | use $crate::bar; | ||
620 | } | ||
621 | } | ||
622 | |||
623 | pub struct bar; | ||
624 | "#, | ||
625 | crate_graph! { | ||
626 | "main": ("/main.rs", ["std"]), | ||
627 | "std": ("/std.rs", ["core"]), | ||
628 | "core": ("/core.rs", []), | ||
629 | }, | ||
630 | ); | ||
631 | assert_snapshot!(map, @r###" | ||
632 | ⋮crate | ||
633 | ⋮bar: t v | ||
634 | "###); | ||
635 | } | ||
diff --git a/crates/ra_hir/src/nameres/tests/mod_resolution.rs b/crates/ra_hir/src/nameres/tests/mod_resolution.rs deleted file mode 100644 index abfe8b1c3..000000000 --- a/crates/ra_hir/src/nameres/tests/mod_resolution.rs +++ /dev/null | |||
@@ -1,759 +0,0 @@ | |||
1 | use super::*; | ||
2 | |||
3 | #[test] | ||
4 | fn name_res_works_for_broken_modules() { | ||
5 | // covers!(name_res_works_for_broken_modules); | ||
6 | let map = def_map( | ||
7 | " | ||
8 | //- /lib.rs | ||
9 | mod foo // no `;`, no body | ||
10 | |||
11 | use self::foo::Baz; | ||
12 | |||
13 | //- /foo/mod.rs | ||
14 | pub mod bar; | ||
15 | |||
16 | pub use self::bar::Baz; | ||
17 | |||
18 | //- /foo/bar.rs | ||
19 | pub struct Baz; | ||
20 | ", | ||
21 | ); | ||
22 | assert_snapshot!(map, @r###" | ||
23 | ⋮crate | ||
24 | ⋮Baz: _ | ||
25 | "###); | ||
26 | } | ||
27 | |||
28 | #[test] | ||
29 | fn nested_module_resolution() { | ||
30 | let map = def_map( | ||
31 | " | ||
32 | //- /lib.rs | ||
33 | mod n1; | ||
34 | |||
35 | //- /n1.rs | ||
36 | mod n2; | ||
37 | |||
38 | //- /n1/n2.rs | ||
39 | struct X; | ||
40 | ", | ||
41 | ); | ||
42 | |||
43 | assert_snapshot!(map, @r###" | ||
44 | ⋮crate | ||
45 | ⋮n1: t | ||
46 | ⋮ | ||
47 | ⋮crate::n1 | ||
48 | ⋮n2: t | ||
49 | ⋮ | ||
50 | ⋮crate::n1::n2 | ||
51 | ⋮X: t v | ||
52 | "###); | ||
53 | } | ||
54 | |||
55 | #[test] | ||
56 | fn module_resolution_works_for_non_standard_filenames() { | ||
57 | let map = def_map_with_crate_graph( | ||
58 | " | ||
59 | //- /my_library.rs | ||
60 | mod foo; | ||
61 | use self::foo::Bar; | ||
62 | |||
63 | //- /foo/mod.rs | ||
64 | pub struct Bar; | ||
65 | ", | ||
66 | crate_graph! { | ||
67 | "my_library": ("/my_library.rs", []), | ||
68 | }, | ||
69 | ); | ||
70 | |||
71 | assert_snapshot!(map, @r###" | ||
72 | ⋮crate | ||
73 | ⋮Bar: t v | ||
74 | ⋮foo: t | ||
75 | ⋮ | ||
76 | ⋮crate::foo | ||
77 | ⋮Bar: t v | ||
78 | "###); | ||
79 | } | ||
80 | |||
81 | #[test] | ||
82 | fn module_resolution_works_for_raw_modules() { | ||
83 | let map = def_map( | ||
84 | " | ||
85 | //- /lib.rs | ||
86 | mod r#async; | ||
87 | use self::r#async::Bar; | ||
88 | |||
89 | //- /async.rs | ||
90 | pub struct Bar; | ||
91 | ", | ||
92 | ); | ||
93 | |||
94 | assert_snapshot!(map, @r###" | ||
95 | ⋮crate | ||
96 | ⋮Bar: t v | ||
97 | ⋮async: t | ||
98 | ⋮ | ||
99 | ⋮crate::async | ||
100 | ⋮Bar: t v | ||
101 | "###); | ||
102 | } | ||
103 | |||
104 | #[test] | ||
105 | fn module_resolution_decl_path() { | ||
106 | let map = def_map( | ||
107 | r###" | ||
108 | //- /lib.rs | ||
109 | #[path = "bar/baz/foo.rs"] | ||
110 | mod foo; | ||
111 | use self::foo::Bar; | ||
112 | |||
113 | //- /bar/baz/foo.rs | ||
114 | pub struct Bar; | ||
115 | "###, | ||
116 | ); | ||
117 | |||
118 | assert_snapshot!(map, @r###" | ||
119 | ⋮crate | ||
120 | ⋮Bar: t v | ||
121 | ⋮foo: t | ||
122 | ⋮ | ||
123 | ⋮crate::foo | ||
124 | ⋮Bar: t v | ||
125 | "###); | ||
126 | } | ||
127 | |||
128 | #[test] | ||
129 | fn module_resolution_module_with_path_in_mod_rs() { | ||
130 | let map = def_map( | ||
131 | r###" | ||
132 | //- /main.rs | ||
133 | mod foo; | ||
134 | |||
135 | //- /foo/mod.rs | ||
136 | #[path = "baz.rs"] | ||
137 | pub mod bar; | ||
138 | |||
139 | use self::bar::Baz; | ||
140 | |||
141 | //- /foo/baz.rs | ||
142 | pub struct Baz; | ||
143 | "###, | ||
144 | ); | ||
145 | |||
146 | assert_snapshot!(map, @r###" | ||
147 | ⋮crate | ||
148 | ⋮foo: t | ||
149 | ⋮ | ||
150 | ⋮crate::foo | ||
151 | ⋮Baz: t v | ||
152 | ⋮bar: t | ||
153 | ⋮ | ||
154 | ⋮crate::foo::bar | ||
155 | ⋮Baz: t v | ||
156 | "###); | ||
157 | } | ||
158 | |||
159 | #[test] | ||
160 | fn module_resolution_module_with_path_non_crate_root() { | ||
161 | let map = def_map( | ||
162 | r###" | ||
163 | //- /main.rs | ||
164 | mod foo; | ||
165 | |||
166 | //- /foo.rs | ||
167 | #[path = "baz.rs"] | ||
168 | pub mod bar; | ||
169 | |||
170 | use self::bar::Baz; | ||
171 | |||
172 | //- /baz.rs | ||
173 | pub struct Baz; | ||
174 | "###, | ||
175 | ); | ||
176 | |||
177 | assert_snapshot!(map, @r###" | ||
178 | ⋮crate | ||
179 | ⋮foo: t | ||
180 | ⋮ | ||
181 | ⋮crate::foo | ||
182 | ⋮Baz: t v | ||
183 | ⋮bar: t | ||
184 | ⋮ | ||
185 | ⋮crate::foo::bar | ||
186 | ⋮Baz: t v | ||
187 | "###); | ||
188 | } | ||
189 | |||
190 | #[test] | ||
191 | fn module_resolution_module_decl_path_super() { | ||
192 | let map = def_map( | ||
193 | r###" | ||
194 | //- /main.rs | ||
195 | #[path = "bar/baz/module.rs"] | ||
196 | mod foo; | ||
197 | pub struct Baz; | ||
198 | |||
199 | //- /bar/baz/module.rs | ||
200 | use super::Baz; | ||
201 | "###, | ||
202 | ); | ||
203 | |||
204 | assert_snapshot!(map, @r###" | ||
205 | ⋮crate | ||
206 | ⋮Baz: t v | ||
207 | ⋮foo: t | ||
208 | ⋮ | ||
209 | ⋮crate::foo | ||
210 | ⋮Baz: t v | ||
211 | "###); | ||
212 | } | ||
213 | |||
214 | #[test] | ||
215 | fn module_resolution_explicit_path_mod_rs() { | ||
216 | let map = def_map( | ||
217 | r###" | ||
218 | //- /main.rs | ||
219 | #[path = "module/mod.rs"] | ||
220 | mod foo; | ||
221 | |||
222 | //- /module/mod.rs | ||
223 | pub struct Baz; | ||
224 | "###, | ||
225 | ); | ||
226 | |||
227 | assert_snapshot!(map, @r###" | ||
228 | ⋮crate | ||
229 | ⋮foo: t | ||
230 | ⋮ | ||
231 | ⋮crate::foo | ||
232 | ⋮Baz: t v | ||
233 | "###); | ||
234 | } | ||
235 | |||
236 | #[test] | ||
237 | fn module_resolution_relative_path() { | ||
238 | let map = def_map( | ||
239 | r###" | ||
240 | //- /main.rs | ||
241 | mod foo; | ||
242 | |||
243 | //- /foo.rs | ||
244 | #[path = "./sub.rs"] | ||
245 | pub mod foo_bar; | ||
246 | |||
247 | //- /sub.rs | ||
248 | pub struct Baz; | ||
249 | "###, | ||
250 | ); | ||
251 | |||
252 | assert_snapshot!(map, @r###" | ||
253 | ⋮crate | ||
254 | ⋮foo: t | ||
255 | ⋮ | ||
256 | ⋮crate::foo | ||
257 | ⋮foo_bar: t | ||
258 | ⋮ | ||
259 | ⋮crate::foo::foo_bar | ||
260 | ⋮Baz: t v | ||
261 | "###); | ||
262 | } | ||
263 | |||
264 | #[test] | ||
265 | fn module_resolution_relative_path_2() { | ||
266 | let map = def_map( | ||
267 | r###" | ||
268 | //- /main.rs | ||
269 | mod foo; | ||
270 | |||
271 | //- /foo/mod.rs | ||
272 | #[path="../sub.rs"] | ||
273 | pub mod foo_bar; | ||
274 | |||
275 | //- /sub.rs | ||
276 | pub struct Baz; | ||
277 | "###, | ||
278 | ); | ||
279 | |||
280 | assert_snapshot!(map, @r###" | ||
281 | ⋮crate | ||
282 | ⋮foo: t | ||
283 | ⋮ | ||
284 | ⋮crate::foo | ||
285 | ⋮foo_bar: t | ||
286 | ⋮ | ||
287 | ⋮crate::foo::foo_bar | ||
288 | ⋮Baz: t v | ||
289 | "###); | ||
290 | } | ||
291 | |||
292 | #[test] | ||
293 | fn module_resolution_explicit_path_mod_rs_2() { | ||
294 | let map = def_map( | ||
295 | r###" | ||
296 | //- /main.rs | ||
297 | #[path = "module/bar/mod.rs"] | ||
298 | mod foo; | ||
299 | |||
300 | //- /module/bar/mod.rs | ||
301 | pub struct Baz; | ||
302 | "###, | ||
303 | ); | ||
304 | |||
305 | assert_snapshot!(map, @r###" | ||
306 | ⋮crate | ||
307 | ⋮foo: t | ||
308 | ⋮ | ||
309 | ⋮crate::foo | ||
310 | ⋮Baz: t v | ||
311 | "###); | ||
312 | } | ||
313 | |||
314 | #[test] | ||
315 | fn module_resolution_explicit_path_mod_rs_with_win_separator() { | ||
316 | let map = def_map( | ||
317 | r###" | ||
318 | //- /main.rs | ||
319 | #[path = "module\bar\mod.rs"] | ||
320 | mod foo; | ||
321 | |||
322 | //- /module/bar/mod.rs | ||
323 | pub struct Baz; | ||
324 | "###, | ||
325 | ); | ||
326 | |||
327 | assert_snapshot!(map, @r###" | ||
328 | ⋮crate | ||
329 | ⋮foo: t | ||
330 | ⋮ | ||
331 | ⋮crate::foo | ||
332 | ⋮Baz: t v | ||
333 | "###); | ||
334 | } | ||
335 | |||
336 | #[test] | ||
337 | fn module_resolution_decl_inside_inline_module_with_path_attribute() { | ||
338 | let map = def_map( | ||
339 | r###" | ||
340 | //- /main.rs | ||
341 | #[path = "models"] | ||
342 | mod foo { | ||
343 | mod bar; | ||
344 | } | ||
345 | |||
346 | //- /models/bar.rs | ||
347 | pub struct Baz; | ||
348 | "###, | ||
349 | ); | ||
350 | |||
351 | assert_snapshot!(map, @r###" | ||
352 | ⋮crate | ||
353 | ⋮foo: t | ||
354 | ⋮ | ||
355 | ⋮crate::foo | ||
356 | ⋮bar: t | ||
357 | ⋮ | ||
358 | ⋮crate::foo::bar | ||
359 | ⋮Baz: t v | ||
360 | "###); | ||
361 | } | ||
362 | |||
363 | #[test] | ||
364 | fn module_resolution_decl_inside_inline_module() { | ||
365 | let map = def_map( | ||
366 | r###" | ||
367 | //- /main.rs | ||
368 | mod foo { | ||
369 | mod bar; | ||
370 | } | ||
371 | |||
372 | //- /foo/bar.rs | ||
373 | pub struct Baz; | ||
374 | "###, | ||
375 | ); | ||
376 | |||
377 | assert_snapshot!(map, @r###" | ||
378 | ⋮crate | ||
379 | ⋮foo: t | ||
380 | ⋮ | ||
381 | ⋮crate::foo | ||
382 | ⋮bar: t | ||
383 | ⋮ | ||
384 | ⋮crate::foo::bar | ||
385 | ⋮Baz: t v | ||
386 | "###); | ||
387 | } | ||
388 | |||
389 | #[test] | ||
390 | fn module_resolution_decl_inside_inline_module_2_with_path_attribute() { | ||
391 | let map = def_map( | ||
392 | r###" | ||
393 | //- /main.rs | ||
394 | #[path = "models/db"] | ||
395 | mod foo { | ||
396 | mod bar; | ||
397 | } | ||
398 | |||
399 | //- /models/db/bar.rs | ||
400 | pub struct Baz; | ||
401 | "###, | ||
402 | ); | ||
403 | |||
404 | assert_snapshot!(map, @r###" | ||
405 | ⋮crate | ||
406 | ⋮foo: t | ||
407 | ⋮ | ||
408 | ⋮crate::foo | ||
409 | ⋮bar: t | ||
410 | ⋮ | ||
411 | ⋮crate::foo::bar | ||
412 | ⋮Baz: t v | ||
413 | "###); | ||
414 | } | ||
415 | |||
416 | #[test] | ||
417 | fn module_resolution_decl_inside_inline_module_3() { | ||
418 | let map = def_map( | ||
419 | r###" | ||
420 | //- /main.rs | ||
421 | #[path = "models/db"] | ||
422 | mod foo { | ||
423 | #[path = "users.rs"] | ||
424 | mod bar; | ||
425 | } | ||
426 | |||
427 | //- /models/db/users.rs | ||
428 | pub struct Baz; | ||
429 | "###, | ||
430 | ); | ||
431 | |||
432 | assert_snapshot!(map, @r###" | ||
433 | ⋮crate | ||
434 | ⋮foo: t | ||
435 | ⋮ | ||
436 | ⋮crate::foo | ||
437 | ⋮bar: t | ||
438 | ⋮ | ||
439 | ⋮crate::foo::bar | ||
440 | ⋮Baz: t v | ||
441 | "###); | ||
442 | } | ||
443 | |||
444 | #[test] | ||
445 | fn module_resolution_decl_inside_inline_module_empty_path() { | ||
446 | let map = def_map( | ||
447 | r###" | ||
448 | //- /main.rs | ||
449 | #[path = ""] | ||
450 | mod foo { | ||
451 | #[path = "users.rs"] | ||
452 | mod bar; | ||
453 | } | ||
454 | |||
455 | //- /users.rs | ||
456 | pub struct Baz; | ||
457 | "###, | ||
458 | ); | ||
459 | |||
460 | assert_snapshot!(map, @r###" | ||
461 | ⋮crate | ||
462 | ⋮foo: t | ||
463 | ⋮ | ||
464 | ⋮crate::foo | ||
465 | ⋮bar: t | ||
466 | ⋮ | ||
467 | ⋮crate::foo::bar | ||
468 | ⋮Baz: t v | ||
469 | "###); | ||
470 | } | ||
471 | |||
472 | #[test] | ||
473 | fn module_resolution_decl_empty_path() { | ||
474 | let map = def_map( | ||
475 | r###" | ||
476 | //- /main.rs | ||
477 | #[path = ""] // Should try to read `/` (a directory) | ||
478 | mod foo; | ||
479 | |||
480 | //- /foo.rs | ||
481 | pub struct Baz; | ||
482 | "###, | ||
483 | ); | ||
484 | |||
485 | assert_snapshot!(map, @r###" | ||
486 | ⋮crate | ||
487 | "###); | ||
488 | } | ||
489 | |||
490 | #[test] | ||
491 | fn module_resolution_decl_inside_inline_module_relative_path() { | ||
492 | let map = def_map( | ||
493 | r###" | ||
494 | //- /main.rs | ||
495 | #[path = "./models"] | ||
496 | mod foo { | ||
497 | mod bar; | ||
498 | } | ||
499 | |||
500 | //- /models/bar.rs | ||
501 | pub struct Baz; | ||
502 | "###, | ||
503 | ); | ||
504 | |||
505 | assert_snapshot!(map, @r###" | ||
506 | ⋮crate | ||
507 | ⋮foo: t | ||
508 | ⋮ | ||
509 | ⋮crate::foo | ||
510 | ⋮bar: t | ||
511 | ⋮ | ||
512 | ⋮crate::foo::bar | ||
513 | ⋮Baz: t v | ||
514 | "###); | ||
515 | } | ||
516 | |||
517 | #[test] | ||
518 | fn module_resolution_decl_inside_inline_module_in_crate_root() { | ||
519 | let map = def_map( | ||
520 | r###" | ||
521 | //- /main.rs | ||
522 | mod foo { | ||
523 | #[path = "baz.rs"] | ||
524 | mod bar; | ||
525 | } | ||
526 | use self::foo::bar::Baz; | ||
527 | |||
528 | //- /foo/baz.rs | ||
529 | pub struct Baz; | ||
530 | "###, | ||
531 | ); | ||
532 | |||
533 | assert_snapshot!(map, @r###" | ||
534 | ⋮crate | ||
535 | ⋮Baz: t v | ||
536 | ⋮foo: t | ||
537 | ⋮ | ||
538 | ⋮crate::foo | ||
539 | ⋮bar: t | ||
540 | ⋮ | ||
541 | ⋮crate::foo::bar | ||
542 | ⋮Baz: t v | ||
543 | "###); | ||
544 | } | ||
545 | |||
546 | #[test] | ||
547 | fn module_resolution_decl_inside_inline_module_in_mod_rs() { | ||
548 | let map = def_map( | ||
549 | r###" | ||
550 | //- /main.rs | ||
551 | mod foo; | ||
552 | |||
553 | //- /foo/mod.rs | ||
554 | mod bar { | ||
555 | #[path = "qwe.rs"] | ||
556 | pub mod baz; | ||
557 | } | ||
558 | use self::bar::baz::Baz; | ||
559 | |||
560 | //- /foo/bar/qwe.rs | ||
561 | pub struct Baz; | ||
562 | "###, | ||
563 | ); | ||
564 | |||
565 | assert_snapshot!(map, @r###" | ||
566 | ⋮crate | ||
567 | ⋮foo: t | ||
568 | ⋮ | ||
569 | ⋮crate::foo | ||
570 | ⋮Baz: t v | ||
571 | ⋮bar: t | ||
572 | ⋮ | ||
573 | ⋮crate::foo::bar | ||
574 | ⋮baz: t | ||
575 | ⋮ | ||
576 | ⋮crate::foo::bar::baz | ||
577 | ⋮Baz: t v | ||
578 | "###); | ||
579 | } | ||
580 | |||
581 | #[test] | ||
582 | fn module_resolution_decl_inside_inline_module_in_non_crate_root() { | ||
583 | let map = def_map( | ||
584 | r###" | ||
585 | //- /main.rs | ||
586 | mod foo; | ||
587 | |||
588 | //- /foo.rs | ||
589 | mod bar { | ||
590 | #[path = "qwe.rs"] | ||
591 | pub mod baz; | ||
592 | } | ||
593 | use self::bar::baz::Baz; | ||
594 | |||
595 | //- /foo/bar/qwe.rs | ||
596 | pub struct Baz; | ||
597 | "###, | ||
598 | ); | ||
599 | |||
600 | assert_snapshot!(map, @r###" | ||
601 | ⋮crate | ||
602 | ⋮foo: t | ||
603 | ⋮ | ||
604 | ⋮crate::foo | ||
605 | ⋮Baz: t v | ||
606 | ⋮bar: t | ||
607 | ⋮ | ||
608 | ⋮crate::foo::bar | ||
609 | ⋮baz: t | ||
610 | ⋮ | ||
611 | ⋮crate::foo::bar::baz | ||
612 | ⋮Baz: t v | ||
613 | "###); | ||
614 | } | ||
615 | |||
616 | #[test] | ||
617 | fn module_resolution_decl_inside_inline_module_in_non_crate_root_2() { | ||
618 | let map = def_map( | ||
619 | r###" | ||
620 | //- /main.rs | ||
621 | mod foo; | ||
622 | |||
623 | //- /foo.rs | ||
624 | #[path = "bar"] | ||
625 | mod bar { | ||
626 | pub mod baz; | ||
627 | } | ||
628 | use self::bar::baz::Baz; | ||
629 | |||
630 | //- /bar/baz.rs | ||
631 | pub struct Baz; | ||
632 | "###, | ||
633 | ); | ||
634 | |||
635 | assert_snapshot!(map, @r###" | ||
636 | ⋮crate | ||
637 | ⋮foo: t | ||
638 | ⋮ | ||
639 | ⋮crate::foo | ||
640 | ⋮Baz: t v | ||
641 | ⋮bar: t | ||
642 | ⋮ | ||
643 | ⋮crate::foo::bar | ||
644 | ⋮baz: t | ||
645 | ⋮ | ||
646 | ⋮crate::foo::bar::baz | ||
647 | ⋮Baz: t v | ||
648 | "###); | ||
649 | } | ||
650 | |||
651 | #[test] | ||
652 | fn unresolved_module_diagnostics() { | ||
653 | let diagnostics = MockDatabase::with_files( | ||
654 | r" | ||
655 | //- /lib.rs | ||
656 | mod foo; | ||
657 | mod bar; | ||
658 | mod baz {} | ||
659 | //- /foo.rs | ||
660 | ", | ||
661 | ) | ||
662 | .diagnostics(); | ||
663 | |||
664 | assert_snapshot!(diagnostics, @r###" | ||
665 | "mod bar;": unresolved module | ||
666 | "### | ||
667 | ); | ||
668 | } | ||
669 | |||
670 | #[test] | ||
671 | fn module_resolution_decl_inside_module_in_non_crate_root_2() { | ||
672 | let map = def_map( | ||
673 | r###" | ||
674 | //- /main.rs | ||
675 | #[path="module/m2.rs"] | ||
676 | mod module; | ||
677 | |||
678 | //- /module/m2.rs | ||
679 | pub mod submod; | ||
680 | |||
681 | //- /module/submod.rs | ||
682 | pub struct Baz; | ||
683 | "###, | ||
684 | ); | ||
685 | |||
686 | assert_snapshot!(map, @r###" | ||
687 | ⋮crate | ||
688 | ⋮module: t | ||
689 | ⋮ | ||
690 | ⋮crate::module | ||
691 | ⋮submod: t | ||
692 | ⋮ | ||
693 | ⋮crate::module::submod | ||
694 | ⋮Baz: t v | ||
695 | "###); | ||
696 | } | ||
697 | |||
698 | #[test] | ||
699 | fn nested_out_of_line_module() { | ||
700 | let map = def_map( | ||
701 | r###" | ||
702 | //- /lib.rs | ||
703 | mod a { | ||
704 | mod b { | ||
705 | mod c; | ||
706 | } | ||
707 | } | ||
708 | |||
709 | //- /a/b/c.rs | ||
710 | struct X; | ||
711 | "###, | ||
712 | ); | ||
713 | |||
714 | assert_snapshot!(map, @r###" | ||
715 | crate | ||
716 | a: t | ||
717 | |||
718 | crate::a | ||
719 | b: t | ||
720 | |||
721 | crate::a::b | ||
722 | c: t | ||
723 | |||
724 | crate::a::b::c | ||
725 | X: t v | ||
726 | "###); | ||
727 | } | ||
728 | |||
729 | #[test] | ||
730 | fn nested_out_of_line_module_with_path() { | ||
731 | let map = def_map( | ||
732 | r###" | ||
733 | //- /lib.rs | ||
734 | mod a { | ||
735 | #[path = "d/e"] | ||
736 | mod b { | ||
737 | mod c; | ||
738 | } | ||
739 | } | ||
740 | |||
741 | //- /a/d/e/c.rs | ||
742 | struct X; | ||
743 | "###, | ||
744 | ); | ||
745 | |||
746 | assert_snapshot!(map, @r###" | ||
747 | crate | ||
748 | a: t | ||
749 | |||
750 | crate::a | ||
751 | b: t | ||
752 | |||
753 | crate::a::b | ||
754 | c: t | ||
755 | |||
756 | crate::a::b::c | ||
757 | X: t v | ||
758 | "###); | ||
759 | } | ||
diff --git a/crates/ra_hir/src/nameres/tests/primitives.rs b/crates/ra_hir/src/nameres/tests/primitives.rs deleted file mode 100644 index 0e2708658..000000000 --- a/crates/ra_hir/src/nameres/tests/primitives.rs +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | use super::*; | ||
2 | |||
3 | #[test] | ||
4 | fn primitive_reexport() { | ||
5 | let map = def_map( | ||
6 | " | ||
7 | //- /lib.rs | ||
8 | mod foo; | ||
9 | use foo::int; | ||
10 | |||
11 | //- /foo.rs | ||
12 | pub use i32 as int; | ||
13 | ", | ||
14 | ); | ||
15 | assert_snapshot!(map, @r###" | ||
16 | ⋮crate | ||
17 | ⋮foo: t | ||
18 | ⋮int: t | ||
19 | ⋮ | ||
20 | ⋮crate::foo | ||
21 | ⋮int: t | ||
22 | "### | ||
23 | ); | ||
24 | } | ||