diff options
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r-- | crates/ra_hir_ty/src/test_db.rs | 22 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 5 |
2 files changed, 18 insertions, 9 deletions
diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/ra_hir_ty/src/test_db.rs index 0481a7b12..fddf0604d 100644 --- a/crates/ra_hir_ty/src/test_db.rs +++ b/crates/ra_hir_ty/src/test_db.rs | |||
@@ -8,8 +8,10 @@ use std::{ | |||
8 | use hir_def::{db::DefDatabase, AssocItemId, ModuleDefId, ModuleId}; | 8 | use hir_def::{db::DefDatabase, AssocItemId, ModuleDefId, ModuleId}; |
9 | use hir_expand::{db::AstDatabase, diagnostics::DiagnosticSink}; | 9 | use hir_expand::{db::AstDatabase, diagnostics::DiagnosticSink}; |
10 | use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast}; | 10 | use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast}; |
11 | use rustc_hash::FxHashSet; | 11 | use ra_syntax::TextRange; |
12 | use rustc_hash::{FxHashMap, FxHashSet}; | ||
12 | use stdx::format_to; | 13 | use stdx::format_to; |
14 | use test_utils::extract_annotations; | ||
13 | 15 | ||
14 | use crate::{ | 16 | use crate::{ |
15 | db::HirDatabase, diagnostics::Diagnostic, expr::ExprValidator, | 17 | db::HirDatabase, diagnostics::Diagnostic, expr::ExprValidator, |
@@ -155,17 +157,27 @@ impl TestDB { | |||
155 | (buf, count) | 157 | (buf, count) |
156 | } | 158 | } |
157 | 159 | ||
158 | pub fn all_files(&self) -> Vec<FileId> { | 160 | pub fn extract_annotations(&self) -> FxHashMap<FileId, Vec<(TextRange, String)>> { |
159 | let mut res = Vec::new(); | 161 | let mut files = Vec::new(); |
160 | let crate_graph = self.crate_graph(); | 162 | let crate_graph = self.crate_graph(); |
161 | for krate in crate_graph.iter() { | 163 | for krate in crate_graph.iter() { |
162 | let crate_def_map = self.crate_def_map(krate); | 164 | let crate_def_map = self.crate_def_map(krate); |
163 | for (module_id, _) in crate_def_map.modules.iter() { | 165 | for (module_id, _) in crate_def_map.modules.iter() { |
164 | let file_id = crate_def_map[module_id].origin.file_id(); | 166 | let file_id = crate_def_map[module_id].origin.file_id(); |
165 | res.extend(file_id) | 167 | files.extend(file_id) |
166 | } | 168 | } |
167 | } | 169 | } |
168 | res | 170 | files |
171 | .into_iter() | ||
172 | .filter_map(|file_id| { | ||
173 | let text = self.file_text(file_id); | ||
174 | let annotations = extract_annotations(&text); | ||
175 | if annotations.is_empty() { | ||
176 | return None; | ||
177 | } | ||
178 | Some((file_id, annotations)) | ||
179 | }) | ||
180 | .collect() | ||
169 | } | 181 | } |
170 | } | 182 | } |
171 | 183 | ||
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 5424e6bb1..9084c3bed 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -28,7 +28,6 @@ use ra_syntax::{ | |||
28 | SyntaxNode, | 28 | SyntaxNode, |
29 | }; | 29 | }; |
30 | use stdx::format_to; | 30 | use stdx::format_to; |
31 | use test_utils::extract_annotations; | ||
32 | 31 | ||
33 | use crate::{ | 32 | use crate::{ |
34 | db::HirDatabase, display::HirDisplay, infer::TypeMismatch, test_db::TestDB, InferenceResult, Ty, | 33 | db::HirDatabase, display::HirDisplay, infer::TypeMismatch, test_db::TestDB, InferenceResult, Ty, |
@@ -49,9 +48,7 @@ fn check_types_source_code(ra_fixture: &str) { | |||
49 | fn check_types_impl(ra_fixture: &str, display_source: bool) { | 48 | fn check_types_impl(ra_fixture: &str, display_source: bool) { |
50 | let db = TestDB::with_files(ra_fixture); | 49 | let db = TestDB::with_files(ra_fixture); |
51 | let mut checked_one = false; | 50 | let mut checked_one = false; |
52 | for file_id in db.all_files() { | 51 | for (file_id, annotations) in db.extract_annotations() { |
53 | let text = db.parse(file_id).syntax_node().to_string(); | ||
54 | let annotations = extract_annotations(&text); | ||
55 | for (range, expected) in annotations { | 52 | for (range, expected) in annotations { |
56 | let ty = type_at_range(&db, FileRange { file_id, range }); | 53 | let ty = type_at_range(&db, FileRange { file_id, range }); |
57 | let actual = if display_source { | 54 | let actual = if display_source { |