aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs
diff options
context:
space:
mode:
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.rs796
1 files changed, 0 insertions, 796 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
deleted file mode 100644
index 1f619787e..000000000
--- a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs
+++ /dev/null
@@ -1,796 +0,0 @@
1use super::*;
2
3#[test]
4fn name_res_works_for_broken_modules() {
5 mark::check!(name_res_works_for_broken_modules);
6 check(
7 r"
8//- /lib.rs
9mod foo // no `;`, no body
10use self::foo::Baz;
11
12//- /foo/mod.rs
13pub mod bar;
14pub use self::bar::Baz;
15
16//- /foo/bar.rs
17pub struct Baz;
18",
19 expect![[r#"
20 crate
21 Baz: _
22 foo: t
23
24 crate::foo
25 "#]],
26 );
27}
28
29#[test]
30fn nested_module_resolution() {
31 check(
32 r#"
33//- /lib.rs
34mod n1;
35
36//- /n1.rs
37mod n2;
38
39//- /n1/n2.rs
40struct X;
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 "#]],
52 );
53}
54
55#[test]
56fn nested_module_resolution_2() {
57 check(
58 r#"
59//- /lib.rs
60mod prelude;
61mod iter;
62
63//- /prelude.rs
64pub use crate::iter::Iterator;
65
66//- /iter.rs
67pub use self::traits::Iterator;
68mod traits;
69
70//- /iter/traits.rs
71pub use self::iterator::Iterator;
72mod iterator;
73
74//- /iter/traits/iterator.rs
75pub trait Iterator;
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 "#]],
96 );
97}
98
99#[test]
100fn module_resolution_works_for_non_standard_filenames() {
101 check(
102 r#"
103//- /my_library.rs crate:my_library
104mod foo;
105use self::foo::Bar;
106
107//- /foo/mod.rs
108pub struct Bar;
109"#,
110 expect![[r#"
111 crate
112 Bar: t v
113 foo: t
114
115 crate::foo
116 Bar: t v
117 "#]],
118 );
119}
120
121#[test]
122fn module_resolution_works_for_raw_modules() {
123 check(
124 r#"
125//- /lib.rs
126mod r#async;
127use self::r#async::Bar;
128
129//- /async.rs
130pub struct Bar;
131"#,
132 expect![[r#"
133 crate
134 Bar: t v
135 async: t
136
137 crate::async
138 Bar: t v
139 "#]],
140 );
141}
142
143#[test]
144fn module_resolution_decl_path() {
145 check(
146 r#"
147//- /lib.rs
148#[path = "bar/baz/foo.rs"]
149mod foo;
150use self::foo::Bar;
151
152//- /bar/baz/foo.rs
153pub struct Bar;
154"#,
155 expect![[r#"
156 crate
157 Bar: t v
158 foo: t
159
160 crate::foo
161 Bar: t v
162 "#]],
163 );
164}
165
166#[test]
167fn module_resolution_module_with_path_in_mod_rs() {
168 check(
169 r#"
170//- /main.rs
171mod foo;
172
173//- /foo/mod.rs
174#[path = "baz.rs"]
175pub mod bar;
176use self::bar::Baz;
177
178//- /foo/baz.rs
179pub struct Baz;
180"#,
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 "#]],
192 );
193}
194
195#[test]
196fn module_resolution_module_with_path_non_crate_root() {
197 check(
198 r#"
199//- /main.rs
200mod foo;
201
202//- /foo.rs
203#[path = "baz.rs"]
204pub mod bar;
205use self::bar::Baz;
206
207//- /baz.rs
208pub struct Baz;
209"#,
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 "#]],
221 );
222}
223
224#[test]
225fn module_resolution_module_decl_path_super() {
226 check(
227 r#"
228//- /main.rs
229#[path = "bar/baz/module.rs"]
230mod foo;
231pub struct Baz;
232
233//- /bar/baz/module.rs
234use super::Baz;
235"#,
236 expect![[r#"
237 crate
238 Baz: t v
239 foo: t
240
241 crate::foo
242 Baz: t v
243 "#]],
244 );
245}
246
247#[test]
248fn module_resolution_explicit_path_mod_rs() {
249 check(
250 r#"
251//- /main.rs
252#[path = "module/mod.rs"]
253mod foo;
254
255//- /module/mod.rs
256pub struct Baz;
257"#,
258 expect![[r#"
259 crate
260 foo: t
261
262 crate::foo
263 Baz: t v
264 "#]],
265 );
266}
267
268#[test]
269fn module_resolution_relative_path() {
270 check(
271 r#"
272//- /main.rs
273mod foo;
274
275//- /foo.rs
276#[path = "./sub.rs"]
277pub mod foo_bar;
278
279//- /sub.rs
280pub struct Baz;
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 "#]],
292 );
293}
294
295#[test]
296fn module_resolution_relative_path_2() {
297 check(
298 r#"
299//- /main.rs
300mod foo;
301
302//- /foo/mod.rs
303#[path="../sub.rs"]
304pub mod foo_bar;
305
306//- /sub.rs
307pub struct Baz;
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 "#]],
319 );
320}
321
322#[test]
323fn module_resolution_relative_path_outside_root() {
324 check(
325 r#"
326//- /main.rs
327#[path="../../../../../outside.rs"]
328mod foo;
329"#,
330 expect![[r#"
331 crate
332 "#]],
333 );
334}
335
336#[test]
337fn module_resolution_explicit_path_mod_rs_2() {
338 check(
339 r#"
340//- /main.rs
341#[path = "module/bar/mod.rs"]
342mod foo;
343
344//- /module/bar/mod.rs
345pub struct Baz;
346"#,
347 expect![[r#"
348 crate
349 foo: t
350
351 crate::foo
352 Baz: t v
353 "#]],
354 );
355}
356
357#[test]
358fn module_resolution_explicit_path_mod_rs_with_win_separator() {
359 check(
360 r#"
361//- /main.rs
362#[path = "module\bar\mod.rs"]
363mod foo;
364
365//- /module/bar/mod.rs
366pub struct Baz;
367"#,
368 expect![[r#"
369 crate
370 foo: t
371
372 crate::foo
373 Baz: t v
374 "#]],
375 );
376}
377
378#[test]
379fn module_resolution_decl_inside_inline_module_with_path_attribute() {
380 check(
381 r#"
382//- /main.rs
383#[path = "models"]
384mod foo { mod bar; }
385
386//- /models/bar.rs
387pub struct Baz;
388"#,
389 expect![[r#"
390 crate
391 foo: t
392
393 crate::foo
394 bar: t
395
396 crate::foo::bar
397 Baz: t v
398 "#]],
399 );
400}
401
402#[test]
403fn module_resolution_decl_inside_inline_module() {
404 check(
405 r#"
406//- /main.rs
407mod foo { mod bar; }
408
409//- /foo/bar.rs
410pub struct Baz;
411"#,
412 expect![[r#"
413 crate
414 foo: t
415
416 crate::foo
417 bar: t
418
419 crate::foo::bar
420 Baz: t v
421 "#]],
422 );
423}
424
425#[test]
426fn module_resolution_decl_inside_inline_module_2_with_path_attribute() {
427 check(
428 r#"
429//- /main.rs
430#[path = "models/db"]
431mod foo { mod bar; }
432
433//- /models/db/bar.rs
434pub struct Baz;
435"#,
436 expect![[r#"
437 crate
438 foo: t
439
440 crate::foo
441 bar: t
442
443 crate::foo::bar
444 Baz: t v
445 "#]],
446 );
447}
448
449#[test]
450fn module_resolution_decl_inside_inline_module_3() {
451 check(
452 r#"
453//- /main.rs
454#[path = "models/db"]
455mod foo {
456 #[path = "users.rs"]
457 mod bar;
458}
459
460//- /models/db/users.rs
461pub struct Baz;
462"#,
463 expect![[r#"
464 crate
465 foo: t
466
467 crate::foo
468 bar: t
469
470 crate::foo::bar
471 Baz: t v
472 "#]],
473 );
474}
475
476#[test]
477fn module_resolution_decl_inside_inline_module_empty_path() {
478 check(
479 r#"
480//- /main.rs
481#[path = ""]
482mod foo {
483 #[path = "users.rs"]
484 mod bar;
485}
486
487//- /users.rs
488pub struct Baz;
489"#,
490 expect![[r#"
491 crate
492 foo: t
493
494 crate::foo
495 bar: t
496
497 crate::foo::bar
498 Baz: t v
499 "#]],
500 );
501}
502
503#[test]
504fn module_resolution_decl_empty_path() {
505 check(
506 r#"
507//- /main.rs
508#[path = ""] // Should try to read `/` (a directory)
509mod foo;
510
511//- /foo.rs
512pub struct Baz;
513"#,
514 expect![[r#"
515 crate
516 "#]],
517 );
518}
519
520#[test]
521fn module_resolution_decl_inside_inline_module_relative_path() {
522 check(
523 r#"
524//- /main.rs
525#[path = "./models"]
526mod foo { mod bar; }
527
528//- /models/bar.rs
529pub struct Baz;
530"#,
531 expect![[r#"
532 crate
533 foo: t
534
535 crate::foo
536 bar: t
537
538 crate::foo::bar
539 Baz: t v
540 "#]],
541 );
542}
543
544#[test]
545fn module_resolution_decl_inside_inline_module_in_crate_root() {
546 check(
547 r#"
548//- /main.rs
549mod foo {
550 #[path = "baz.rs"]
551 mod bar;
552}
553use self::foo::bar::Baz;
554
555//- /foo/baz.rs
556pub struct Baz;
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 "#]],
569 );
570}
571
572#[test]
573fn module_resolution_decl_inside_inline_module_in_mod_rs() {
574 check(
575 r#"
576//- /main.rs
577mod foo;
578
579//- /foo/mod.rs
580mod bar {
581 #[path = "qwe.rs"]
582 pub mod baz;
583}
584use self::bar::baz::Baz;
585
586//- /foo/bar/qwe.rs
587pub struct Baz;
588"#,
589 expect![[r#"
590 crate
591 foo: t
592
593 crate::foo
594 Baz: t v
595 bar: t
596
597 crate::foo::bar
598 baz: t
599
600 crate::foo::bar::baz
601 Baz: t v
602 "#]],
603 );
604}
605
606#[test]
607fn module_resolution_decl_inside_inline_module_in_non_crate_root() {
608 check(
609 r#"
610//- /main.rs
611mod foo;
612
613//- /foo.rs
614mod bar {
615 #[path = "qwe.rs"]
616 pub mod baz;
617}
618use self::bar::baz::Baz;
619
620//- /foo/bar/qwe.rs
621pub struct Baz;
622"#,
623 expect![[r#"
624 crate
625 foo: t
626
627 crate::foo
628 Baz: t v
629 bar: t
630
631 crate::foo::bar
632 baz: t
633
634 crate::foo::bar::baz
635 Baz: t v
636 "#]],
637 );
638}
639
640#[test]
641fn module_resolution_decl_inside_inline_module_in_non_crate_root_2() {
642 check(
643 r#"
644//- /main.rs
645mod foo;
646
647//- /foo.rs
648#[path = "bar"]
649mod bar {
650 pub mod baz;
651}
652use self::bar::baz::Baz;
653
654//- /bar/baz.rs
655pub struct Baz;
656"#,
657 expect![[r#"
658 crate
659 foo: t
660
661 crate::foo
662 Baz: t v
663 bar: t
664
665 crate::foo::bar
666 baz: t
667
668 crate::foo::bar::baz
669 Baz: t v
670 "#]],
671 );
672}
673
674#[test]
675fn unresolved_module_diagnostics() {
676 let db = TestDB::with_files(
677 r"
678 //- /lib.rs
679 mod foo;
680 mod bar;
681 mod baz {}
682 //- /foo.rs
683 ",
684 );
685 let krate = db.test_crate();
686
687 let crate_def_map = db.crate_def_map(krate);
688
689 expect![[r#"
690 [
691 UnresolvedModule {
692 module: Idx::<ModuleData>(0),
693 declaration: InFile {
694 file_id: HirFileId(
695 FileId(
696 FileId(
697 0,
698 ),
699 ),
700 ),
701 value: FileAstId::<syntax::ast::generated::nodes::Module>(1),
702 },
703 candidate: "bar.rs",
704 },
705 ]
706 "#]]
707 .assert_debug_eq(&crate_def_map.diagnostics);
708}
709
710#[test]
711fn module_resolution_decl_inside_module_in_non_crate_root_2() {
712 check(
713 r#"
714//- /main.rs
715#[path="module/m2.rs"]
716mod module;
717
718//- /module/m2.rs
719pub mod submod;
720
721//- /module/submod.rs
722pub struct Baz;
723"#,
724 expect![[r#"
725 crate
726 module: t
727
728 crate::module
729 submod: t
730
731 crate::module::submod
732 Baz: t v
733 "#]],
734 );
735}
736
737#[test]
738fn nested_out_of_line_module() {
739 check(
740 r#"
741//- /lib.rs
742mod a {
743 mod b {
744 mod c;
745 }
746}
747
748//- /a/b/c.rs
749struct X;
750"#,
751 expect![[r#"
752 crate
753 a: t
754
755 crate::a
756 b: t
757
758 crate::a::b
759 c: t
760
761 crate::a::b::c
762 X: t v
763 "#]],
764 );
765}
766
767#[test]
768fn nested_out_of_line_module_with_path() {
769 check(
770 r#"
771//- /lib.rs
772mod a {
773 #[path = "d/e"]
774 mod b {
775 mod c;
776 }
777}
778
779//- /a/d/e/c.rs
780struct X;
781"#,
782 expect![[r#"
783 crate
784 a: t
785
786 crate::a
787 b: t
788
789 crate::a::b
790 c: t
791
792 crate::a::b::c
793 X: t v
794 "#]],
795 );
796}