diff options
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 98eedaa3f..0880b51bc 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -1,31 +1,38 @@ | |||
1 | use std::fmt::Write; | 1 | use std::fmt::Write; |
2 | use std::sync::Arc; | 2 | use std::path::{PathBuf}; |
3 | use std::path::{Path, PathBuf}; | ||
4 | 3 | ||
5 | use salsa::Database; | 4 | use ra_db::{SyntaxDatabase}; |
6 | use ra_db::{FilesDatabase, CrateGraph, SyntaxDatabase}; | 5 | use ra_syntax::ast::{self, AstNode}; |
7 | use ra_syntax::{SmolStr, algo::visit::{visitor, Visitor}, ast::{self, AstNode}}; | ||
8 | use test_utils::{project_dir, dir_tests}; | 6 | use test_utils::{project_dir, dir_tests}; |
9 | use relative_path::RelativePath; | ||
10 | |||
11 | use crate::{source_binder, mock::WORKSPACE, module::ModuleSourceNode}; | ||
12 | 7 | ||
13 | use crate::{ | 8 | use crate::{ |
14 | self as hir, | 9 | source_binder, |
15 | db::HirDatabase, | ||
16 | mock::MockDatabase, | 10 | mock::MockDatabase, |
17 | }; | 11 | }; |
18 | 12 | ||
19 | fn infer_file(content: &str) -> String { | 13 | fn infer_file(content: &str) -> String { |
20 | let (db, source_root, file_id) = MockDatabase::with_single_file(content); | 14 | let (db, _, file_id) = MockDatabase::with_single_file(content); |
21 | let source_file = db.source_file(file_id); | 15 | let source_file = db.source_file(file_id); |
22 | let mut acc = String::new(); | 16 | let mut acc = String::new(); |
23 | for fn_def in source_file.syntax().descendants().filter_map(ast::FnDef::cast) { | 17 | for fn_def in source_file |
24 | let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap().unwrap(); | 18 | .syntax() |
19 | .descendants() | ||
20 | .filter_map(ast::FnDef::cast) | ||
21 | { | ||
22 | let func = source_binder::function_from_source(&db, file_id, fn_def) | ||
23 | .unwrap() | ||
24 | .unwrap(); | ||
25 | let inference_result = func.infer(&db); | 25 | let inference_result = func.infer(&db); |
26 | for (syntax_ptr, ty) in &inference_result.type_for { | 26 | for (syntax_ptr, ty) in &inference_result.type_for { |
27 | let node = syntax_ptr.resolve(&source_file); | 27 | let node = syntax_ptr.resolve(&source_file); |
28 | write!(acc, "{} '{}': {}\n", syntax_ptr.range(), ellipsize(node.text().to_string().replace("\n", " "), 15), ty); | 28 | write!( |
29 | acc, | ||
30 | "{} '{}': {}\n", | ||
31 | syntax_ptr.range(), | ||
32 | ellipsize(node.text().to_string().replace("\n", " "), 15), | ||
33 | ty | ||
34 | ) | ||
35 | .unwrap(); | ||
29 | } | 36 | } |
30 | } | 37 | } |
31 | acc | 38 | acc |
@@ -51,9 +58,7 @@ fn ellipsize(mut text: String, max_len: usize) -> String { | |||
51 | 58 | ||
52 | #[test] | 59 | #[test] |
53 | pub fn infer_tests() { | 60 | pub fn infer_tests() { |
54 | dir_tests(&test_data_dir(), &["."], |text, _path| { | 61 | dir_tests(&test_data_dir(), &["."], |text, _path| infer_file(text)); |
55 | infer_file(text) | ||
56 | }); | ||
57 | } | 62 | } |
58 | 63 | ||
59 | fn test_data_dir() -> PathBuf { | 64 | fn test_data_dir() -> PathBuf { |