diff options
author | Florian Diebold <[email protected]> | 2019-01-08 13:40:41 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-01-08 14:16:24 +0000 |
commit | 946b0ba02c2ab126b1b1d29027e60f21915d631e (patch) | |
tree | c1f4896435ecfa48470e08787a24a5e3b73cc4fb /crates/ra_hir/src/nameres/tests.rs | |
parent | d4b44a092f1fd5267a02719667d8d5e22ba0d904 (diff) |
Fix name resolution across source roots
It was using the wrong name in that case.
Diffstat (limited to 'crates/ra_hir/src/nameres/tests.rs')
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 97 |
1 files changed, 96 insertions, 1 deletions
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 4e3659ad0..c511c40b2 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/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, CrateGraph}; | 4 | use ra_db::{FilesDatabase, CrateGraph, SourceRootId}; |
5 | use relative_path::RelativePath; | 5 | use relative_path::RelativePath; |
6 | use test_utils::assert_eq_text; | 6 | use test_utils::assert_eq_text; |
7 | 7 | ||
@@ -228,6 +228,101 @@ fn item_map_across_crates() { | |||
228 | } | 228 | } |
229 | 229 | ||
230 | #[test] | 230 | #[test] |
231 | fn import_across_source_roots() { | ||
232 | let (mut db, sr) = MockDatabase::with_files( | ||
233 | " | ||
234 | //- /lib.rs | ||
235 | pub mod a { | ||
236 | pub mod b { | ||
237 | pub struct C; | ||
238 | } | ||
239 | } | ||
240 | ", | ||
241 | ); | ||
242 | let lib_id = sr.files[RelativePath::new("/lib.rs")]; | ||
243 | |||
244 | let source_root = SourceRootId(1); | ||
245 | |||
246 | let (sr2, pos) = db.add_fixture( | ||
247 | source_root, | ||
248 | " | ||
249 | //- /main.rs | ||
250 | use test_crate::a::b::C; | ||
251 | ", | ||
252 | ); | ||
253 | assert!(pos.is_none()); | ||
254 | |||
255 | let main_id = sr2.files[RelativePath::new("/main.rs")]; | ||
256 | |||
257 | eprintln!("lib = {:?}, main = {:?}", lib_id, main_id); | ||
258 | |||
259 | let mut crate_graph = CrateGraph::default(); | ||
260 | let main_crate = crate_graph.add_crate_root(main_id); | ||
261 | let lib_crate = crate_graph.add_crate_root(lib_id); | ||
262 | crate_graph.add_dep(main_crate, "test_crate".into(), lib_crate); | ||
263 | |||
264 | db.set_crate_graph(crate_graph); | ||
265 | |||
266 | let module = crate::source_binder::module_from_file_id(&db, main_id) | ||
267 | .unwrap() | ||
268 | .unwrap(); | ||
269 | let module_id = module.def_id.loc(&db).module_id; | ||
270 | let item_map = db.item_map(source_root).unwrap(); | ||
271 | |||
272 | check_module_item_map( | ||
273 | &item_map, | ||
274 | module_id, | ||
275 | " | ||
276 | C: t v | ||
277 | test_crate: t | ||
278 | ", | ||
279 | ); | ||
280 | } | ||
281 | |||
282 | #[test] | ||
283 | fn reexport_across_crates() { | ||
284 | let (mut db, sr) = MockDatabase::with_files( | ||
285 | " | ||
286 | //- /main.rs | ||
287 | use test_crate::Baz; | ||
288 | |||
289 | //- /lib.rs | ||
290 | pub use foo::Baz; | ||
291 | |||
292 | mod foo; | ||
293 | |||
294 | //- /foo.rs | ||
295 | pub struct Baz; | ||
296 | ", | ||
297 | ); | ||
298 | let main_id = sr.files[RelativePath::new("/main.rs")]; | ||
299 | let lib_id = sr.files[RelativePath::new("/lib.rs")]; | ||
300 | |||
301 | let mut crate_graph = CrateGraph::default(); | ||
302 | let main_crate = crate_graph.add_crate_root(main_id); | ||
303 | let lib_crate = crate_graph.add_crate_root(lib_id); | ||
304 | crate_graph.add_dep(main_crate, "test_crate".into(), lib_crate); | ||
305 | |||
306 | db.set_crate_graph(crate_graph); | ||
307 | |||
308 | let source_root = db.file_source_root(main_id); | ||
309 | let module = crate::source_binder::module_from_file_id(&db, main_id) | ||
310 | .unwrap() | ||
311 | .unwrap(); | ||
312 | let module_id = module.def_id.loc(&db).module_id; | ||
313 | let item_map = db.item_map(source_root).unwrap(); | ||
314 | |||
315 | check_module_item_map( | ||
316 | &item_map, | ||
317 | module_id, | ||
318 | " | ||
319 | Baz: t v | ||
320 | test_crate: t | ||
321 | ", | ||
322 | ); | ||
323 | } | ||
324 | |||
325 | #[test] | ||
231 | fn typing_inside_a_function_should_not_invalidate_item_map() { | 326 | fn typing_inside_a_function_should_not_invalidate_item_map() { |
232 | let (mut db, pos) = MockDatabase::with_position( | 327 | let (mut db, pos) = MockDatabase::with_position( |
233 | " | 328 | " |