aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-04 19:21:15 +0000
committerAleksey Kladov <[email protected]>2019-11-04 19:21:15 +0000
commit74d827bb8001952f90c85fca3d064fe3096009bd (patch)
tree672dfa705dbdd06a167a645b5c5ebea9afe3a57e /crates/ra_hir
parent7649a8ebbe900f43cc9b8789c2942cfbadab8f1c (diff)
Rename MockDatabase -> TestDB
Actually working rename is sooo useful!
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/expr/scope.rs6
-rw-r--r--crates/ra_hir/src/lib.rs4
-rw-r--r--crates/ra_hir/src/test_db.rs (renamed from crates/ra_hir/src/mock.rs)39
-rw-r--r--crates/ra_hir/src/ty/tests.rs32
4 files changed, 39 insertions, 42 deletions
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs
index f7196b740..c14c2ab66 100644
--- a/crates/ra_hir/src/expr/scope.rs
+++ b/crates/ra_hir/src/expr/scope.rs
@@ -178,7 +178,7 @@ mod tests {
178 use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; 178 use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
179 use test_utils::{assert_eq_text, extract_offset}; 179 use test_utils::{assert_eq_text, extract_offset};
180 180
181 use crate::{mock::MockDatabase, source_binder::SourceAnalyzer}; 181 use crate::{source_binder::SourceAnalyzer, test_db::TestDB};
182 182
183 fn do_check(code: &str, expected: &[&str]) { 183 fn do_check(code: &str, expected: &[&str]) {
184 let (off, code) = extract_offset(code); 184 let (off, code) = extract_offset(code);
@@ -191,7 +191,7 @@ mod tests {
191 buf 191 buf
192 }; 192 };
193 193
194 let (db, file_id) = MockDatabase::with_single_file(&code); 194 let (db, file_id) = TestDB::with_single_file(&code);
195 let file = db.parse(file_id).ok().unwrap(); 195 let file = db.parse(file_id).ok().unwrap();
196 let marker: ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); 196 let marker: ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
197 let analyzer = SourceAnalyzer::new(&db, file_id, marker.syntax(), None); 197 let analyzer = SourceAnalyzer::new(&db, file_id, marker.syntax(), None);
@@ -288,7 +288,7 @@ mod tests {
288 fn do_check_local_name(code: &str, expected_offset: u32) { 288 fn do_check_local_name(code: &str, expected_offset: u32) {
289 let (off, code) = extract_offset(code); 289 let (off, code) = extract_offset(code);
290 290
291 let (db, file_id) = MockDatabase::with_single_file(&code); 291 let (db, file_id) = TestDB::with_single_file(&code);
292 let file = db.parse(file_id).ok().unwrap(); 292 let file = db.parse(file_id).ok().unwrap();
293 let expected_name = find_node_at_offset::<ast::Name>(file.syntax(), expected_offset.into()) 293 let expected_name = find_node_at_offset::<ast::Name>(file.syntax(), expected_offset.into())
294 .expect("failed to find a name at the target offset"); 294 .expect("failed to find a name at the target offset");
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 3ba99d92d..da6aa2ed8 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -29,8 +29,6 @@ macro_rules! impl_froms {
29pub mod debug; 29pub mod debug;
30 30
31pub mod db; 31pub mod db;
32#[macro_use]
33pub mod mock;
34pub mod source_binder; 32pub mod source_binder;
35 33
36mod ids; 34mod ids;
@@ -52,6 +50,8 @@ mod code_model;
52pub mod from_source; 50pub mod from_source;
53 51
54#[cfg(test)] 52#[cfg(test)]
53mod test_db;
54#[cfg(test)]
55mod marks; 55mod marks;
56 56
57use hir_expand::AstId; 57use hir_expand::AstId;
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/test_db.rs
index ff1f3fa75..047a27aaf 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/test_db.rs
@@ -12,8 +12,6 @@ use ra_db::{
12 12
13use crate::{db, debug::HirDebugHelper}; 13use crate::{db, debug::HirDebugHelper};
14 14
15pub const WORKSPACE: SourceRootId = SourceRootId(0);
16
17#[salsa::database( 15#[salsa::database(
18 ra_db::SourceDatabaseExtStorage, 16 ra_db::SourceDatabaseExtStorage,
19 ra_db::SourceDatabaseStorage, 17 ra_db::SourceDatabaseStorage,
@@ -24,14 +22,14 @@ pub const WORKSPACE: SourceRootId = SourceRootId(0);
24 db::HirDatabaseStorage 22 db::HirDatabaseStorage
25)] 23)]
26#[derive(Debug)] 24#[derive(Debug)]
27pub struct MockDatabase { 25pub struct TestDB {
28 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, 26 events: Mutex<Option<Vec<salsa::Event<TestDB>>>>,
29 runtime: salsa::Runtime<MockDatabase>, 27 runtime: salsa::Runtime<TestDB>,
30} 28}
31 29
32impl panic::RefUnwindSafe for MockDatabase {} 30impl panic::RefUnwindSafe for TestDB {}
33 31
34impl FileLoader for MockDatabase { 32impl FileLoader for TestDB {
35 fn file_text(&self, file_id: FileId) -> Arc<String> { 33 fn file_text(&self, file_id: FileId) -> Arc<String> {
36 FileLoaderDelegate(self).file_text(file_id) 34 FileLoaderDelegate(self).file_text(file_id)
37 } 35 }
@@ -48,7 +46,7 @@ impl FileLoader for MockDatabase {
48} 46}
49 47
50// FIXME: improve `WithFixture` to bring useful hir debugging back 48// FIXME: improve `WithFixture` to bring useful hir debugging back
51impl HirDebugHelper for MockDatabase { 49impl HirDebugHelper for TestDB {
52 fn crate_name(&self, _krate: CrateId) -> Option<String> { 50 fn crate_name(&self, _krate: CrateId) -> Option<String> {
53 None 51 None
54 } 52 }
@@ -58,7 +56,7 @@ impl HirDebugHelper for MockDatabase {
58 } 56 }
59} 57}
60 58
61impl MockDatabase { 59impl TestDB {
62 pub fn diagnostics(&self) -> String { 60 pub fn diagnostics(&self) -> String {
63 let mut buf = String::new(); 61 let mut buf = String::new();
64 let crate_graph = self.crate_graph(); 62 let crate_graph = self.crate_graph();
@@ -79,12 +77,12 @@ impl MockDatabase {
79 } 77 }
80} 78}
81 79
82impl salsa::Database for MockDatabase { 80impl salsa::Database for TestDB {
83 fn salsa_runtime(&self) -> &salsa::Runtime<MockDatabase> { 81 fn salsa_runtime(&self) -> &salsa::Runtime<TestDB> {
84 &self.runtime 82 &self.runtime
85 } 83 }
86 84
87 fn salsa_event(&self, event: impl Fn() -> salsa::Event<MockDatabase>) { 85 fn salsa_event(&self, event: impl Fn() -> salsa::Event<TestDB>) {
88 let mut events = self.events.lock(); 86 let mut events = self.events.lock();
89 if let Some(events) = &mut *events { 87 if let Some(events) = &mut *events {
90 events.push(event()); 88 events.push(event());
@@ -92,26 +90,25 @@ impl salsa::Database for MockDatabase {
92 } 90 }
93} 91}
94 92
95impl Default for MockDatabase { 93impl Default for TestDB {
96 fn default() -> MockDatabase { 94 fn default() -> TestDB {
97 let mut db = 95 let mut db = TestDB { events: Default::default(), runtime: salsa::Runtime::default() };
98 MockDatabase { events: Default::default(), runtime: salsa::Runtime::default() };
99 db.set_crate_graph(Default::default()); 96 db.set_crate_graph(Default::default());
100 db 97 db
101 } 98 }
102} 99}
103 100
104impl salsa::ParallelDatabase for MockDatabase { 101impl salsa::ParallelDatabase for TestDB {
105 fn snapshot(&self) -> salsa::Snapshot<MockDatabase> { 102 fn snapshot(&self) -> salsa::Snapshot<TestDB> {
106 salsa::Snapshot::new(MockDatabase { 103 salsa::Snapshot::new(TestDB {
107 events: Default::default(), 104 events: Default::default(),
108 runtime: self.runtime.snapshot(self), 105 runtime: self.runtime.snapshot(self),
109 }) 106 })
110 } 107 }
111} 108}
112 109
113impl MockDatabase { 110impl TestDB {
114 pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<MockDatabase>> { 111 pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<TestDB>> {
115 *self.events.lock() = Some(Vec::new()); 112 *self.events.lock() = Some(Vec::new());
116 f(); 113 f();
117 self.events.lock().take().unwrap() 114 self.events.lock().take().unwrap()
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 4af2fe0b4..e56b9356e 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -11,7 +11,7 @@ use ra_syntax::{
11use test_utils::covers; 11use test_utils::covers;
12 12
13use crate::{ 13use crate::{
14 expr::BodySourceMap, mock::MockDatabase, ty::display::HirDisplay, ty::InferenceResult, 14 expr::BodySourceMap, test_db::TestDB, ty::display::HirDisplay, ty::InferenceResult,
15 SourceAnalyzer, 15 SourceAnalyzer,
16}; 16};
17 17
@@ -24,7 +24,7 @@ mod coercion;
24 24
25#[test] 25#[test]
26fn cfg_impl_block() { 26fn cfg_impl_block() {
27 let (db, pos) = MockDatabase::with_position( 27 let (db, pos) = TestDB::with_position(
28 r#" 28 r#"
29//- /main.rs crate:main deps:foo cfg:test 29//- /main.rs crate:main deps:foo cfg:test
30use foo::S as T; 30use foo::S as T;
@@ -64,7 +64,7 @@ impl S {
64 64
65#[test] 65#[test]
66fn infer_await() { 66fn infer_await() {
67 let (db, pos) = MockDatabase::with_position( 67 let (db, pos) = TestDB::with_position(
68 r#" 68 r#"
69//- /main.rs crate:main deps:std 69//- /main.rs crate:main deps:std
70 70
@@ -95,7 +95,7 @@ mod future {
95 95
96#[test] 96#[test]
97fn infer_box() { 97fn infer_box() {
98 let (db, pos) = MockDatabase::with_position( 98 let (db, pos) = TestDB::with_position(
99 r#" 99 r#"
100//- /main.rs crate:main deps:std 100//- /main.rs crate:main deps:std
101 101
@@ -122,7 +122,7 @@ mod boxed {
122 122
123#[test] 123#[test]
124fn infer_adt_self() { 124fn infer_adt_self() {
125 let (db, pos) = MockDatabase::with_position( 125 let (db, pos) = TestDB::with_position(
126 r#" 126 r#"
127//- /main.rs 127//- /main.rs
128enum Nat { Succ(Self), Demo(Nat), Zero } 128enum Nat { Succ(Self), Demo(Nat), Zero }
@@ -141,7 +141,7 @@ fn test() {
141 141
142#[test] 142#[test]
143fn infer_try() { 143fn infer_try() {
144 let (db, pos) = MockDatabase::with_position( 144 let (db, pos) = TestDB::with_position(
145 r#" 145 r#"
146//- /main.rs crate:main deps:std 146//- /main.rs crate:main deps:std
147 147
@@ -181,7 +181,7 @@ mod result {
181 181
182#[test] 182#[test]
183fn infer_for_loop() { 183fn infer_for_loop() {
184 let (db, pos) = MockDatabase::with_position( 184 let (db, pos) = TestDB::with_position(
185 r#" 185 r#"
186//- /main.rs crate:main deps:std 186//- /main.rs crate:main deps:std
187 187
@@ -223,7 +223,7 @@ mod collections {
223#[test] 223#[test]
224fn infer_while_let() { 224fn infer_while_let() {
225 covers!(infer_while_let); 225 covers!(infer_while_let);
226 let (db, pos) = MockDatabase::with_position( 226 let (db, pos) = TestDB::with_position(
227 r#" 227 r#"
228//- /main.rs 228//- /main.rs
229enum Option<T> { Some(T), None } 229enum Option<T> { Some(T), None }
@@ -2484,7 +2484,7 @@ pub fn main_loop() {
2484 2484
2485#[test] 2485#[test]
2486fn cross_crate_associated_method_call() { 2486fn cross_crate_associated_method_call() {
2487 let (db, pos) = MockDatabase::with_position( 2487 let (db, pos) = TestDB::with_position(
2488 r#" 2488 r#"
2489//- /main.rs crate:main deps:other_crate 2489//- /main.rs crate:main deps:other_crate
2490fn test() { 2490fn test() {
@@ -3378,7 +3378,7 @@ fn test() { S.foo()<|>; }
3378 3378
3379#[test] 3379#[test]
3380fn infer_macro_with_dollar_crate_is_correct_in_expr() { 3380fn infer_macro_with_dollar_crate_is_correct_in_expr() {
3381 let (db, pos) = MockDatabase::with_position( 3381 let (db, pos) = TestDB::with_position(
3382 r#" 3382 r#"
3383//- /main.rs crate:main deps:foo 3383//- /main.rs crate:main deps:foo
3384fn test() { 3384fn test() {
@@ -3482,7 +3482,7 @@ fn test() { (&S).foo()<|>; }
3482 3482
3483#[test] 3483#[test]
3484fn method_resolution_trait_from_prelude() { 3484fn method_resolution_trait_from_prelude() {
3485 let (db, pos) = MockDatabase::with_position( 3485 let (db, pos) = TestDB::with_position(
3486 r#" 3486 r#"
3487//- /main.rs crate:main deps:other_crate 3487//- /main.rs crate:main deps:other_crate
3488struct S; 3488struct S;
@@ -4651,7 +4651,7 @@ fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
4651 assert_eq!(t, "{unknown}"); 4651 assert_eq!(t, "{unknown}");
4652} 4652}
4653 4653
4654fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { 4654fn type_at_pos(db: &TestDB, pos: FilePosition) -> String {
4655 let file = db.parse(pos.file_id).ok().unwrap(); 4655 let file = db.parse(pos.file_id).ok().unwrap();
4656 let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); 4656 let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap();
4657 let analyzer = SourceAnalyzer::new(db, pos.file_id, expr.syntax(), Some(pos.offset)); 4657 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 {
4660} 4660}
4661 4661
4662fn type_at(content: &str) -> String { 4662fn type_at(content: &str) -> String {
4663 let (db, file_pos) = MockDatabase::with_position(content); 4663 let (db, file_pos) = TestDB::with_position(content);
4664 type_at_pos(&db, file_pos) 4664 type_at_pos(&db, file_pos)
4665} 4665}
4666 4666
4667fn infer(content: &str) -> String { 4667fn infer(content: &str) -> String {
4668 let (db, file_id) = MockDatabase::with_single_file(content); 4668 let (db, file_id) = TestDB::with_single_file(content);
4669 let source_file = db.parse(file_id).ok().unwrap(); 4669 let source_file = db.parse(file_id).ok().unwrap();
4670 4670
4671 let mut acc = String::new(); 4671 let mut acc = String::new();
@@ -4748,7 +4748,7 @@ fn ellipsize(mut text: String, max_len: usize) -> String {
4748 4748
4749#[test] 4749#[test]
4750fn typing_whitespace_inside_a_function_should_not_invalidate_types() { 4750fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
4751 let (mut db, pos) = MockDatabase::with_position( 4751 let (mut db, pos) = TestDB::with_position(
4752 " 4752 "
4753 //- /lib.rs 4753 //- /lib.rs
4754 fn foo() -> i32 { 4754 fn foo() -> i32 {
@@ -4788,7 +4788,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
4788 4788
4789#[test] 4789#[test]
4790fn no_such_field_diagnostics() { 4790fn no_such_field_diagnostics() {
4791 let diagnostics = MockDatabase::with_files( 4791 let diagnostics = TestDB::with_files(
4792 r" 4792 r"
4793 //- /lib.rs 4793 //- /lib.rs
4794 struct S { foo: i32, bar: () } 4794 struct S { foo: i32, bar: () }