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.rs100
1 files changed, 93 insertions, 7 deletions
diff --git a/crates/ra_hir/src/nameres/tests/mod_resolution.rs b/crates/ra_hir/src/nameres/tests/mod_resolution.rs
index e3e6f1e95..755f5723b 100644
--- a/crates/ra_hir/src/nameres/tests/mod_resolution.rs
+++ b/crates/ra_hir/src/nameres/tests/mod_resolution.rs
@@ -26,6 +26,33 @@ fn name_res_works_for_broken_modules() {
26} 26}
27 27
28#[test] 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]
29fn module_resolution_works_for_non_standard_filenames() { 56fn module_resolution_works_for_non_standard_filenames() {
30 let map = def_map_with_crate_graph( 57 let map = def_map_with_crate_graph(
31 " 58 "
@@ -467,7 +494,7 @@ fn module_resolution_decl_inside_inline_module_empty_path() {
467 mod bar; 494 mod bar;
468 } 495 }
469 496
470 //- /foo/users.rs 497 //- /users.rs
471 pub struct Baz; 498 pub struct Baz;
472 "###, 499 "###,
473 crate_graph! { 500 crate_graph! {
@@ -492,7 +519,7 @@ fn module_resolution_decl_empty_path() {
492 let map = def_map_with_crate_graph( 519 let map = def_map_with_crate_graph(
493 r###" 520 r###"
494 //- /main.rs 521 //- /main.rs
495 #[path = ""] 522 #[path = ""] // Should try to read `/` (a directory)
496 mod foo; 523 mod foo;
497 524
498 //- /foo.rs 525 //- /foo.rs
@@ -505,10 +532,6 @@ fn module_resolution_decl_empty_path() {
505 532
506 assert_snapshot!(map, @r###" 533 assert_snapshot!(map, @r###"
507 ⋮crate 534 ⋮crate
508 ⋮foo: t
509
510 ⋮crate::foo
511 ⋮Baz: t v
512 "###); 535 "###);
513} 536}
514 537
@@ -626,7 +649,7 @@ fn module_resolution_decl_inside_inline_module_in_non_crate_root() {
626 } 649 }
627 use self::bar::baz::Baz; 650 use self::bar::baz::Baz;
628 651
629 //- /bar/qwe.rs 652 //- /foo/bar/qwe.rs
630 pub struct Baz; 653 pub struct Baz;
631 "###, 654 "###,
632 crate_graph! { 655 crate_graph! {
@@ -737,3 +760,66 @@ fn module_resolution_decl_inside_module_in_non_crate_root_2() {
737 ⋮Baz: t v 760 ⋮Baz: t v
738 "###); 761 "###);
739} 762}
763
764#[test]
765fn nested_out_of_line_module() {
766 let map = def_map(
767 r###"
768 //- /lib.rs
769 mod a {
770 mod b {
771 mod c;
772 }
773 }
774
775 //- /a/b/c.rs
776 struct X;
777 "###,
778 );
779
780 assert_snapshot!(map, @r###"
781 crate
782 a: t
783
784 crate::a
785 b: t
786
787 crate::a::b
788 c: t
789
790 crate::a::b::c
791 X: t v
792 "###);
793}
794
795#[test]
796fn nested_out_of_line_module_with_path() {
797 let map = def_map(
798 r###"
799 //- /lib.rs
800 mod a {
801 #[path = "d/e"]
802 mod b {
803 mod c;
804 }
805 }
806
807 //- /a/d/e/c.rs
808 struct X;
809 "###,
810 );
811
812 assert_snapshot!(map, @r###"
813 crate
814 a: t
815
816 crate::a
817 b: t
818
819 crate::a::b
820 c: t
821
822 crate::a::b::c
823 X: t v
824 "###);
825}