aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/tests.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-04-12 23:32:43 +0100
committerAleksey Kladov <[email protected]>2019-04-12 23:32:43 +0100
commit58fe5598e70eef6edf109865cb87b806b22536fb (patch)
tree786feda8eb12fa0fd24f0ed073b588122b827fcb /crates/ra_hir/src/ty/tests.rs
parentb0d8f9ff5d2a64f93189543385485c5b48fb8d76 (diff)
simplify
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r--crates/ra_hir/src/ty/tests.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 87d6bcaec..d7c2ca132 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -8,7 +8,6 @@ use ra_syntax::{algo, ast::{self, AstNode}, SyntaxKind::*};
8use test_utils::covers; 8use test_utils::covers;
9 9
10use crate::{ 10use crate::{
11 source_binder,
12 mock::MockDatabase, 11 mock::MockDatabase,
13 ty::display::HirDisplay, 12 ty::display::HirDisplay,
14 ty::InferenceResult, 13 ty::InferenceResult,
@@ -2303,13 +2302,10 @@ fn test() -> u64 {
2303} 2302}
2304 2303
2305fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { 2304fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
2306 let func = source_binder::function_from_position(db, pos).unwrap(); 2305 let file = db.parse(pos.file_id);
2307 let body_source_map = func.body_source_map(db); 2306 let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap();
2308 let inference_result = func.infer(db); 2307 let analyzer = SourceAnalyzer::new(db, pos.file_id, expr.syntax(), Some(pos.offset));
2309 let (_, syntax) = func.source(db); 2308 let ty = analyzer.type_of(db, expr).unwrap();
2310 let node = algo::find_node_at_offset::<ast::Expr>(syntax.syntax(), pos.offset).unwrap();
2311 let expr = body_source_map.node_expr(node).unwrap();
2312 let ty = &inference_result[expr];
2313 ty.display(db).to_string() 2309 ty.display(db).to_string()
2314} 2310}
2315 2311
@@ -2390,10 +2386,12 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
2390 } 2386 }
2391 ", 2387 ",
2392 ); 2388 );
2393 let func = source_binder::function_from_position(&db, pos).unwrap();
2394 { 2389 {
2390 let file = db.parse(pos.file_id);
2391 let node =
2392 algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent();
2395 let events = db.log_executed(|| { 2393 let events = db.log_executed(|| {
2396 func.infer(&db); 2394 SourceAnalyzer::new(&db, pos.file_id, node, None);
2397 }); 2395 });
2398 assert!(format!("{:?}", events).contains("infer")) 2396 assert!(format!("{:?}", events).contains("infer"))
2399 } 2397 }
@@ -2410,8 +2408,11 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
2410 db.query_mut(ra_db::FileTextQuery).set(pos.file_id, Arc::new(new_text)); 2408 db.query_mut(ra_db::FileTextQuery).set(pos.file_id, Arc::new(new_text));
2411 2409
2412 { 2410 {
2411 let file = db.parse(pos.file_id);
2412 let node =
2413 algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent();
2413 let events = db.log_executed(|| { 2414 let events = db.log_executed(|| {
2414 func.infer(&db); 2415 SourceAnalyzer::new(&db, pos.file_id, node, None);
2415 }); 2416 });
2416 assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events) 2417 assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
2417 } 2418 }