mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Move hir_ty incremental test to its own file
This commit is contained in:
parent
a2940c42c0
commit
26b4777e1f
@ -7,6 +7,7 @@ mod traits;
|
|||||||
mod method_resolution;
|
mod method_resolution;
|
||||||
mod macros;
|
mod macros;
|
||||||
mod display_source_code;
|
mod display_source_code;
|
||||||
|
mod incremental;
|
||||||
|
|
||||||
use std::{env, sync::Arc};
|
use std::{env, sync::Arc};
|
||||||
|
|
||||||
@ -317,50 +318,6 @@ fn ellipsize(mut text: String, max_len: usize) -> String {
|
|||||||
text
|
text
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
|
||||||
let (mut db, pos) = TestDB::with_position(
|
|
||||||
"
|
|
||||||
//- /lib.rs
|
|
||||||
fn foo() -> i32 {
|
|
||||||
$01 + 1
|
|
||||||
}
|
|
||||||
",
|
|
||||||
);
|
|
||||||
{
|
|
||||||
let events = db.log_executed(|| {
|
|
||||||
let module = db.module_for_file(pos.file_id);
|
|
||||||
let crate_def_map = module.def_map(&db);
|
|
||||||
visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
|
|
||||||
db.infer(def);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
assert!(format!("{:?}", events).contains("infer"))
|
|
||||||
}
|
|
||||||
|
|
||||||
let new_text = "
|
|
||||||
fn foo() -> i32 {
|
|
||||||
1
|
|
||||||
+
|
|
||||||
1
|
|
||||||
}
|
|
||||||
"
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
db.set_file_text(pos.file_id, Arc::new(new_text));
|
|
||||||
|
|
||||||
{
|
|
||||||
let events = db.log_executed(|| {
|
|
||||||
let module = db.module_for_file(pos.file_id);
|
|
||||||
let crate_def_map = module.def_map(&db);
|
|
||||||
visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
|
|
||||||
db.infer(def);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_infer(ra_fixture: &str, expect: Expect) {
|
fn check_infer(ra_fixture: &str, expect: Expect) {
|
||||||
let mut actual = infer(ra_fixture);
|
let mut actual = infer(ra_fixture);
|
||||||
actual.push('\n');
|
actual.push('\n');
|
||||||
|
51
crates/hir_ty/src/tests/incremental.rs
Normal file
51
crates/hir_ty/src/tests/incremental.rs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use base_db::{fixture::WithFixture, SourceDatabaseExt};
|
||||||
|
|
||||||
|
use crate::{db::HirDatabase, test_db::TestDB};
|
||||||
|
|
||||||
|
use super::visit_module;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
||||||
|
let (mut db, pos) = TestDB::with_position(
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
fn foo() -> i32 {
|
||||||
|
$01 + 1
|
||||||
|
}
|
||||||
|
",
|
||||||
|
);
|
||||||
|
{
|
||||||
|
let events = db.log_executed(|| {
|
||||||
|
let module = db.module_for_file(pos.file_id);
|
||||||
|
let crate_def_map = module.def_map(&db);
|
||||||
|
visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
|
||||||
|
db.infer(def);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
assert!(format!("{:?}", events).contains("infer"))
|
||||||
|
}
|
||||||
|
|
||||||
|
let new_text = "
|
||||||
|
fn foo() -> i32 {
|
||||||
|
1
|
||||||
|
+
|
||||||
|
1
|
||||||
|
}
|
||||||
|
"
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
db.set_file_text(pos.file_id, Arc::new(new_text));
|
||||||
|
|
||||||
|
{
|
||||||
|
let events = db.log_executed(|| {
|
||||||
|
let module = db.module_for_file(pos.file_id);
|
||||||
|
let crate_def_map = module.def_map(&db);
|
||||||
|
visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
|
||||||
|
db.infer(def);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user