diff options
author | Aleksey Kladov <[email protected]> | 2018-12-09 10:49:54 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-12-09 10:49:54 +0000 |
commit | 7784c7a701ba944decf671f80dea581d68667663 (patch) | |
tree | 548400065966f715ae203e6f6e0fcfd9f12e4470 /crates/ra_hir/src/module/nameres/tests.rs | |
parent | e89da32bb7cf7388946964e1e34df722527d0838 (diff) |
resolve extern crates propertly
Diffstat (limited to 'crates/ra_hir/src/module/nameres/tests.rs')
-rw-r--r-- | crates/ra_hir/src/module/nameres/tests.rs | 37 |
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 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use salsa::Database; | 3 | use salsa::Database; |
4 | use ra_db::FilesDatabase; | 4 | use ra_db::{FilesDatabase, CrateGraph}; |
5 | use ra_syntax::SmolStr; | 5 | use ra_syntax::SmolStr; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
@@ -21,7 +21,7 @@ fn item_map(fixture: &str) -> (Arc<hir::ItemMap>, hir::ModuleId) { | |||
21 | } | 21 | } |
22 | 22 | ||
23 | #[test] | 23 | #[test] |
24 | fn test_item_map() { | 24 | fn 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] |
46 | fn 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] | ||
46 | fn typing_inside_a_function_should_not_invalidate_item_map() { | 79 | fn 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 | " |