From 548e5a5c29bb0b453ef170e65d45a6673d8443f1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 4 May 2021 15:31:23 +0300 Subject: internal: add failing incremental test --- crates/hir_def/src/nameres/tests/incremental.rs | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'crates/hir_def/src/nameres/tests') 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() { assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) } } + +#[test] +fn typing_inside_a_function_doe_should_not_invalidate_expansions() { + let (mut db, pos) = TestDB::with_position( + r#" +//- /lib.rs +macro_rules! m { + ($ident:ident) => { + fn $ident() { }; + } +} +mod foo; + +//- /foo/mod.rs +pub mod bar; + +//- /foo/bar.rs +m!(X); +fn quux() { 1$0 } +m!(Y); +m!(Z); +"#, + ); + let krate = db.test_crate(); + { + let events = db.log_executed(|| { + let crate_def_map = db.crate_def_map(krate); + let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); + assert_eq!(module_data.scope.resolutions().count(), 4); + }); + let n_recalculated_item_trees = events.iter().filter(|it| it.contains("item_tree")).count(); + assert_eq!(n_recalculated_item_trees, 6); + } + + let new_text = r#" +m!(X); +fn quux() { 92 } +m!(Y); +m!(Z); +"#; + db.set_file_text(pos.file_id, Arc::new(new_text.to_string())); + + { + let events = db.log_executed(|| { + let crate_def_map = db.crate_def_map(krate); + let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); + assert_eq!(module_data.scope.resolutions().count(), 4); + }); + let n_recalculated_item_trees = events.iter().filter(|it| it.contains("item_tree")).count(); + assert_eq!(n_recalculated_item_trees, 1); + } +} -- cgit v1.2.3 From c4f9cb9b53314b584f6451908ce40bbd65453116 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 4 May 2021 17:12:35 +0300 Subject: Update crates/hir_def/src/nameres/tests/incremental.rs Co-authored-by: Jonas Schievink --- crates/hir_def/src/nameres/tests/incremental.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/hir_def/src/nameres/tests') diff --git a/crates/hir_def/src/nameres/tests/incremental.rs b/crates/hir_def/src/nameres/tests/incremental.rs index 747407ec7..227ecd162 100644 --- a/crates/hir_def/src/nameres/tests/incremental.rs +++ b/crates/hir_def/src/nameres/tests/incremental.rs @@ -107,7 +107,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() { } #[test] -fn typing_inside_a_function_doe_should_not_invalidate_expansions() { +fn typing_inside_a_function_should_not_invalidate_expansions() { let (mut db, pos) = TestDB::with_position( r#" //- /lib.rs -- cgit v1.2.3