From 63f54d234f0d622d043dca8176f0715889a6ed48 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 27 Dec 2018 21:02:08 +0300 Subject: dont leak Name details in testing --- crates/ra_hir/src/module/nameres/tests.rs | 67 +++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 12 deletions(-) (limited to 'crates/ra_hir/src/module/nameres/tests.rs') diff --git a/crates/ra_hir/src/module/nameres/tests.rs b/crates/ra_hir/src/module/nameres/tests.rs index 165ac81c8..ca20f064f 100644 --- a/crates/ra_hir/src/module/nameres/tests.rs +++ b/crates/ra_hir/src/module/nameres/tests.rs @@ -2,14 +2,13 @@ use std::sync::Arc; use salsa::Database; use ra_db::{FilesDatabase, CrateGraph}; -use ra_syntax::SmolStr; use relative_path::RelativePath; +use test_utils::assert_eq_text; use crate::{ self as hir, db::HirDatabase, mock::MockDatabase, - Name, }; fn item_map(fixture: &str) -> (Arc, hir::ModuleId) { @@ -22,6 +21,35 @@ fn item_map(fixture: &str) -> (Arc, hir::ModuleId) { (db.item_map(source_root).unwrap(), module_id) } +fn check_module_item_map(map: &hir::ItemMap, module_id: hir::ModuleId, expected: &str) { + let mut lines = map.per_module[&module_id] + .items + .iter() + .map(|(name, res)| format!("{}: {}", name, dump_resolution(res))) + .collect::>(); + lines.sort(); + let actual = lines.join("\n"); + let expected = expected + .trim() + .lines() + .map(|it| it.trim()) + .collect::>() + .join("\n"); + assert_eq_text!(&actual, &expected); + + fn dump_resolution(resolution: &hir::Resolution) -> &'static str { + match ( + resolution.def_id.types.is_some(), + resolution.def_id.values.is_some(), + ) { + (true, true) => "t v", + (true, false) => "t", + (false, true) => "v", + (false, false) => "_", + } + } +} + #[test] fn item_map_smoke_test() { let (item_map, module_id) = item_map( @@ -39,13 +67,18 @@ fn item_map_smoke_test() { pub struct Baz; ", ); - let name = Name::new(SmolStr::from("Baz")); - let resolution = &item_map.per_module[&module_id].items[&name]; - assert!(resolution.def_id.take_types().is_some()); + check_module_item_map( + &item_map, + module_id, + " + Baz: t v + foo: t + ", + ); } #[test] -fn test_self() { +fn item_map_using_self() { let (item_map, module_id) = item_map( " //- /lib.rs @@ -58,9 +91,14 @@ fn test_self() { pub struct Baz; ", ); - let name = Name::new(SmolStr::from("Baz")); - let resolution = &item_map.per_module[&module_id].items[&name]; - assert!(resolution.def_id.take_types().is_some()); + check_module_item_map( + &item_map, + module_id, + " + Baz: t v + foo: t + ", + ); } #[test] @@ -91,9 +129,14 @@ fn item_map_across_crates() { let module_id = module.module_id; let item_map = db.item_map(source_root).unwrap(); - let name = Name::new(SmolStr::from("Baz")); - let resolution = &item_map.per_module[&module_id].items[&name]; - assert!(resolution.def_id.take_types().is_some()); + check_module_item_map( + &item_map, + module_id, + " + Baz: t v + test_crate: t + ", + ); } #[test] -- cgit v1.2.3