From 683e5e64f42b6c74596015c5d19e2eab186fe68d Mon Sep 17 00:00:00 2001 From: Erlend Tobiassen Date: Sun, 27 Jan 2019 14:51:26 +0100 Subject: Test non standard crate root --- crates/ra_hir/src/nameres/tests.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'crates/ra_hir/src/nameres') diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index e72781f51..5b161cf49 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -19,6 +19,19 @@ fn item_map(fixture: &str) -> (Arc, ModuleId) { (db.item_map(krate.crate_id), module_id) } +fn item_map_custom_crate_root(fixture: &str, root: &str) -> (Arc, ModuleId) { + let (mut db, pos) = MockDatabase::with_position(fixture); + + let mut crate_graph = CrateGraph::default(); + crate_graph.add_crate_root(db.file_id(root)); + db.set_crate_graph(Arc::new(crate_graph)); + + let module = crate::source_binder::module_from_position(&db, dbg!(pos)).unwrap(); + let krate = module.krate(&db).unwrap(); + let module_id = module.module_id; + (db.item_map(krate.crate_id), module_id) +} + fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { let mut lines = map[module_id] .items @@ -133,6 +146,31 @@ fn re_exports() { ); } +#[test] +fn module_resolution_works_for_non_standard_filenames() { + let (item_map, module_id) = item_map_custom_crate_root( + " + //- /my_library.rs + mod foo; + + use self::foo::Bar; + <|> + + //- /foo/mod.rs + pub struct Bar; + ", + "/my_library.rs", + ); + check_module_item_map( + &item_map, + module_id, + " + Bar: t v + foo: t + ", + ); +} + #[test] fn name_res_works_for_broken_modules() { covers!(name_res_works_for_broken_modules); -- cgit v1.2.3 From b149882d198818d6302c2a6318d68c4e0b4380ff Mon Sep 17 00:00:00 2001 From: Erlend Tobiassen Date: Sun, 27 Jan 2019 15:44:59 +0100 Subject: Remove dbg!(...) --- crates/ra_hir/src/nameres/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir/src/nameres') diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 5b161cf49..971f71637 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -26,7 +26,7 @@ fn item_map_custom_crate_root(fixture: &str, root: &str) -> (Arc, Modul crate_graph.add_crate_root(db.file_id(root)); db.set_crate_graph(Arc::new(crate_graph)); - let module = crate::source_binder::module_from_position(&db, dbg!(pos)).unwrap(); + let module = crate::source_binder::module_from_position(&db, pos).unwrap(); let krate = module.krate(&db).unwrap(); let module_id = module.module_id; (db.item_map(krate.crate_id), module_id) -- cgit v1.2.3 From b775fa285c985821f38f09c25507d80ee793ecfd Mon Sep 17 00:00:00 2001 From: Erlend Tobiassen Date: Sun, 27 Jan 2019 16:32:31 +0100 Subject: Revert parts of "Test non standard crate root" Prefer cursor position over file_map --- crates/ra_hir/src/nameres/tests.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir/src/nameres') diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 971f71637..3d420467c 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -19,11 +19,12 @@ fn item_map(fixture: &str) -> (Arc, ModuleId) { (db.item_map(krate.crate_id), module_id) } -fn item_map_custom_crate_root(fixture: &str, root: &str) -> (Arc, ModuleId) { +/// Sets the crate root to the file of the cursor marker +fn item_map_custom_crate_root(fixture: &str) -> (Arc, ModuleId) { let (mut db, pos) = MockDatabase::with_position(fixture); let mut crate_graph = CrateGraph::default(); - crate_graph.add_crate_root(db.file_id(root)); + crate_graph.add_crate_root(pos.file_id); db.set_crate_graph(Arc::new(crate_graph)); let module = crate::source_binder::module_from_position(&db, pos).unwrap(); @@ -152,14 +153,11 @@ fn module_resolution_works_for_non_standard_filenames() { " //- /my_library.rs mod foo; - use self::foo::Bar; <|> - //- /foo/mod.rs pub struct Bar; ", - "/my_library.rs", ); check_module_item_map( &item_map, -- cgit v1.2.3