aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-05-27 19:21:52 +0100
committerJonas Schievink <[email protected]>2021-05-27 19:21:52 +0100
commit26b4777e1fce193e0842b7a1c9b85f08eb3ae2d7 (patch)
treef83bbb66c3ba55814acb36556a1812cb63b5db57 /crates/hir_ty/src/tests
parenta2940c42c0ab30e80e1a63494ca17fb2d81bdd1f (diff)
Move hir_ty incremental test to its own file
Diffstat (limited to 'crates/hir_ty/src/tests')
-rw-r--r--crates/hir_ty/src/tests/incremental.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/crates/hir_ty/src/tests/incremental.rs b/crates/hir_ty/src/tests/incremental.rs
new file mode 100644
index 000000000..3e08e83e8
--- /dev/null
+++ b/crates/hir_ty/src/tests/incremental.rs
@@ -0,0 +1,51 @@
1use std::sync::Arc;
2
3use base_db::{fixture::WithFixture, SourceDatabaseExt};
4
5use crate::{db::HirDatabase, test_db::TestDB};
6
7use super::visit_module;
8
9#[test]
10fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
11 let (mut db, pos) = TestDB::with_position(
12 "
13 //- /lib.rs
14 fn foo() -> i32 {
15 $01 + 1
16 }
17 ",
18 );
19 {
20 let events = db.log_executed(|| {
21 let module = db.module_for_file(pos.file_id);
22 let crate_def_map = module.def_map(&db);
23 visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
24 db.infer(def);
25 });
26 });
27 assert!(format!("{:?}", events).contains("infer"))
28 }
29
30 let new_text = "
31 fn foo() -> i32 {
32 1
33 +
34 1
35 }
36 "
37 .to_string();
38
39 db.set_file_text(pos.file_id, Arc::new(new_text));
40
41 {
42 let events = db.log_executed(|| {
43 let module = db.module_for_file(pos.file_id);
44 let crate_def_map = module.def_map(&db);
45 visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
46 db.infer(def);
47 });
48 });
49 assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
50 }
51}