diff options
author | Florian Diebold <[email protected]> | 2019-01-05 12:42:47 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-01-05 21:41:12 +0000 |
commit | a6f33b4ca5e70a056c60b24cb8cb3283d8209624 (patch) | |
tree | f92f6f5b9431c4047163cbec6db23c57447d8aa8 /crates/ra_hir/src/ty | |
parent | 3e42a158787955ff9f2e81be43479dbe8f2b1bb6 (diff) |
Add test for invalidation of inferred types when typing inside function
This currently fails, but should work once we have hir::Expr.
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 44 |
1 files changed, 44 insertions, 0 deletions
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 @@ | |||
1 | use std::sync::Arc; | ||
1 | use std::fmt::Write; | 2 | use std::fmt::Write; |
2 | use std::path::{PathBuf, Path}; | 3 | use std::path::{PathBuf, Path}; |
3 | use std::fs; | 4 | use std::fs; |
4 | 5 | ||
6 | use salsa::Database; | ||
7 | |||
5 | use ra_db::{SyntaxDatabase}; | 8 | use ra_db::{SyntaxDatabase}; |
6 | use ra_syntax::ast::{self, AstNode}; | 9 | use ra_syntax::ast::{self, AstNode}; |
7 | use test_utils::{project_dir, assert_eq_text, read_text}; | 10 | use test_utils::{project_dir, assert_eq_text, read_text}; |
@@ -217,3 +220,44 @@ fn ellipsize(mut text: String, max_len: usize) -> String { | |||
217 | fn test_data_dir() -> PathBuf { | 220 | fn test_data_dir() -> PathBuf { |
218 | project_dir().join("crates/ra_hir/src/ty/tests/data") | 221 | project_dir().join("crates/ra_hir/src/ty/tests/data") |
219 | } | 222 | } |
223 | |||
224 | #[test] | ||
225 | #[should_panic] // TODO this should work once hir::Expr is used | ||
226 | fn typing_whitespace_inside_a_function_should_not_invalidate_types() { | ||
227 | let (mut db, pos) = MockDatabase::with_position( | ||
228 | " | ||
229 | //- /lib.rs | ||
230 | fn foo() -> i32 { | ||
231 | <|>1 + 1 | ||
232 | } | ||
233 | ", | ||
234 | ); | ||
235 | let func = source_binder::function_from_position(&db, pos) | ||
236 | .unwrap() | ||
237 | .unwrap(); | ||
238 | { | ||
239 | let events = db.log_executed(|| { | ||
240 | func.infer(&db).unwrap(); | ||
241 | }); | ||
242 | assert!(format!("{:?}", events).contains("infer")) | ||
243 | } | ||
244 | |||
245 | let new_text = " | ||
246 | fn foo() -> i32 { | ||
247 | 1 | ||
248 | + | ||
249 | 1 | ||
250 | } | ||
251 | " | ||
252 | .to_string(); | ||
253 | |||
254 | db.query_mut(ra_db::FileTextQuery) | ||
255 | .set(pos.file_id, Arc::new(new_text)); | ||
256 | |||
257 | { | ||
258 | let events = db.log_executed(|| { | ||
259 | func.infer(&db).unwrap(); | ||
260 | }); | ||
261 | assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events) | ||
262 | } | ||
263 | } | ||