aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/tests.rs39
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 @@
1use std::fmt::Write; 1use std::fmt::Write;
2use std::sync::Arc; 2use std::path::{PathBuf};
3use std::path::{Path, PathBuf};
4 3
5use salsa::Database; 4use ra_db::{SyntaxDatabase};
6use ra_db::{FilesDatabase, CrateGraph, SyntaxDatabase}; 5use ra_syntax::ast::{self, AstNode};
7use ra_syntax::{SmolStr, algo::visit::{visitor, Visitor}, ast::{self, AstNode}};
8use test_utils::{project_dir, dir_tests}; 6use test_utils::{project_dir, dir_tests};
9use relative_path::RelativePath;
10
11use crate::{source_binder, mock::WORKSPACE, module::ModuleSourceNode};
12 7
13use crate::{ 8use crate::{
14 self as hir, 9 source_binder,
15 db::HirDatabase,
16 mock::MockDatabase, 10 mock::MockDatabase,
17}; 11};
18 12
19fn infer_file(content: &str) -> String { 13fn 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]
53pub fn infer_tests() { 60pub 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
59fn test_data_dir() -> PathBuf { 64fn test_data_dir() -> PathBuf {