aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-05-04 13:31:23 +0100
committerJonas Schievink <[email protected]>2021-05-06 19:00:11 +0100
commit548e5a5c29bb0b453ef170e65d45a6673d8443f1 (patch)
tree0dc2fbd8c95c54eabbb3b8e872cdcbc5874ba65f /crates/hir_def
parent976a3226fe0f145dfefd473e9fecd63d58aca50e (diff)
internal: add failing incremental test
Diffstat (limited to 'crates/hir_def')
-rw-r--r--crates/hir_def/src/nameres/tests/incremental.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/crates/hir_def/src/nameres/tests/incremental.rs b/crates/hir_def/src/nameres/tests/incremental.rs
index 509e1bbbc..747407ec7 100644
--- a/crates/hir_def/src/nameres/tests/incremental.rs
+++ b/crates/hir_def/src/nameres/tests/incremental.rs
@@ -105,3 +105,55 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
105 assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) 105 assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
106 } 106 }
107} 107}
108
109#[test]
110fn typing_inside_a_function_doe_should_not_invalidate_expansions() {
111 let (mut db, pos) = TestDB::with_position(
112 r#"
113//- /lib.rs
114macro_rules! m {
115 ($ident:ident) => {
116 fn $ident() { };
117 }
118}
119mod foo;
120
121//- /foo/mod.rs
122pub mod bar;
123
124//- /foo/bar.rs
125m!(X);
126fn quux() { 1$0 }
127m!(Y);
128m!(Z);
129"#,
130 );
131 let krate = db.test_crate();
132 {
133 let events = db.log_executed(|| {
134 let crate_def_map = db.crate_def_map(krate);
135 let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
136 assert_eq!(module_data.scope.resolutions().count(), 4);
137 });
138 let n_recalculated_item_trees = events.iter().filter(|it| it.contains("item_tree")).count();
139 assert_eq!(n_recalculated_item_trees, 6);
140 }
141
142 let new_text = r#"
143m!(X);
144fn quux() { 92 }
145m!(Y);
146m!(Z);
147"#;
148 db.set_file_text(pos.file_id, Arc::new(new_text.to_string()));
149
150 {
151 let events = db.log_executed(|| {
152 let crate_def_map = db.crate_def_map(krate);
153 let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
154 assert_eq!(module_data.scope.resolutions().count(), 4);
155 });
156 let n_recalculated_item_trees = events.iter().filter(|it| it.contains("item_tree")).count();
157 assert_eq!(n_recalculated_item_trees, 1);
158 }
159}