diff options
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 1650606b7..25a354947 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}; |
@@ -241,3 +244,44 @@ fn ellipsize(mut text: String, max_len: usize) -> String { | |||
241 | fn test_data_dir() -> PathBuf { | 244 | fn test_data_dir() -> PathBuf { |
242 | project_dir().join("crates/ra_hir/src/ty/tests/data") | 245 | project_dir().join("crates/ra_hir/src/ty/tests/data") |
243 | } | 246 | } |
247 | |||
248 | #[test] | ||
249 | #[should_panic] // TODO this should work once hir::Expr is used | ||
250 | fn typing_whitespace_inside_a_function_should_not_invalidate_types() { | ||
251 | let (mut db, pos) = MockDatabase::with_position( | ||
252 | " | ||
253 | //- /lib.rs | ||
254 | fn foo() -> i32 { | ||
255 | <|>1 + 1 | ||
256 | } | ||
257 | ", | ||
258 | ); | ||
259 | let func = source_binder::function_from_position(&db, pos) | ||
260 | .unwrap() | ||
261 | .unwrap(); | ||
262 | { | ||
263 | let events = db.log_executed(|| { | ||
264 | func.infer(&db).unwrap(); | ||
265 | }); | ||
266 | assert!(format!("{:?}", events).contains("infer")) | ||
267 | } | ||
268 | |||
269 | let new_text = " | ||
270 | fn foo() -> i32 { | ||
271 | 1 | ||
272 | + | ||
273 | 1 | ||
274 | } | ||
275 | " | ||
276 | .to_string(); | ||
277 | |||
278 | db.query_mut(ra_db::FileTextQuery) | ||
279 | .set(pos.file_id, Arc::new(new_text)); | ||
280 | |||
281 | { | ||
282 | let events = db.log_executed(|| { | ||
283 | func.infer(&db).unwrap(); | ||
284 | }); | ||
285 | assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events) | ||
286 | } | ||
287 | } | ||