diff options
author | Aleksey Kladov <[email protected]> | 2019-01-23 20:14:13 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-24 10:29:19 +0000 |
commit | 3ab1519cb27b927074ed7fbbb18a856e6e7fabb8 (patch) | |
tree | 692c7a256604e188d38890966290bd1637d7dd60 /crates/ra_hir/src/nameres/tests.rs | |
parent | cfb085ded8d61d7b744d0a83ecbb3da254f6ab9f (diff) |
Change ids strategy
this is a part of larghish hir refactoring which aims to
* replace per-source-root module trees with per crate trees
* switch from a monotyped DedId to type-specific ids
Diffstat (limited to 'crates/ra_hir/src/nameres/tests.rs')
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index e92007453..9322bf08c 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_db::{FilesDatabase, CrateGraph, SourceRootId, salsa::Database}; | 3 | use ra_db::{CrateGraph, SourceRootId, salsa::Database}; |
4 | use relative_path::RelativePath; | 4 | use relative_path::RelativePath; |
5 | use test_utils::{assert_eq_text, covers}; | 5 | use test_utils::{assert_eq_text, covers}; |
6 | 6 | ||
@@ -13,10 +13,10 @@ use crate::{ | |||
13 | 13 | ||
14 | fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) { | 14 | fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) { |
15 | let (db, pos) = MockDatabase::with_position(fixture); | 15 | let (db, pos) = MockDatabase::with_position(fixture); |
16 | let source_root = db.file_source_root(pos.file_id); | ||
17 | let module = crate::source_binder::module_from_position(&db, pos).unwrap(); | 16 | let module = crate::source_binder::module_from_position(&db, pos).unwrap(); |
18 | let module_id = module.def_id.loc(&db).module_id; | 17 | let krate = module.krate(&db).unwrap(); |
19 | (db.item_map(source_root), module_id) | 18 | let module_id = module.module_id; |
19 | (db.item_map(krate.crate_id), module_id) | ||
20 | } | 20 | } |
21 | 21 | ||
22 | fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { | 22 | fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { |
@@ -238,14 +238,13 @@ fn item_map_across_crates() { | |||
238 | 238 | ||
239 | db.set_crate_graph(crate_graph); | 239 | db.set_crate_graph(crate_graph); |
240 | 240 | ||
241 | let source_root = db.file_source_root(main_id); | ||
242 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); | 241 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
243 | let module_id = module.def_id.loc(&db).module_id; | 242 | let krate = module.krate(&db).unwrap(); |
244 | let item_map = db.item_map(source_root); | 243 | let item_map = db.item_map(krate.crate_id); |
245 | 244 | ||
246 | check_module_item_map( | 245 | check_module_item_map( |
247 | &item_map, | 246 | &item_map, |
248 | module_id, | 247 | module.module_id, |
249 | " | 248 | " |
250 | Baz: t v | 249 | Baz: t v |
251 | test_crate: t | 250 | test_crate: t |
@@ -292,12 +291,12 @@ fn import_across_source_roots() { | |||
292 | db.set_crate_graph(crate_graph); | 291 | db.set_crate_graph(crate_graph); |
293 | 292 | ||
294 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); | 293 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
295 | let module_id = module.def_id.loc(&db).module_id; | 294 | let krate = module.krate(&db).unwrap(); |
296 | let item_map = db.item_map(source_root); | 295 | let item_map = db.item_map(krate.crate_id); |
297 | 296 | ||
298 | check_module_item_map( | 297 | check_module_item_map( |
299 | &item_map, | 298 | &item_map, |
300 | module_id, | 299 | module.module_id, |
301 | " | 300 | " |
302 | C: t v | 301 | C: t v |
303 | test_crate: t | 302 | test_crate: t |
@@ -333,14 +332,13 @@ fn reexport_across_crates() { | |||
333 | 332 | ||
334 | db.set_crate_graph(crate_graph); | 333 | db.set_crate_graph(crate_graph); |
335 | 334 | ||
336 | let source_root = db.file_source_root(main_id); | ||
337 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); | 335 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
338 | let module_id = module.def_id.loc(&db).module_id; | 336 | let krate = module.krate(&db).unwrap(); |
339 | let item_map = db.item_map(source_root); | 337 | let item_map = db.item_map(krate.crate_id); |
340 | 338 | ||
341 | check_module_item_map( | 339 | check_module_item_map( |
342 | &item_map, | 340 | &item_map, |
343 | module_id, | 341 | module.module_id, |
344 | " | 342 | " |
345 | Baz: t v | 343 | Baz: t v |
346 | test_crate: t | 344 | test_crate: t |
@@ -350,10 +348,11 @@ fn reexport_across_crates() { | |||
350 | 348 | ||
351 | fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) { | 349 | fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) { |
352 | let (mut db, pos) = MockDatabase::with_position(initial); | 350 | let (mut db, pos) = MockDatabase::with_position(initial); |
353 | let source_root = db.file_source_root(pos.file_id); | 351 | let module = crate::source_binder::module_from_file_id(&db, pos.file_id).unwrap(); |
352 | let krate = module.krate(&db).unwrap(); | ||
354 | { | 353 | { |
355 | let events = db.log_executed(|| { | 354 | let events = db.log_executed(|| { |
356 | db.item_map(source_root); | 355 | db.item_map(krate.crate_id); |
357 | }); | 356 | }); |
358 | assert!(format!("{:?}", events).contains("item_map")) | 357 | assert!(format!("{:?}", events).contains("item_map")) |
359 | } | 358 | } |
@@ -362,7 +361,7 @@ fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) { | |||
362 | 361 | ||
363 | { | 362 | { |
364 | let events = db.log_executed(|| { | 363 | let events = db.log_executed(|| { |
365 | db.item_map(source_root); | 364 | db.item_map(krate.crate_id); |
366 | }); | 365 | }); |
367 | assert!( | 366 | assert!( |
368 | !format!("{:?}", events).contains("item_map"), | 367 | !format!("{:?}", events).contains("item_map"), |