diff options
Diffstat (limited to 'crates/libanalysis/src/module_map_db.rs')
-rw-r--r-- | crates/libanalysis/src/module_map_db.rs | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/crates/libanalysis/src/module_map_db.rs b/crates/libanalysis/src/module_map_db.rs index 1ef87ab3f..25dbe8dd4 100644 --- a/crates/libanalysis/src/module_map_db.rs +++ b/crates/libanalysis/src/module_map_db.rs | |||
@@ -94,14 +94,15 @@ mod descr { | |||
94 | 94 | ||
95 | #[cfg(test)] | 95 | #[cfg(test)] |
96 | mod tests { | 96 | mod tests { |
97 | use super::*; | 97 | use std::collections::HashMap; |
98 | use im; | 98 | use im; |
99 | use relative_path::{RelativePath, RelativePathBuf}; | 99 | use relative_path::{RelativePath, RelativePathBuf}; |
100 | use { | 100 | use { |
101 | db::Db, | 101 | db::{Query, Db, TraceEventKind}, |
102 | imp::FileResolverImp, | 102 | imp::FileResolverImp, |
103 | FileId, FileResolver, | 103 | FileId, FileResolver, |
104 | }; | 104 | }; |
105 | use super::*; | ||
105 | 106 | ||
106 | #[derive(Debug)] | 107 | #[derive(Debug)] |
107 | struct FileMap(im::HashMap<FileId, RelativePathBuf>); | 108 | struct FileMap(im::HashMap<FileId, RelativePathBuf>); |
@@ -154,10 +155,29 @@ mod tests { | |||
154 | fn change_file(&mut self, file_id: FileId, new_text: &str) { | 155 | fn change_file(&mut self, file_id: FileId, new_text: &str) { |
155 | self.db.change_file(file_id, Some(new_text.to_string())); | 156 | self.db.change_file(file_id, Some(new_text.to_string())); |
156 | } | 157 | } |
157 | fn check_parent_modules(&self, file_id: FileId, expected: &[FileId]) { | 158 | fn check_parent_modules( |
159 | &self, | ||
160 | file_id: FileId, | ||
161 | expected: &[FileId], | ||
162 | queries: &[(u32, u64)] | ||
163 | ) { | ||
158 | let ctx = self.db.query_ctx(); | 164 | let ctx = self.db.query_ctx(); |
159 | let actual = ctx.get::<ParentModule>(&file_id); | 165 | let actual = ctx.get::<ParentModule>(&file_id); |
160 | assert_eq!(actual.as_slice(), expected); | 166 | assert_eq!(actual.as_slice(), expected); |
167 | let mut counts = HashMap::new(); | ||
168 | ctx.trace.borrow().iter() | ||
169 | .filter(|event| event.kind == TraceEventKind::Start) | ||
170 | .for_each(|event| *counts.entry(event.query_id).or_insert(0) += 1); | ||
171 | for &(query_id, expected_count) in queries.iter() { | ||
172 | let actual_count = *counts.get(&query_id).unwrap_or(&0); | ||
173 | assert_eq!( | ||
174 | actual_count, | ||
175 | expected_count, | ||
176 | "counts for {} differ", | ||
177 | query_id, | ||
178 | ) | ||
179 | } | ||
180 | |||
161 | } | 181 | } |
162 | } | 182 | } |
163 | 183 | ||
@@ -165,25 +185,25 @@ mod tests { | |||
165 | fn test_parent_module() { | 185 | fn test_parent_module() { |
166 | let mut f = Fixture::new(); | 186 | let mut f = Fixture::new(); |
167 | let foo = f.add_file("/foo.rs", ""); | 187 | let foo = f.add_file("/foo.rs", ""); |
168 | f.check_parent_modules(foo, &[]); | 188 | f.check_parent_modules(foo, &[], &[(FileSyntax::ID, 1)]); |
169 | 189 | ||
170 | let lib = f.add_file("/lib.rs", "mod foo;"); | 190 | let lib = f.add_file("/lib.rs", "mod foo;"); |
171 | f.check_parent_modules(foo, &[lib]); | 191 | f.check_parent_modules(foo, &[lib], &[(FileSyntax::ID, 2)]); |
172 | 192 | ||
173 | f.change_file(lib, ""); | 193 | f.change_file(lib, ""); |
174 | f.check_parent_modules(foo, &[]); | 194 | f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 2)]); |
175 | 195 | ||
176 | f.change_file(lib, "mod foo;"); | 196 | f.change_file(lib, "mod foo;"); |
177 | f.check_parent_modules(foo, &[lib]); | 197 | f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 2)]); |
178 | 198 | ||
179 | f.change_file(lib, "mod bar;"); | 199 | f.change_file(lib, "mod bar;"); |
180 | f.check_parent_modules(foo, &[]); | 200 | f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 2)]); |
181 | 201 | ||
182 | f.change_file(lib, "mod foo;"); | 202 | f.change_file(lib, "mod foo;"); |
183 | f.check_parent_modules(foo, &[lib]); | 203 | f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 2)]); |
184 | 204 | ||
185 | f.remove_file(lib); | 205 | f.remove_file(lib); |
186 | f.check_parent_modules(foo, &[]); | 206 | f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 1)]); |
187 | } | 207 | } |
188 | 208 | ||
189 | } | 209 | } |