From ce0d4a3b1deaca318a1ed2ff83cca652ef8e8c82 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 10 Oct 2019 14:45:05 +0300 Subject: Refactor and fix some more edge cases around name resolution --- crates/ra_hir/src/nameres/tests/mod_resolution.rs | 100 ++++++++++++++++++++-- 1 file changed, 93 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir/src/nameres/tests/mod_resolution.rs') 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 @@ -25,6 +25,33 @@ fn name_res_works_for_broken_modules() { "###); } +#[test] +fn nested_module_resolution() { + let map = def_map( + " + //- /lib.rs + mod n1; + + //- /n1.rs + mod n2; + + //- /n1/n2.rs + struct X; + ", + ); + + assert_snapshot!(map, @r###" + ⋮crate + ⋮n1: t + ⋮ + ⋮crate::n1 + ⋮n2: t + ⋮ + ⋮crate::n1::n2 + ⋮X: t v + "###); +} + #[test] fn module_resolution_works_for_non_standard_filenames() { let map = def_map_with_crate_graph( @@ -467,7 +494,7 @@ fn module_resolution_decl_inside_inline_module_empty_path() { mod bar; } - //- /foo/users.rs + //- /users.rs pub struct Baz; "###, crate_graph! { @@ -492,7 +519,7 @@ fn module_resolution_decl_empty_path() { let map = def_map_with_crate_graph( r###" //- /main.rs - #[path = ""] + #[path = ""] // Should try to read `/` (a directory) mod foo; //- /foo.rs @@ -505,10 +532,6 @@ fn module_resolution_decl_empty_path() { assert_snapshot!(map, @r###" ⋮crate - ⋮foo: t - ⋮ - ⋮crate::foo - ⋮Baz: t v "###); } @@ -626,7 +649,7 @@ fn module_resolution_decl_inside_inline_module_in_non_crate_root() { } use self::bar::baz::Baz; - //- /bar/qwe.rs + //- /foo/bar/qwe.rs pub struct Baz; "###, crate_graph! { @@ -737,3 +760,66 @@ fn module_resolution_decl_inside_module_in_non_crate_root_2() { ⋮Baz: t v "###); } + +#[test] +fn nested_out_of_line_module() { + let map = def_map( + r###" + //- /lib.rs + mod a { + mod b { + mod c; + } + } + + //- /a/b/c.rs + struct X; + "###, + ); + + assert_snapshot!(map, @r###" + crate + a: t + + crate::a + b: t + + crate::a::b + c: t + + crate::a::b::c + X: t v + "###); +} + +#[test] +fn nested_out_of_line_module_with_path() { + let map = def_map( + r###" + //- /lib.rs + mod a { + #[path = "d/e"] + mod b { + mod c; + } + } + + //- /a/d/e/c.rs + struct X; + "###, + ); + + assert_snapshot!(map, @r###" + crate + a: t + + crate::a + b: t + + crate::a::b + c: t + + crate::a::b::c + X: t v + "###); +} -- cgit v1.2.3