mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
remove duplication in tests
This commit is contained in:
parent
46f74e33ca
commit
8f93e7b9a4
1 changed files with 33 additions and 55 deletions
|
@ -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]
|
#[test]
|
||||||
fn typing_inside_a_function_should_not_invalidate_item_map() {
|
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
|
//- /lib.rs
|
||||||
mod foo;
|
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! {
|
salsa::query_group! {
|
||||||
trait Baz {
|
trait Baz {
|
||||||
fn foo() -> i32 { 92 }
|
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]
|
#[test]
|
||||||
fn typing_inside_a_function_inside_a_macro_should_not_invalidate_item_map() {
|
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
|
//- /lib.rs
|
||||||
mod foo;<|>
|
mod foo;<|>
|
||||||
|
@ -393,35 +394,12 @@ fn typing_inside_a_function_inside_a_macro_should_not_invalidate_item_map() {
|
||||||
//- /foo/bar.rs
|
//- /foo/bar.rs
|
||||||
pub struct Baz;
|
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;
|
mod foo;
|
||||||
|
|
||||||
use crate::foo::bar::Baz;
|
use crate::foo::bar::Baz;
|
||||||
|
|
||||||
fn foo() -> i32 { 92 }
|
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…
Add table
Add a link
Reference in a new issue