aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/module/nameres/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/module/nameres/tests.rs')
-rw-r--r--crates/ra_hir/src/module/nameres/tests.rs37
1 files changed, 35 insertions, 2 deletions
diff --git a/crates/ra_hir/src/module/nameres/tests.rs b/crates/ra_hir/src/module/nameres/tests.rs
index 060683e27..9ddc32dcd 100644
--- a/crates/ra_hir/src/module/nameres/tests.rs
+++ b/crates/ra_hir/src/module/nameres/tests.rs
@@ -1,7 +1,7 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use salsa::Database; 3use salsa::Database;
4use ra_db::FilesDatabase; 4use ra_db::{FilesDatabase, CrateGraph};
5use ra_syntax::SmolStr; 5use ra_syntax::SmolStr;
6 6
7use crate::{ 7use crate::{
@@ -21,7 +21,7 @@ fn item_map(fixture: &str) -> (Arc<hir::ItemMap>, hir::ModuleId) {
21} 21}
22 22
23#[test] 23#[test]
24fn test_item_map() { 24fn item_map_smoke_test() {
25 let (item_map, module_id) = item_map( 25 let (item_map, module_id) = item_map(
26 " 26 "
27 //- /lib.rs 27 //- /lib.rs
@@ -43,6 +43,39 @@ fn test_item_map() {
43} 43}
44 44
45#[test] 45#[test]
46fn item_map_across_crates() {
47 let (mut db, files) = MockDatabase::with_files(
48 "
49 //- /main.rs
50 use test_crate::Baz;
51
52 //- /lib.rs
53 pub struct Baz;
54 ",
55 );
56 let main_id = files.file_id("/main.rs");
57 let lib_id = files.file_id("/lib.rs");
58
59 let mut crate_graph = CrateGraph::default();
60 let main_crate = crate_graph.add_crate_root(main_id);
61 let lib_crate = crate_graph.add_crate_root(lib_id);
62 crate_graph.add_dep(main_crate, "test_crate".into(), lib_crate);
63
64 db.set_crate_graph(crate_graph);
65
66 let source_root = db.file_source_root(main_id);
67 let module = hir::source_binder::module_from_file_id(&db, main_id)
68 .unwrap()
69 .unwrap();
70 let module_id = module.module_id;
71 let item_map = db.item_map(source_root).unwrap();
72
73 let name = SmolStr::from("Baz");
74 let resolution = &item_map.per_module[&module_id].items[&name];
75 assert!(resolution.def_id.is_some());
76}
77
78#[test]
46fn typing_inside_a_function_should_not_invalidate_item_map() { 79fn typing_inside_a_function_should_not_invalidate_item_map() {
47 let (mut db, pos) = MockDatabase::with_position( 80 let (mut db, pos) = MockDatabase::with_position(
48 " 81 "