More incremental tests

This commit is contained in:
Lukas Wirth 2023-11-19 12:27:22 +01:00
parent 05f375eae2
commit 8423893d1c

View File

@ -1,13 +1,18 @@
use base_db::SourceDatabaseExt;
use base_db::{SourceDatabase, SourceDatabaseExt};
use triomphe::Arc;
use crate::{db::DefDatabase, AdtId, ModuleDefId};
use super::*;
use crate::{
db::DefDatabase,
nameres::tests::{TestDB, WithFixture},
AdtId, ModuleDefId,
};
fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change: &str) {
let (mut db, pos) = TestDB::with_position(ra_fixture_initial);
let krate = db.test_crate();
let krate = {
let crate_graph = db.crate_graph();
crate_graph.iter().last().unwrap()
};
{
let events = db.log_executed(|| {
db.crate_def_map(krate);
@ -28,39 +33,39 @@ fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change:
fn typing_inside_a_function_should_not_invalidate_def_map() {
check_def_map_is_not_recomputed(
r"
//- /lib.rs
mod foo;$0
//- /lib.rs
mod foo;$0
use crate::foo::bar::Baz;
use crate::foo::bar::Baz;
enum E { A, B }
use E::*;
enum E { A, B }
use E::*;
fn foo() -> i32 {
1 + 1
}
fn foo() -> i32 {
1 + 1
}
#[cfg(never)]
fn no() {}
//- /foo/mod.rs
pub mod bar;
#[cfg(never)]
fn no() {}
//- /foo/mod.rs
pub mod bar;
//- /foo/bar.rs
pub struct Baz;
",
//- /foo/bar.rs
pub struct Baz;
",
r"
mod foo;
mod foo;
use crate::foo::bar::Baz;
use crate::foo::bar::Baz;
enum E { A, B }
use E::*;
enum E { A, B }
use E::*;
fn foo() -> i32 { 92 }
fn foo() -> i32 { 92 }
#[cfg(never)]
fn no() {}
",
#[cfg(never)]
fn no() {}
",
);
}
@ -68,30 +73,157 @@ fn typing_inside_a_function_should_not_invalidate_def_map() {
fn typing_inside_a_macro_should_not_invalidate_def_map() {
check_def_map_is_not_recomputed(
r"
//- /lib.rs
macro_rules! m {
($ident:ident) => {
fn f() {
$ident + $ident;
};
}
}
mod foo;
//- /lib.rs
macro_rules! m {
($ident:ident) => {
fn f() {
$ident + $ident;
};
}
}
mod foo;
//- /foo/mod.rs
pub mod bar;
//- /foo/mod.rs
pub mod bar;
//- /foo/bar.rs
$0
m!(X);
//- /foo/bar.rs
$0
m!(X);
pub struct S {}
",
pub struct S {}
",
r"
m!(Y);
m!(Y);
pub struct S {}
",
pub struct S {}
",
);
}
#[test]
fn typing_inside_an_attribute_should_not_invalidate_def_map() {
check_def_map_is_not_recomputed(
r"
//- proc_macros: identity
//- /lib.rs
mod foo;
//- /foo/mod.rs
pub mod bar;
//- /foo/bar.rs
$0
#[proc_macros::identity]
fn f() {}
",
r"
#[proc_macros::identity]
fn f() { foo }
",
);
}
#[test]
fn typing_inside_an_attribute_arg_should_not_invalidate_def_map() {
check_def_map_is_not_recomputed(
r"
//- proc_macros: identity
//- /lib.rs
mod foo;
//- /foo/mod.rs
pub mod bar;
//- /foo/bar.rs
$0
#[proc_macros::identity]
fn f() {}
",
r"
#[proc_macros::identity(foo)]
fn f() {}
",
);
}
#[test]
fn typing_inside_macro_heavy_file_should_not_invalidate_def_map() {
check_def_map_is_not_recomputed(
r"
//- proc_macros: identity, derive_identity
//- /lib.rs
macro_rules! m {
($ident:ident) => {
fn fm() {
$ident + $ident;
};
}
}
mod foo;
//- /foo/mod.rs
pub mod bar;
//- /foo/bar.rs
$0
fn f() {}
m!(X);
macro_rules! m2 {
($ident:ident) => {
fn f2() {
$ident + $ident;
};
}
}
m2!(X);
#[proc_macros::identity]
#[derive(proc_macros::DeriveIdentity)]
pub struct S {}
",
r"
fn f() {0}
m!(X);
macro_rules! m2 {
($ident:ident) => {
fn f2() {
$ident + $ident;
};
}
}
m2!(X);
#[proc_macros::identity]
#[derive(proc_macros::DeriveIdentity)]
pub struct S {}
",
);
}
#[test]
fn typing_inside_a_derive_should_not_invalidate_def_map() {
check_def_map_is_not_recomputed(
r"
//- proc_macros: derive_identity
//- minicore:derive
//- /lib.rs
mod foo;
//- /foo/mod.rs
pub mod bar;
//- /foo/bar.rs
$0
#[derive(proc_macros::DeriveIdentity)]
#[allow()]
struct S;
",
r"
#[derive(proc_macros::DeriveIdentity)]
#[allow(dead_code)]
struct S;
",
);
}