From a6f33b4ca5e70a056c60b24cb8cb3283d8209624 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 5 Jan 2019 13:42:47 +0100 Subject: Add test for invalidation of inferred types when typing inside function This currently fails, but should work once we have hir::Expr. --- crates/ra_hir/src/ty/tests.rs | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'crates/ra_hir/src/ty/tests.rs') diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index fb53fcf0b..515c66e85 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -1,7 +1,10 @@ +use std::sync::Arc; use std::fmt::Write; use std::path::{PathBuf, Path}; use std::fs; +use salsa::Database; + use ra_db::{SyntaxDatabase}; use ra_syntax::ast::{self, AstNode}; use test_utils::{project_dir, assert_eq_text, read_text}; @@ -217,3 +220,44 @@ fn ellipsize(mut text: String, max_len: usize) -> String { fn test_data_dir() -> PathBuf { project_dir().join("crates/ra_hir/src/ty/tests/data") } + +#[test] +#[should_panic] // TODO this should work once hir::Expr is used +fn typing_whitespace_inside_a_function_should_not_invalidate_types() { + let (mut db, pos) = MockDatabase::with_position( + " + //- /lib.rs + fn foo() -> i32 { + <|>1 + 1 + } + ", + ); + let func = source_binder::function_from_position(&db, pos) + .unwrap() + .unwrap(); + { + let events = db.log_executed(|| { + func.infer(&db).unwrap(); + }); + assert!(format!("{:?}", events).contains("infer")) + } + + let new_text = " + fn foo() -> i32 { + 1 + + + 1 + } + " + .to_string(); + + db.query_mut(ra_db::FileTextQuery) + .set(pos.file_id, Arc::new(new_text)); + + { + let events = db.log_executed(|| { + func.infer(&db).unwrap(); + }); + assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events) + } +} -- cgit v1.2.3