From 42370610ce03c1bb5893d9e29c2c215482e8d8ca Mon Sep 17 00:00:00 2001
From: Aleksey Kladov <aleksey.kladov@gmail.com>
Date: Mon, 4 Nov 2019 22:28:47 +0300
Subject: Restore assists tests

---
 crates/ra_assists/src/doc_tests.rs |  3 ++-
 crates/ra_assists/src/lib.rs       |  8 ++++---
 crates/ra_assists/src/test_db.rs   | 43 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 4 deletions(-)
 create mode 100644 crates/ra_assists/src/test_db.rs

(limited to 'crates')

diff --git a/crates/ra_assists/src/doc_tests.rs b/crates/ra_assists/src/doc_tests.rs
index 2500a5ab7..a8f8446cb 100644
--- a/crates/ra_assists/src/doc_tests.rs
+++ b/crates/ra_assists/src/doc_tests.rs
@@ -5,10 +5,11 @@
 
 mod generated;
 
-use hir::mock::TestDB;
 use ra_db::{fixture::WithFixture, FileRange};
 use test_utils::{assert_eq_text, extract_range_or_offset};
 
+use crate::test_db::TestDB;
+
 fn check(assist_id: &str, before: &str, after: &str) {
     let (selection, before) = extract_range_or_offset(before);
     let (db, file_id) = TestDB::with_single_file(&before);
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index 85fb72395..39c1c283f 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -9,6 +9,8 @@ mod assist_ctx;
 mod marks;
 #[cfg(test)]
 mod doc_tests;
+#[cfg(test)]
+mod test_db;
 
 use hir::db::HirDatabase;
 use ra_db::FileRange;
@@ -146,12 +148,11 @@ mod assists {
 
 #[cfg(test)]
 mod helpers {
-    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};
 
-    use crate::{Assist, AssistCtx};
+    use crate::{test_db::TestDB, Assist, AssistCtx};
 
     pub(crate) fn check_assist(
         assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
@@ -268,11 +269,12 @@ mod helpers {
 
 #[cfg(test)]
 mod tests {
-    use hir::mock::TestDB;
     use ra_db::{fixture::WithFixture, FileRange};
     use ra_syntax::TextRange;
     use test_utils::{extract_offset, extract_range};
 
+    use crate::test_db::TestDB;
+
     #[test]
     fn assist_order_field_struct() {
         let before = "struct Foo { <|>bar: u32 }";
diff --git a/crates/ra_assists/src/test_db.rs b/crates/ra_assists/src/test_db.rs
new file mode 100644
index 000000000..7b196561a
--- /dev/null
+++ b/crates/ra_assists/src/test_db.rs
@@ -0,0 +1,43 @@
+use std::sync::Arc;
+
+use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath};
+
+#[salsa::database(
+    ra_db::SourceDatabaseExtStorage,
+    ra_db::SourceDatabaseStorage,
+    hir::db::InternDatabaseStorage,
+    hir::db::AstDatabaseStorage,
+    hir::db::DefDatabaseStorage,
+    hir::db::DefDatabase2Storage,
+    hir::db::HirDatabaseStorage
+)]
+#[derive(Debug, Default)]
+pub struct TestDB {
+    runtime: salsa::Runtime<TestDB>,
+}
+
+impl salsa::Database for TestDB {
+    fn salsa_runtime(&self) -> &salsa::Runtime<Self> {
+        &self.runtime
+    }
+}
+
+impl std::panic::RefUnwindSafe for TestDB {}
+
+impl FileLoader for TestDB {
+    fn file_text(&self, file_id: FileId) -> Arc<String> {
+        FileLoaderDelegate(self).file_text(file_id)
+    }
+    fn resolve_relative_path(
+        &self,
+        anchor: FileId,
+        relative_path: &RelativePath,
+    ) -> Option<FileId> {
+        FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path)
+    }
+    fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> {
+        FileLoaderDelegate(self).relevant_crates(file_id)
+    }
+}
+
+impl hir::debug::HirDebugHelper for TestDB {}
-- 
cgit v1.2.3