From 397d84ee292295ce1d19033e586467ef9148e5bc Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 2 Feb 2019 00:36:48 +0100 Subject: Add test for extern crate renames --- crates/ra_hir/src/nameres/tests.rs | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 81c8a4f12..42c59f76f 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -334,6 +334,48 @@ fn item_map_across_crates() { ); } +#[test] +fn extern_crate_rename() { + let (mut db, sr) = MockDatabase::with_files( + " + //- /main.rs + extern crate alloc as alloc_crate; + + mod alloc; + + use alloc_crate::Arc; + + //- /lib.rs + struct Arc; + ", + ); + let main_id = sr.files[RelativePath::new("/main.rs")]; + let lib_id = sr.files[RelativePath::new("/lib.rs")]; + + let mut crate_graph = CrateGraph::default(); + let main_crate = crate_graph.add_crate_root(main_id); + let lib_crate = crate_graph.add_crate_root(lib_id); + crate_graph + .add_dep(main_crate, "alloc".into(), lib_crate) + .unwrap(); + + db.set_crate_graph(Arc::new(crate_graph)); + + let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); + let krate = module.krate(&db).unwrap(); + let item_map = db.item_map(krate); + + check_module_item_map( + &item_map, + module.module_id, + " + Arc: t v + alloc: t + alloc_crate: t + ", + ); +} + #[test] fn import_across_source_roots() { let (mut db, sr) = MockDatabase::with_files( -- cgit v1.2.3