aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres/tests/mod_resolution.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/nameres/tests/mod_resolution.rs')
-rw-r--r--crates/ra_hir/src/nameres/tests/mod_resolution.rs759
1 files changed, 0 insertions, 759 deletions
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 @@
1use super::*;
2
3#[test]
4fn 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]
29fn 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]
56fn 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]
82fn 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]
105fn 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]
129fn 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]
160fn 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]
191fn 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]
215fn 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]
237fn 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]
265fn 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]
293fn 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]
315fn 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]
337fn 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]
364fn 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]
390fn 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]
417fn 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]
445fn 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]
473fn 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]
491fn 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]
518fn 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]
547fn 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]
582fn 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]
617fn 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]
652fn 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]
671fn 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]
699fn 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]
730fn 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}