diff options
author | Aleksey Kladov <[email protected]> | 2018-12-27 18:02:08 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-12-27 18:02:08 +0000 |
commit | 63f54d234f0d622d043dca8176f0715889a6ed48 (patch) | |
tree | f00675907234c81c0538c5a9178dad09e4169d63 /crates/ra_hir/src/module/nameres | |
parent | a9f55029b9db3bcd439d31c5007785299f7d4025 (diff) |
dont leak Name details in testing
Diffstat (limited to 'crates/ra_hir/src/module/nameres')
-rw-r--r-- | crates/ra_hir/src/module/nameres/tests.rs | 67 |
1 files changed, 55 insertions, 12 deletions
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; | |||
2 | 2 | ||
3 | use salsa::Database; | 3 | use salsa::Database; |
4 | use ra_db::{FilesDatabase, CrateGraph}; | 4 | use ra_db::{FilesDatabase, CrateGraph}; |
5 | use ra_syntax::SmolStr; | ||
6 | use relative_path::RelativePath; | 5 | use relative_path::RelativePath; |
6 | use test_utils::assert_eq_text; | ||
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | self as hir, | 9 | self as hir, |
10 | db::HirDatabase, | 10 | db::HirDatabase, |
11 | mock::MockDatabase, | 11 | mock::MockDatabase, |
12 | Name, | ||
13 | }; | 12 | }; |
14 | 13 | ||
15 | fn item_map(fixture: &str) -> (Arc<hir::ItemMap>, hir::ModuleId) { | 14 | fn item_map(fixture: &str) -> (Arc<hir::ItemMap>, hir::ModuleId) { |
@@ -22,6 +21,35 @@ fn item_map(fixture: &str) -> (Arc<hir::ItemMap>, hir::ModuleId) { | |||
22 | (db.item_map(source_root).unwrap(), module_id) | 21 | (db.item_map(source_root).unwrap(), module_id) |
23 | } | 22 | } |
24 | 23 | ||
24 | fn check_module_item_map(map: &hir::ItemMap, module_id: hir::ModuleId, expected: &str) { | ||
25 | let mut lines = map.per_module[&module_id] | ||
26 | .items | ||
27 | .iter() | ||
28 | .map(|(name, res)| format!("{}: {}", name, dump_resolution(res))) | ||
29 | .collect::<Vec<_>>(); | ||
30 | lines.sort(); | ||
31 | let actual = lines.join("\n"); | ||
32 | let expected = expected | ||
33 | .trim() | ||
34 | .lines() | ||
35 | .map(|it| it.trim()) | ||
36 | .collect::<Vec<_>>() | ||
37 | .join("\n"); | ||
38 | assert_eq_text!(&actual, &expected); | ||
39 | |||
40 | fn dump_resolution(resolution: &hir::Resolution) -> &'static str { | ||
41 | match ( | ||
42 | resolution.def_id.types.is_some(), | ||
43 | resolution.def_id.values.is_some(), | ||
44 | ) { | ||
45 | (true, true) => "t v", | ||
46 | (true, false) => "t", | ||
47 | (false, true) => "v", | ||
48 | (false, false) => "_", | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | |||
25 | #[test] | 53 | #[test] |
26 | fn item_map_smoke_test() { | 54 | fn item_map_smoke_test() { |
27 | let (item_map, module_id) = item_map( | 55 | let (item_map, module_id) = item_map( |
@@ -39,13 +67,18 @@ fn item_map_smoke_test() { | |||
39 | pub struct Baz; | 67 | pub struct Baz; |
40 | ", | 68 | ", |
41 | ); | 69 | ); |
42 | let name = Name::new(SmolStr::from("Baz")); | 70 | check_module_item_map( |
43 | let resolution = &item_map.per_module[&module_id].items[&name]; | 71 | &item_map, |
44 | assert!(resolution.def_id.take_types().is_some()); | 72 | module_id, |
73 | " | ||
74 | Baz: t v | ||
75 | foo: t | ||
76 | ", | ||
77 | ); | ||
45 | } | 78 | } |
46 | 79 | ||
47 | #[test] | 80 | #[test] |
48 | fn test_self() { | 81 | fn item_map_using_self() { |
49 | let (item_map, module_id) = item_map( | 82 | let (item_map, module_id) = item_map( |
50 | " | 83 | " |
51 | //- /lib.rs | 84 | //- /lib.rs |
@@ -58,9 +91,14 @@ fn test_self() { | |||
58 | pub struct Baz; | 91 | pub struct Baz; |
59 | ", | 92 | ", |
60 | ); | 93 | ); |
61 | let name = Name::new(SmolStr::from("Baz")); | 94 | check_module_item_map( |
62 | let resolution = &item_map.per_module[&module_id].items[&name]; | 95 | &item_map, |
63 | assert!(resolution.def_id.take_types().is_some()); | 96 | module_id, |
97 | " | ||
98 | Baz: t v | ||
99 | foo: t | ||
100 | ", | ||
101 | ); | ||
64 | } | 102 | } |
65 | 103 | ||
66 | #[test] | 104 | #[test] |
@@ -91,9 +129,14 @@ fn item_map_across_crates() { | |||
91 | let module_id = module.module_id; | 129 | let module_id = module.module_id; |
92 | let item_map = db.item_map(source_root).unwrap(); | 130 | let item_map = db.item_map(source_root).unwrap(); |
93 | 131 | ||
94 | let name = Name::new(SmolStr::from("Baz")); | 132 | check_module_item_map( |
95 | let resolution = &item_map.per_module[&module_id].items[&name]; | 133 | &item_map, |
96 | assert!(resolution.def_id.take_types().is_some()); | 134 | module_id, |
135 | " | ||
136 | Baz: t v | ||
137 | test_crate: t | ||
138 | ", | ||
139 | ); | ||
97 | } | 140 | } |
98 | 141 | ||
99 | #[test] | 142 | #[test] |