aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres/tests
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-10-10 12:45:05 +0100
committerAleksey Kladov <[email protected]>2019-10-10 12:46:14 +0100
commitce0d4a3b1deaca318a1ed2ff83cca652ef8e8c82 (patch)
treec3f495cd98d2a992a2f7b636f2284af2c5c86715 /crates/ra_hir/src/nameres/tests
parent72b8cfb5aa99d85cd8cc936232cbbf24d1995547 (diff)
Refactor and fix some more edge cases around name resolution
Diffstat (limited to 'crates/ra_hir/src/nameres/tests')
-rw-r--r--crates/ra_hir/src/nameres/tests/macros.rs29
-rw-r--r--crates/ra_hir/src/nameres/tests/mod_resolution.rs100
2 files changed, 114 insertions, 15 deletions
diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs
index e4b408394..4f52ad2c5 100644
--- a/crates/ra_hir/src/nameres/tests/macros.rs
+++ b/crates/ra_hir/src/nameres/tests/macros.rs
@@ -38,21 +38,34 @@ fn macro_rules_can_define_modules() {
38 } 38 }
39 m!(n1); 39 m!(n1);
40 40
41 mod m {
42 m!(n3)
43 }
44
41 //- /n1.rs 45 //- /n1.rs
42 m!(n2) 46 m!(n2)
43 //- /n1/n2.rs 47 //- /n1/n2.rs
44 struct X; 48 struct X;
49 //- /m/n3.rs
50 struct Y;
45 ", 51 ",
46 ); 52 );
47 assert_snapshot!(map, @r###" 53 assert_snapshot!(map, @r###"
48 ⋮crate 54 crate
49 ⋮n1: t 55 m: t
50 56 n1: t
51 ⋮crate::n1 57
52 ⋮n2: t 58 crate::m
53 59 n3: t
54 ⋮crate::n1::n2 60
55 ⋮X: t v 61 crate::m::n3
62 Y: t v
63
64 crate::n1
65 n2: t
66
67 crate::n1::n2
68 X: t v
56 "###); 69 "###);
57} 70}
58 71
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}