diff options
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-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 | } | ||