mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Rename MockDatabase -> TestDB
Actually working rename is sooo useful!
This commit is contained in:
parent
7649a8ebbe
commit
74d827bb80
6 changed files with 57 additions and 60 deletions
|
@ -5,13 +5,13 @@
|
|||
|
||||
mod generated;
|
||||
|
||||
use hir::mock::MockDatabase;
|
||||
use hir::mock::TestDB;
|
||||
use ra_db::{fixture::WithFixture, FileRange};
|
||||
use test_utils::{assert_eq_text, extract_range_or_offset};
|
||||
|
||||
fn check(assist_id: &str, before: &str, after: &str) {
|
||||
let (selection, before) = extract_range_or_offset(before);
|
||||
let (db, file_id) = MockDatabase::with_single_file(&before);
|
||||
let (db, file_id) = TestDB::with_single_file(&before);
|
||||
let frange = FileRange { file_id, range: selection.into() };
|
||||
|
||||
let (_assist_id, action) = crate::assists(&db, frange)
|
||||
|
|
|
@ -146,7 +146,7 @@ mod assists {
|
|||
|
||||
#[cfg(test)]
|
||||
mod helpers {
|
||||
use hir::mock::MockDatabase;
|
||||
use hir::mock::TestDB;
|
||||
use ra_db::{fixture::WithFixture, FileRange};
|
||||
use ra_syntax::TextRange;
|
||||
use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range};
|
||||
|
@ -154,12 +154,12 @@ mod helpers {
|
|||
use crate::{Assist, AssistCtx};
|
||||
|
||||
pub(crate) fn check_assist(
|
||||
assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>,
|
||||
assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
|
||||
before: &str,
|
||||
after: &str,
|
||||
) {
|
||||
let (before_cursor_pos, before) = extract_offset(before);
|
||||
let (db, file_id) = MockDatabase::with_single_file(&before);
|
||||
let (db, file_id) = TestDB::with_single_file(&before);
|
||||
let frange =
|
||||
FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) };
|
||||
let assist =
|
||||
|
@ -182,12 +182,12 @@ mod helpers {
|
|||
}
|
||||
|
||||
pub(crate) fn check_assist_range(
|
||||
assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>,
|
||||
assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
|
||||
before: &str,
|
||||
after: &str,
|
||||
) {
|
||||
let (range, before) = extract_range(before);
|
||||
let (db, file_id) = MockDatabase::with_single_file(&before);
|
||||
let (db, file_id) = TestDB::with_single_file(&before);
|
||||
let frange = FileRange { file_id, range };
|
||||
let assist =
|
||||
AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable");
|
||||
|
@ -204,12 +204,12 @@ mod helpers {
|
|||
}
|
||||
|
||||
pub(crate) fn check_assist_target(
|
||||
assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>,
|
||||
assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
|
||||
before: &str,
|
||||
target: &str,
|
||||
) {
|
||||
let (before_cursor_pos, before) = extract_offset(before);
|
||||
let (db, file_id) = MockDatabase::with_single_file(&before);
|
||||
let (db, file_id) = TestDB::with_single_file(&before);
|
||||
let frange =
|
||||
FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) };
|
||||
let assist =
|
||||
|
@ -224,12 +224,12 @@ mod helpers {
|
|||
}
|
||||
|
||||
pub(crate) fn check_assist_range_target(
|
||||
assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>,
|
||||
assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
|
||||
before: &str,
|
||||
target: &str,
|
||||
) {
|
||||
let (range, before) = extract_range(before);
|
||||
let (db, file_id) = MockDatabase::with_single_file(&before);
|
||||
let (db, file_id) = TestDB::with_single_file(&before);
|
||||
let frange = FileRange { file_id, range };
|
||||
let assist =
|
||||
AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable");
|
||||
|
@ -243,11 +243,11 @@ mod helpers {
|
|||
}
|
||||
|
||||
pub(crate) fn check_assist_not_applicable(
|
||||
assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>,
|
||||
assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
|
||||
before: &str,
|
||||
) {
|
||||
let (before_cursor_pos, before) = extract_offset(before);
|
||||
let (db, file_id) = MockDatabase::with_single_file(&before);
|
||||
let (db, file_id) = TestDB::with_single_file(&before);
|
||||
let frange =
|
||||
FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) };
|
||||
let assist = AssistCtx::with_ctx(&db, frange, true, assist);
|
||||
|
@ -255,11 +255,11 @@ mod helpers {
|
|||
}
|
||||
|
||||
pub(crate) fn check_assist_range_not_applicable(
|
||||
assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>,
|
||||
assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
|
||||
before: &str,
|
||||
) {
|
||||
let (range, before) = extract_range(before);
|
||||
let (db, file_id) = MockDatabase::with_single_file(&before);
|
||||
let (db, file_id) = TestDB::with_single_file(&before);
|
||||
let frange = FileRange { file_id, range };
|
||||
let assist = AssistCtx::with_ctx(&db, frange, true, assist);
|
||||
assert!(assist.is_none());
|
||||
|
@ -268,7 +268,7 @@ mod helpers {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use hir::mock::MockDatabase;
|
||||
use hir::mock::TestDB;
|
||||
use ra_db::{fixture::WithFixture, FileRange};
|
||||
use ra_syntax::TextRange;
|
||||
use test_utils::{extract_offset, extract_range};
|
||||
|
@ -277,7 +277,7 @@ mod tests {
|
|||
fn assist_order_field_struct() {
|
||||
let before = "struct Foo { <|>bar: u32 }";
|
||||
let (before_cursor_pos, before) = extract_offset(before);
|
||||
let (db, file_id) = MockDatabase::with_single_file(&before);
|
||||
let (db, file_id) = TestDB::with_single_file(&before);
|
||||
let frange =
|
||||
FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) };
|
||||
let assists = super::assists(&db, frange);
|
||||
|
@ -298,7 +298,7 @@ mod tests {
|
|||
}
|
||||
}";
|
||||
let (range, before) = extract_range(before);
|
||||
let (db, file_id) = MockDatabase::with_single_file(&before);
|
||||
let (db, file_id) = TestDB::with_single_file(&before);
|
||||
let frange = FileRange { file_id, range };
|
||||
let assists = super::assists(&db, frange);
|
||||
let mut assists = assists.iter();
|
||||
|
|
|
@ -178,7 +178,7 @@ mod tests {
|
|||
use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
|
||||
use test_utils::{assert_eq_text, extract_offset};
|
||||
|
||||
use crate::{mock::MockDatabase, source_binder::SourceAnalyzer};
|
||||
use crate::{source_binder::SourceAnalyzer, test_db::TestDB};
|
||||
|
||||
fn do_check(code: &str, expected: &[&str]) {
|
||||
let (off, code) = extract_offset(code);
|
||||
|
@ -191,7 +191,7 @@ mod tests {
|
|||
buf
|
||||
};
|
||||
|
||||
let (db, file_id) = MockDatabase::with_single_file(&code);
|
||||
let (db, file_id) = TestDB::with_single_file(&code);
|
||||
let file = db.parse(file_id).ok().unwrap();
|
||||
let marker: ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
|
||||
let analyzer = SourceAnalyzer::new(&db, file_id, marker.syntax(), None);
|
||||
|
@ -288,7 +288,7 @@ mod tests {
|
|||
fn do_check_local_name(code: &str, expected_offset: u32) {
|
||||
let (off, code) = extract_offset(code);
|
||||
|
||||
let (db, file_id) = MockDatabase::with_single_file(&code);
|
||||
let (db, file_id) = TestDB::with_single_file(&code);
|
||||
let file = db.parse(file_id).ok().unwrap();
|
||||
let expected_name = find_node_at_offset::<ast::Name>(file.syntax(), expected_offset.into())
|
||||
.expect("failed to find a name at the target offset");
|
||||
|
|
|
@ -29,8 +29,6 @@ macro_rules! impl_froms {
|
|||
pub mod debug;
|
||||
|
||||
pub mod db;
|
||||
#[macro_use]
|
||||
pub mod mock;
|
||||
pub mod source_binder;
|
||||
|
||||
mod ids;
|
||||
|
@ -51,6 +49,8 @@ mod code_model;
|
|||
|
||||
pub mod from_source;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_db;
|
||||
#[cfg(test)]
|
||||
mod marks;
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@ use ra_db::{
|
|||
|
||||
use crate::{db, debug::HirDebugHelper};
|
||||
|
||||
pub const WORKSPACE: SourceRootId = SourceRootId(0);
|
||||
|
||||
#[salsa::database(
|
||||
ra_db::SourceDatabaseExtStorage,
|
||||
ra_db::SourceDatabaseStorage,
|
||||
|
@ -24,14 +22,14 @@ pub const WORKSPACE: SourceRootId = SourceRootId(0);
|
|||
db::HirDatabaseStorage
|
||||
)]
|
||||
#[derive(Debug)]
|
||||
pub struct MockDatabase {
|
||||
events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
|
||||
runtime: salsa::Runtime<MockDatabase>,
|
||||
pub struct TestDB {
|
||||
events: Mutex<Option<Vec<salsa::Event<TestDB>>>>,
|
||||
runtime: salsa::Runtime<TestDB>,
|
||||
}
|
||||
|
||||
impl panic::RefUnwindSafe for MockDatabase {}
|
||||
impl panic::RefUnwindSafe for TestDB {}
|
||||
|
||||
impl FileLoader for MockDatabase {
|
||||
impl FileLoader for TestDB {
|
||||
fn file_text(&self, file_id: FileId) -> Arc<String> {
|
||||
FileLoaderDelegate(self).file_text(file_id)
|
||||
}
|
||||
|
@ -48,7 +46,7 @@ impl FileLoader for MockDatabase {
|
|||
}
|
||||
|
||||
// FIXME: improve `WithFixture` to bring useful hir debugging back
|
||||
impl HirDebugHelper for MockDatabase {
|
||||
impl HirDebugHelper for TestDB {
|
||||
fn crate_name(&self, _krate: CrateId) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
@ -58,7 +56,7 @@ impl HirDebugHelper for MockDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
impl MockDatabase {
|
||||
impl TestDB {
|
||||
pub fn diagnostics(&self) -> String {
|
||||
let mut buf = String::new();
|
||||
let crate_graph = self.crate_graph();
|
||||
|
@ -79,12 +77,12 @@ impl MockDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
impl salsa::Database for MockDatabase {
|
||||
fn salsa_runtime(&self) -> &salsa::Runtime<MockDatabase> {
|
||||
impl salsa::Database for TestDB {
|
||||
fn salsa_runtime(&self) -> &salsa::Runtime<TestDB> {
|
||||
&self.runtime
|
||||
}
|
||||
|
||||
fn salsa_event(&self, event: impl Fn() -> salsa::Event<MockDatabase>) {
|
||||
fn salsa_event(&self, event: impl Fn() -> salsa::Event<TestDB>) {
|
||||
let mut events = self.events.lock();
|
||||
if let Some(events) = &mut *events {
|
||||
events.push(event());
|
||||
|
@ -92,26 +90,25 @@ impl salsa::Database for MockDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for MockDatabase {
|
||||
fn default() -> MockDatabase {
|
||||
let mut db =
|
||||
MockDatabase { events: Default::default(), runtime: salsa::Runtime::default() };
|
||||
impl Default for TestDB {
|
||||
fn default() -> TestDB {
|
||||
let mut db = TestDB { events: Default::default(), runtime: salsa::Runtime::default() };
|
||||
db.set_crate_graph(Default::default());
|
||||
db
|
||||
}
|
||||
}
|
||||
|
||||
impl salsa::ParallelDatabase for MockDatabase {
|
||||
fn snapshot(&self) -> salsa::Snapshot<MockDatabase> {
|
||||
salsa::Snapshot::new(MockDatabase {
|
||||
impl salsa::ParallelDatabase for TestDB {
|
||||
fn snapshot(&self) -> salsa::Snapshot<TestDB> {
|
||||
salsa::Snapshot::new(TestDB {
|
||||
events: Default::default(),
|
||||
runtime: self.runtime.snapshot(self),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl MockDatabase {
|
||||
pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<MockDatabase>> {
|
||||
impl TestDB {
|
||||
pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<TestDB>> {
|
||||
*self.events.lock() = Some(Vec::new());
|
||||
f();
|
||||
self.events.lock().take().unwrap()
|
|
@ -11,7 +11,7 @@ use ra_syntax::{
|
|||
use test_utils::covers;
|
||||
|
||||
use crate::{
|
||||
expr::BodySourceMap, mock::MockDatabase, ty::display::HirDisplay, ty::InferenceResult,
|
||||
expr::BodySourceMap, test_db::TestDB, ty::display::HirDisplay, ty::InferenceResult,
|
||||
SourceAnalyzer,
|
||||
};
|
||||
|
||||
|
@ -24,7 +24,7 @@ mod coercion;
|
|||
|
||||
#[test]
|
||||
fn cfg_impl_block() {
|
||||
let (db, pos) = MockDatabase::with_position(
|
||||
let (db, pos) = TestDB::with_position(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:foo cfg:test
|
||||
use foo::S as T;
|
||||
|
@ -64,7 +64,7 @@ impl S {
|
|||
|
||||
#[test]
|
||||
fn infer_await() {
|
||||
let (db, pos) = MockDatabase::with_position(
|
||||
let (db, pos) = TestDB::with_position(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:std
|
||||
|
||||
|
@ -95,7 +95,7 @@ mod future {
|
|||
|
||||
#[test]
|
||||
fn infer_box() {
|
||||
let (db, pos) = MockDatabase::with_position(
|
||||
let (db, pos) = TestDB::with_position(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:std
|
||||
|
||||
|
@ -122,7 +122,7 @@ mod boxed {
|
|||
|
||||
#[test]
|
||||
fn infer_adt_self() {
|
||||
let (db, pos) = MockDatabase::with_position(
|
||||
let (db, pos) = TestDB::with_position(
|
||||
r#"
|
||||
//- /main.rs
|
||||
enum Nat { Succ(Self), Demo(Nat), Zero }
|
||||
|
@ -141,7 +141,7 @@ fn test() {
|
|||
|
||||
#[test]
|
||||
fn infer_try() {
|
||||
let (db, pos) = MockDatabase::with_position(
|
||||
let (db, pos) = TestDB::with_position(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:std
|
||||
|
||||
|
@ -181,7 +181,7 @@ mod result {
|
|||
|
||||
#[test]
|
||||
fn infer_for_loop() {
|
||||
let (db, pos) = MockDatabase::with_position(
|
||||
let (db, pos) = TestDB::with_position(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:std
|
||||
|
||||
|
@ -223,7 +223,7 @@ mod collections {
|
|||
#[test]
|
||||
fn infer_while_let() {
|
||||
covers!(infer_while_let);
|
||||
let (db, pos) = MockDatabase::with_position(
|
||||
let (db, pos) = TestDB::with_position(
|
||||
r#"
|
||||
//- /main.rs
|
||||
enum Option<T> { Some(T), None }
|
||||
|
@ -2484,7 +2484,7 @@ pub fn main_loop() {
|
|||
|
||||
#[test]
|
||||
fn cross_crate_associated_method_call() {
|
||||
let (db, pos) = MockDatabase::with_position(
|
||||
let (db, pos) = TestDB::with_position(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:other_crate
|
||||
fn test() {
|
||||
|
@ -3378,7 +3378,7 @@ fn test() { S.foo()<|>; }
|
|||
|
||||
#[test]
|
||||
fn infer_macro_with_dollar_crate_is_correct_in_expr() {
|
||||
let (db, pos) = MockDatabase::with_position(
|
||||
let (db, pos) = TestDB::with_position(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:foo
|
||||
fn test() {
|
||||
|
@ -3482,7 +3482,7 @@ fn test() { (&S).foo()<|>; }
|
|||
|
||||
#[test]
|
||||
fn method_resolution_trait_from_prelude() {
|
||||
let (db, pos) = MockDatabase::with_position(
|
||||
let (db, pos) = TestDB::with_position(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:other_crate
|
||||
struct S;
|
||||
|
@ -4651,7 +4651,7 @@ fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
|
|||
assert_eq!(t, "{unknown}");
|
||||
}
|
||||
|
||||
fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
|
||||
fn type_at_pos(db: &TestDB, pos: FilePosition) -> String {
|
||||
let file = db.parse(pos.file_id).ok().unwrap();
|
||||
let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap();
|
||||
let analyzer = SourceAnalyzer::new(db, pos.file_id, expr.syntax(), Some(pos.offset));
|
||||
|
@ -4660,12 +4660,12 @@ fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
|
|||
}
|
||||
|
||||
fn type_at(content: &str) -> String {
|
||||
let (db, file_pos) = MockDatabase::with_position(content);
|
||||
let (db, file_pos) = TestDB::with_position(content);
|
||||
type_at_pos(&db, file_pos)
|
||||
}
|
||||
|
||||
fn infer(content: &str) -> String {
|
||||
let (db, file_id) = MockDatabase::with_single_file(content);
|
||||
let (db, file_id) = TestDB::with_single_file(content);
|
||||
let source_file = db.parse(file_id).ok().unwrap();
|
||||
|
||||
let mut acc = String::new();
|
||||
|
@ -4748,7 +4748,7 @@ fn ellipsize(mut text: String, max_len: usize) -> String {
|
|||
|
||||
#[test]
|
||||
fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
||||
let (mut db, pos) = MockDatabase::with_position(
|
||||
let (mut db, pos) = TestDB::with_position(
|
||||
"
|
||||
//- /lib.rs
|
||||
fn foo() -> i32 {
|
||||
|
@ -4788,7 +4788,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
|||
|
||||
#[test]
|
||||
fn no_such_field_diagnostics() {
|
||||
let diagnostics = MockDatabase::with_files(
|
||||
let diagnostics = TestDB::with_files(
|
||||
r"
|
||||
//- /lib.rs
|
||||
struct S { foo: i32, bar: () }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue