aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/mock.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-12-09 11:00:56 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-12-09 11:00:56 +0000
commit19f6cdcc034a2a91e6112a4ceb32e26413b0aa0d (patch)
tree548400065966f715ae203e6f6e0fcfd9f12e4470 /crates/ra_hir/src/mock.rs
parent34956b7823d72467fbf4fa62bd4413dfb680f78d (diff)
parent7784c7a701ba944decf671f80dea581d68667663 (diff)
Merge #268
268: WIP: resolve imports across crates r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/mock.rs')
-rw-r--r--crates/ra_hir/src/mock.rs24
1 files changed, 20 insertions, 4 deletions
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index e855df11d..b7193c4f3 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -2,7 +2,7 @@ use std::sync::Arc;
2 2
3use parking_lot::Mutex; 3use parking_lot::Mutex;
4use salsa::{self, Database}; 4use salsa::{self, Database};
5use ra_db::{LocationIntener, BaseDatabase, FilePosition, mock::FileMap, FileId, WORKSPACE}; 5use ra_db::{LocationIntener, BaseDatabase, FilePosition, mock::FileMap, FileId, WORKSPACE, CrateGraph};
6use relative_path::RelativePathBuf; 6use relative_path::RelativePathBuf;
7use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; 7use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset};
8 8
@@ -16,7 +16,24 @@ pub(crate) struct MockDatabase {
16} 16}
17 17
18impl MockDatabase { 18impl MockDatabase {
19 pub(crate) fn with_files(fixture: &str) -> (MockDatabase, FileMap) {
20 let (db, file_map, position) = MockDatabase::from_fixture(fixture);
21 assert!(position.is_none());
22 (db, file_map)
23 }
24
19 pub(crate) fn with_position(fixture: &str) -> (MockDatabase, FilePosition) { 25 pub(crate) fn with_position(fixture: &str) -> (MockDatabase, FilePosition) {
26 let (db, _, position) = MockDatabase::from_fixture(fixture);
27 let position = position.expect("expected a marker ( <|> )");
28 (db, position)
29 }
30
31 pub(crate) fn set_crate_graph(&mut self, crate_graph: CrateGraph) {
32 self.query_mut(ra_db::CrateGraphQuery)
33 .set((), Arc::new(crate_graph));
34 }
35
36 fn from_fixture(fixture: &str) -> (MockDatabase, FileMap, Option<FilePosition>) {
20 let mut db = MockDatabase::default(); 37 let mut db = MockDatabase::default();
21 38
22 let mut position = None; 39 let mut position = None;
@@ -32,11 +49,10 @@ impl MockDatabase {
32 db.add_file(&mut file_map, &entry.meta, &entry.text); 49 db.add_file(&mut file_map, &entry.meta, &entry.text);
33 } 50 }
34 } 51 }
35 let position = position.expect("expected a marker (<|>)"); 52 let source_root = file_map.clone().into_source_root();
36 let source_root = file_map.into_source_root();
37 db.query_mut(ra_db::SourceRootQuery) 53 db.query_mut(ra_db::SourceRootQuery)
38 .set(WORKSPACE, Arc::new(source_root)); 54 .set(WORKSPACE, Arc::new(source_root));
39 (db, position) 55 (db, file_map, position)
40 } 56 }
41 57
42 fn add_file(&mut self, file_map: &mut FileMap, path: &str, text: &str) -> FileId { 58 fn add_file(&mut self, file_map: &mut FileMap, path: &str, text: &str) -> FileId {