aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres/tests/incremental.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/nameres/tests/incremental.rs')
-rw-r--r--crates/hir_def/src/nameres/tests/incremental.rs101
1 files changed, 101 insertions, 0 deletions
diff --git a/crates/hir_def/src/nameres/tests/incremental.rs b/crates/hir_def/src/nameres/tests/incremental.rs
new file mode 100644
index 000000000..cfbc62cc4
--- /dev/null
+++ b/crates/hir_def/src/nameres/tests/incremental.rs
@@ -0,0 +1,101 @@
1use std::sync::Arc;
2
3use base_db::SourceDatabaseExt;
4
5use super::*;
6
7fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change: &str) {
8 let (mut db, pos) = TestDB::with_position(ra_fixture_initial);
9 let krate = db.test_crate();
10 {
11 let events = db.log_executed(|| {
12 db.crate_def_map(krate);
13 });
14 assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
15 }
16 db.set_file_text(pos.file_id, Arc::new(ra_fixture_change.to_string()));
17
18 {
19 let events = db.log_executed(|| {
20 db.crate_def_map(krate);
21 });
22 assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
23 }
24}
25
26#[test]
27fn typing_inside_a_function_should_not_invalidate_def_map() {
28 check_def_map_is_not_recomputed(
29 r"
30 //- /lib.rs
31 mod foo;<|>
32
33 use crate::foo::bar::Baz;
34
35 enum E { A, B }
36 use E::*;
37
38 fn foo() -> i32 {
39 1 + 1
40 }
41 //- /foo/mod.rs
42 pub mod bar;
43
44 //- /foo/bar.rs
45 pub struct Baz;
46 ",
47 r"
48 mod foo;
49
50 use crate::foo::bar::Baz;
51
52 enum E { A, B }
53 use E::*;
54
55 fn foo() -> i32 { 92 }
56 ",
57 );
58}
59
60#[test]
61fn typing_inside_a_macro_should_not_invalidate_def_map() {
62 let (mut db, pos) = TestDB::with_position(
63 r"
64 //- /lib.rs
65 macro_rules! m {
66 ($ident:ident) => {
67 fn f() {
68 $ident + $ident;
69 };
70 }
71 }
72 mod foo;
73
74 //- /foo/mod.rs
75 pub mod bar;
76
77 //- /foo/bar.rs
78 <|>
79 m!(X);
80 ",
81 );
82 let krate = db.test_crate();
83 {
84 let events = db.log_executed(|| {
85 let crate_def_map = db.crate_def_map(krate);
86 let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
87 assert_eq!(module_data.scope.resolutions().count(), 1);
88 });
89 assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
90 }
91 db.set_file_text(pos.file_id, Arc::new("m!(Y);".to_string()));
92
93 {
94 let events = db.log_executed(|| {
95 let crate_def_map = db.crate_def_map(krate);
96 let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
97 assert_eq!(module_data.scope.resolutions().count(), 1);
98 });
99 assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
100 }
101}