mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-27 07:03:45 +00:00
remove duplication in tests
This commit is contained in:
parent
46f74e33ca
commit
8f93e7b9a4
@ -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
|
||||
)
|
||||
}
|
||||
",
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user