mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Merge #2255
2255: Add convenience method for testing r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
3948de3143
4 changed files with 15 additions and 7 deletions
|
@ -8,8 +8,8 @@ use rustc_hash::FxHashMap;
|
|||
use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER};
|
||||
|
||||
use crate::{
|
||||
CrateGraph, Edition, FileId, FilePosition, RelativePathBuf, SourceDatabaseExt, SourceRoot,
|
||||
SourceRootId,
|
||||
CrateGraph, CrateId, Edition, FileId, FilePosition, RelativePathBuf, SourceDatabaseExt,
|
||||
SourceRoot, SourceRootId,
|
||||
};
|
||||
|
||||
pub const WORKSPACE: SourceRootId = SourceRootId(0);
|
||||
|
@ -33,6 +33,14 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static {
|
|||
let pos = with_files(&mut db, fixture);
|
||||
(db, pos.unwrap())
|
||||
}
|
||||
|
||||
fn test_crate(&self) -> CrateId {
|
||||
let crate_graph = self.crate_graph();
|
||||
let mut it = crate_graph.iter();
|
||||
let res = it.next().unwrap();
|
||||
assert!(it.next().is_none());
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {}
|
||||
|
|
|
@ -798,7 +798,7 @@ mod tests {
|
|||
|
||||
fn do_limited_resolve(code: &str, limit: u32, poison_limit: u32) -> CrateDefMap {
|
||||
let (db, _file_id) = TestDB::with_single_file(&code);
|
||||
let krate = db.crate_graph().iter().next().unwrap();
|
||||
let krate = db.test_crate();
|
||||
|
||||
let def_map = {
|
||||
let edition = db.crate_graph().edition(krate);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use ra_db::{SourceDatabase, SourceDatabaseExt};
|
||||
use ra_db::SourceDatabaseExt;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn check_def_map_is_not_recomputed(initial: &str, file_change: &str) {
|
||||
let (mut db, pos) = TestDB::with_position(initial);
|
||||
let krate = db.crate_graph().iter().next().unwrap();
|
||||
let krate = db.test_crate();
|
||||
{
|
||||
let events = db.log_executed(|| {
|
||||
db.crate_def_map(krate);
|
||||
|
@ -111,7 +111,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
|
|||
m!(X);
|
||||
",
|
||||
);
|
||||
let krate = db.crate_graph().iter().next().unwrap();
|
||||
let krate = db.test_crate();
|
||||
{
|
||||
let events = db.log_executed(|| {
|
||||
let crate_def_map = db.crate_def_map(krate);
|
||||
|
|
|
@ -656,7 +656,7 @@ fn unresolved_module_diagnostics() {
|
|||
//- /foo.rs
|
||||
",
|
||||
);
|
||||
let krate = db.crate_graph().iter().next().unwrap();
|
||||
let krate = db.test_crate();
|
||||
|
||||
let crate_def_map = db.crate_def_map(krate);
|
||||
|
||||
|
|
Loading…
Reference in a new issue