From 8f93e7b9a4f99a458bf03c7ef9871060fa8f2cf9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 9 Jan 2019 00:48:54 +0300 Subject: remove duplication in tests --- crates/ra_hir/src/nameres/tests.rs | 88 ++++++++++++++------------------------ 1 file changed, 33 insertions(+), 55 deletions(-) diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index c511c40b2..ac96bea37 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -322,9 +322,33 @@ fn reexport_across_crates() { ); } +fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) { + let (mut db, pos) = MockDatabase::with_position(initial); + let source_root = db.file_source_root(pos.file_id); + { + let events = db.log_executed(|| { + db.item_map(source_root).unwrap(); + }); + assert!(format!("{:?}", events).contains("item_map")) + } + db.query_mut(ra_db::FileTextQuery) + .set(pos.file_id, Arc::new(file_change.to_string())); + + { + let events = db.log_executed(|| { + db.item_map(source_root).unwrap(); + }); + assert!( + !format!("{:?}", events).contains("item_map"), + "{:#?}", + events + ) + } +} + #[test] fn typing_inside_a_function_should_not_invalidate_item_map() { - let (mut db, pos) = MockDatabase::with_position( + check_item_map_is_not_recomputed( " //- /lib.rs mod foo; @@ -342,42 +366,19 @@ fn typing_inside_a_function_should_not_invalidate_item_map() { } } ", - ); - let source_root = db.file_source_root(pos.file_id); - { - let events = db.log_executed(|| { - db.item_map(source_root).unwrap(); - }); - assert!(format!("{:?}", events).contains("item_map")) - } - - let new_text = " + " salsa::query_group! { trait Baz { fn foo() -> i32 { 92 } } } - " - .to_string(); - - db.query_mut(ra_db::FileTextQuery) - .set(pos.file_id, Arc::new(new_text)); - - { - let events = db.log_executed(|| { - db.item_map(source_root).unwrap(); - }); - assert!( - !format!("{:?}", events).contains("item_map"), - "{:#?}", - events - ) - } + ", + ); } #[test] fn typing_inside_a_function_inside_a_macro_should_not_invalidate_item_map() { - let (mut db, pos) = MockDatabase::with_position( + check_item_map_is_not_recomputed( " //- /lib.rs mod foo;<|> @@ -392,36 +393,13 @@ fn typing_inside_a_function_inside_a_macro_should_not_invalidate_item_map() { //- /foo/bar.rs pub struct Baz; - ", - ); - let source_root = db.file_source_root(pos.file_id); - { - let events = db.log_executed(|| { - db.item_map(source_root).unwrap(); - }); - assert!(format!("{:?}", events).contains("item_map")) - } - - let new_text = " + ", + " mod foo; use crate::foo::bar::Baz; fn foo() -> i32 { 92 } - " - .to_string(); - - db.query_mut(ra_db::FileTextQuery) - .set(pos.file_id, Arc::new(new_text)); - - { - let events = db.log_executed(|| { - db.item_map(source_root).unwrap(); - }); - assert!( - !format!("{:?}", events).contains("item_map"), - "{:#?}", - events - ) - } + ", + ); } -- cgit v1.2.3