Skip to content

Commit 361b399

Browse files
author
Jonas Schievink
committed
Fix tests
1 parent 31f5b48 commit 361b399

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

crates/ra_hir_def/src/import_map.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ pub fn search_dependencies<'a>(
327327
#[cfg(test)]
328328
mod tests {
329329
use super::*;
330-
use crate::test_db::TestDB;
330+
use crate::{test_db::TestDB, AssocContainerId, Lookup};
331331
use insta::assert_snapshot;
332332
use itertools::Itertools;
333333
use ra_db::fixture::WithFixture;
@@ -370,6 +370,7 @@ mod tests {
370370
ItemInNs::Values(_) => "v",
371371
ItemInNs::Macros(_) => "m",
372372
};
373+
let item = assoc_to_trait(&db, item);
373374
item.krate(db.upcast()).map(|krate| {
374375
let map = db.import_map(krate);
375376
let path = map.path_of(item).unwrap();
@@ -384,6 +385,29 @@ mod tests {
384385
.join("\n")
385386
}
386387

388+
fn assoc_to_trait(db: &dyn DefDatabase, item: ItemInNs) -> ItemInNs {
389+
let assoc: AssocItemId = match item {
390+
ItemInNs::Types(it) | ItemInNs::Values(it) => match it {
391+
ModuleDefId::TypeAliasId(it) => it.into(),
392+
ModuleDefId::FunctionId(it) => it.into(),
393+
ModuleDefId::ConstId(it) => it.into(),
394+
_ => return item,
395+
},
396+
_ => return item,
397+
};
398+
399+
let container = match assoc {
400+
AssocItemId::FunctionId(it) => it.lookup(db).container,
401+
AssocItemId::ConstId(it) => it.lookup(db).container,
402+
AssocItemId::TypeAliasId(it) => it.lookup(db).container,
403+
};
404+
405+
match container {
406+
AssocContainerId::TraitId(it) => ItemInNs::Types(it.into()),
407+
_ => item,
408+
}
409+
}
410+
387411
#[test]
388412
fn smoke() {
389413
let map = import_map(
@@ -641,6 +665,7 @@ mod tests {
641665
dep::Fmt (m)
642666
dep::fmt::Display (t)
643667
dep::format (v)
668+
dep::fmt::Display (t)
644669
"###);
645670

646671
let res = search_dependencies_of(ra_fixture, "main", Query::new("fmt").anchor_end());
@@ -649,6 +674,7 @@ mod tests {
649674
dep::Fmt (t)
650675
dep::Fmt (v)
651676
dep::Fmt (m)
677+
dep::fmt::Display (t)
652678
"###);
653679
}
654680

0 commit comments

Comments
 (0)