diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/src/doc_tests.rs | 4 | ||||
-rw-r--r-- | crates/ra_assists/src/lib.rs | 32 | ||||
-rw-r--r-- | crates/ra_hir/src/expr/scope.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 4 | ||||
-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.rs | 32 |
6 files changed, 57 insertions, 60 deletions
diff --git a/crates/ra_assists/src/doc_tests.rs b/crates/ra_assists/src/doc_tests.rs index 43194037e..2500a5ab7 100644 --- a/crates/ra_assists/src/doc_tests.rs +++ b/crates/ra_assists/src/doc_tests.rs | |||
@@ -5,13 +5,13 @@ | |||
5 | 5 | ||
6 | mod generated; | 6 | mod generated; |
7 | 7 | ||
8 | use hir::mock::MockDatabase; | 8 | use hir::mock::TestDB; |
9 | use ra_db::{fixture::WithFixture, FileRange}; | 9 | use ra_db::{fixture::WithFixture, FileRange}; |
10 | use test_utils::{assert_eq_text, extract_range_or_offset}; | 10 | use test_utils::{assert_eq_text, extract_range_or_offset}; |
11 | 11 | ||
12 | fn check(assist_id: &str, before: &str, after: &str) { | 12 | fn check(assist_id: &str, before: &str, after: &str) { |
13 | let (selection, before) = extract_range_or_offset(before); | 13 | let (selection, before) = extract_range_or_offset(before); |
14 | let (db, file_id) = MockDatabase::with_single_file(&before); | 14 | let (db, file_id) = TestDB::with_single_file(&before); |
15 | let frange = FileRange { file_id, range: selection.into() }; | 15 | let frange = FileRange { file_id, range: selection.into() }; |
16 | 16 | ||
17 | let (_assist_id, action) = crate::assists(&db, frange) | 17 | let (_assist_id, action) = crate::assists(&db, frange) |
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 13db37d29..85fb72395 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs | |||
@@ -146,7 +146,7 @@ mod assists { | |||
146 | 146 | ||
147 | #[cfg(test)] | 147 | #[cfg(test)] |
148 | mod helpers { | 148 | mod helpers { |
149 | use hir::mock::MockDatabase; | 149 | use hir::mock::TestDB; |
150 | use ra_db::{fixture::WithFixture, FileRange}; | 150 | use ra_db::{fixture::WithFixture, FileRange}; |
151 | use ra_syntax::TextRange; | 151 | use ra_syntax::TextRange; |
152 | use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range}; | 152 | use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range}; |
@@ -154,12 +154,12 @@ mod helpers { | |||
154 | use crate::{Assist, AssistCtx}; | 154 | use crate::{Assist, AssistCtx}; |
155 | 155 | ||
156 | pub(crate) fn check_assist( | 156 | pub(crate) fn check_assist( |
157 | assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>, | 157 | assist: fn(AssistCtx<TestDB>) -> Option<Assist>, |
158 | before: &str, | 158 | before: &str, |
159 | after: &str, | 159 | after: &str, |
160 | ) { | 160 | ) { |
161 | let (before_cursor_pos, before) = extract_offset(before); | 161 | let (before_cursor_pos, before) = extract_offset(before); |
162 | let (db, file_id) = MockDatabase::with_single_file(&before); | 162 | let (db, file_id) = TestDB::with_single_file(&before); |
163 | let frange = | 163 | let frange = |
164 | FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; | 164 | FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; |
165 | let assist = | 165 | let assist = |
@@ -182,12 +182,12 @@ mod helpers { | |||
182 | } | 182 | } |
183 | 183 | ||
184 | pub(crate) fn check_assist_range( | 184 | pub(crate) fn check_assist_range( |
185 | assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>, | 185 | assist: fn(AssistCtx<TestDB>) -> Option<Assist>, |
186 | before: &str, | 186 | before: &str, |
187 | after: &str, | 187 | after: &str, |
188 | ) { | 188 | ) { |
189 | let (range, before) = extract_range(before); | 189 | let (range, before) = extract_range(before); |
190 | let (db, file_id) = MockDatabase::with_single_file(&before); | 190 | let (db, file_id) = TestDB::with_single_file(&before); |
191 | let frange = FileRange { file_id, range }; | 191 | let frange = FileRange { file_id, range }; |
192 | let assist = | 192 | let assist = |
193 | AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable"); | 193 | AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable"); |
@@ -204,12 +204,12 @@ mod helpers { | |||
204 | } | 204 | } |
205 | 205 | ||
206 | pub(crate) fn check_assist_target( | 206 | pub(crate) fn check_assist_target( |
207 | assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>, | 207 | assist: fn(AssistCtx<TestDB>) -> Option<Assist>, |
208 | before: &str, | 208 | before: &str, |
209 | target: &str, | 209 | target: &str, |
210 | ) { | 210 | ) { |
211 | let (before_cursor_pos, before) = extract_offset(before); | 211 | let (before_cursor_pos, before) = extract_offset(before); |
212 | let (db, file_id) = MockDatabase::with_single_file(&before); | 212 | let (db, file_id) = TestDB::with_single_file(&before); |
213 | let frange = | 213 | let frange = |
214 | FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; | 214 | FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; |
215 | let assist = | 215 | let assist = |
@@ -224,12 +224,12 @@ mod helpers { | |||
224 | } | 224 | } |
225 | 225 | ||
226 | pub(crate) fn check_assist_range_target( | 226 | pub(crate) fn check_assist_range_target( |
227 | assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>, | 227 | assist: fn(AssistCtx<TestDB>) -> Option<Assist>, |
228 | before: &str, | 228 | before: &str, |
229 | target: &str, | 229 | target: &str, |
230 | ) { | 230 | ) { |
231 | let (range, before) = extract_range(before); | 231 | let (range, before) = extract_range(before); |
232 | let (db, file_id) = MockDatabase::with_single_file(&before); | 232 | let (db, file_id) = TestDB::with_single_file(&before); |
233 | let frange = FileRange { file_id, range }; | 233 | let frange = FileRange { file_id, range }; |
234 | let assist = | 234 | let assist = |
235 | AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable"); | 235 | AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable"); |
@@ -243,11 +243,11 @@ mod helpers { | |||
243 | } | 243 | } |
244 | 244 | ||
245 | pub(crate) fn check_assist_not_applicable( | 245 | pub(crate) fn check_assist_not_applicable( |
246 | assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>, | 246 | assist: fn(AssistCtx<TestDB>) -> Option<Assist>, |
247 | before: &str, | 247 | before: &str, |
248 | ) { | 248 | ) { |
249 | let (before_cursor_pos, before) = extract_offset(before); | 249 | let (before_cursor_pos, before) = extract_offset(before); |
250 | let (db, file_id) = MockDatabase::with_single_file(&before); | 250 | let (db, file_id) = TestDB::with_single_file(&before); |
251 | let frange = | 251 | let frange = |
252 | FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; | 252 | FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; |
253 | let assist = AssistCtx::with_ctx(&db, frange, true, assist); | 253 | let assist = AssistCtx::with_ctx(&db, frange, true, assist); |
@@ -255,11 +255,11 @@ mod helpers { | |||
255 | } | 255 | } |
256 | 256 | ||
257 | pub(crate) fn check_assist_range_not_applicable( | 257 | pub(crate) fn check_assist_range_not_applicable( |
258 | assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>, | 258 | assist: fn(AssistCtx<TestDB>) -> Option<Assist>, |
259 | before: &str, | 259 | before: &str, |
260 | ) { | 260 | ) { |
261 | let (range, before) = extract_range(before); | 261 | let (range, before) = extract_range(before); |
262 | let (db, file_id) = MockDatabase::with_single_file(&before); | 262 | let (db, file_id) = TestDB::with_single_file(&before); |
263 | let frange = FileRange { file_id, range }; | 263 | let frange = FileRange { file_id, range }; |
264 | let assist = AssistCtx::with_ctx(&db, frange, true, assist); | 264 | let assist = AssistCtx::with_ctx(&db, frange, true, assist); |
265 | assert!(assist.is_none()); | 265 | assert!(assist.is_none()); |
@@ -268,7 +268,7 @@ mod helpers { | |||
268 | 268 | ||
269 | #[cfg(test)] | 269 | #[cfg(test)] |
270 | mod tests { | 270 | mod tests { |
271 | use hir::mock::MockDatabase; | 271 | use hir::mock::TestDB; |
272 | use ra_db::{fixture::WithFixture, FileRange}; | 272 | use ra_db::{fixture::WithFixture, FileRange}; |
273 | use ra_syntax::TextRange; | 273 | use ra_syntax::TextRange; |
274 | use test_utils::{extract_offset, extract_range}; | 274 | use test_utils::{extract_offset, extract_range}; |
@@ -277,7 +277,7 @@ mod tests { | |||
277 | fn assist_order_field_struct() { | 277 | fn assist_order_field_struct() { |
278 | let before = "struct Foo { <|>bar: u32 }"; | 278 | let before = "struct Foo { <|>bar: u32 }"; |
279 | let (before_cursor_pos, before) = extract_offset(before); | 279 | let (before_cursor_pos, before) = extract_offset(before); |
280 | let (db, file_id) = MockDatabase::with_single_file(&before); | 280 | let (db, file_id) = TestDB::with_single_file(&before); |
281 | let frange = | 281 | let frange = |
282 | FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; | 282 | FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; |
283 | let assists = super::assists(&db, frange); | 283 | let assists = super::assists(&db, frange); |
@@ -298,7 +298,7 @@ mod tests { | |||
298 | } | 298 | } |
299 | }"; | 299 | }"; |
300 | let (range, before) = extract_range(before); | 300 | let (range, before) = extract_range(before); |
301 | let (db, file_id) = MockDatabase::with_single_file(&before); | 301 | let (db, file_id) = TestDB::with_single_file(&before); |
302 | let frange = FileRange { file_id, range }; | 302 | let frange = FileRange { file_id, range }; |
303 | let assists = super::assists(&db, frange); | 303 | let assists = super::assists(&db, frange); |
304 | let mut assists = assists.iter(); | 304 | let mut assists = assists.iter(); |
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 { | |||
29 | pub mod debug; | 29 | pub mod debug; |
30 | 30 | ||
31 | pub mod db; | 31 | pub mod db; |
32 | #[macro_use] | ||
33 | pub mod mock; | ||
34 | pub mod source_binder; | 32 | pub mod source_binder; |
35 | 33 | ||
36 | mod ids; | 34 | mod ids; |
@@ -52,6 +50,8 @@ mod code_model; | |||
52 | pub mod from_source; | 50 | pub mod from_source; |
53 | 51 | ||
54 | #[cfg(test)] | 52 | #[cfg(test)] |
53 | mod test_db; | ||
54 | #[cfg(test)] | ||
55 | mod marks; | 55 | mod marks; |
56 | 56 | ||
57 | use hir_expand::AstId; | 57 | use 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 | ||
13 | use crate::{db, debug::HirDebugHelper}; | 13 | use crate::{db, debug::HirDebugHelper}; |
14 | 14 | ||
15 | pub 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)] |
27 | pub struct MockDatabase { | 25 | pub 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 | ||
32 | impl panic::RefUnwindSafe for MockDatabase {} | 30 | impl panic::RefUnwindSafe for TestDB {} |
33 | 31 | ||
34 | impl FileLoader for MockDatabase { | 32 | impl 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 |
51 | impl HirDebugHelper for MockDatabase { | 49 | impl 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 | ||
61 | impl MockDatabase { | 59 | impl 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 | ||
82 | impl salsa::Database for MockDatabase { | 80 | impl 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 | ||
95 | impl Default for MockDatabase { | 93 | impl 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 | ||
104 | impl salsa::ParallelDatabase for MockDatabase { | 101 | impl 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 | ||
113 | impl MockDatabase { | 110 | impl 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::{ | |||
11 | use test_utils::covers; | 11 | use test_utils::covers; |
12 | 12 | ||
13 | use crate::{ | 13 | use 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] |
26 | fn cfg_impl_block() { | 26 | fn 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 |
30 | use foo::S as T; | 30 | use foo::S as T; |
@@ -64,7 +64,7 @@ impl S { | |||
64 | 64 | ||
65 | #[test] | 65 | #[test] |
66 | fn infer_await() { | 66 | fn 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] |
97 | fn infer_box() { | 97 | fn 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] |
124 | fn infer_adt_self() { | 124 | fn 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 |
128 | enum Nat { Succ(Self), Demo(Nat), Zero } | 128 | enum Nat { Succ(Self), Demo(Nat), Zero } |
@@ -141,7 +141,7 @@ fn test() { | |||
141 | 141 | ||
142 | #[test] | 142 | #[test] |
143 | fn infer_try() { | 143 | fn 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] |
183 | fn infer_for_loop() { | 183 | fn 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] |
224 | fn infer_while_let() { | 224 | fn 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 |
229 | enum Option<T> { Some(T), None } | 229 | enum Option<T> { Some(T), None } |
@@ -2484,7 +2484,7 @@ pub fn main_loop() { | |||
2484 | 2484 | ||
2485 | #[test] | 2485 | #[test] |
2486 | fn cross_crate_associated_method_call() { | 2486 | fn 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 |
2490 | fn test() { | 2490 | fn test() { |
@@ -3378,7 +3378,7 @@ fn test() { S.foo()<|>; } | |||
3378 | 3378 | ||
3379 | #[test] | 3379 | #[test] |
3380 | fn infer_macro_with_dollar_crate_is_correct_in_expr() { | 3380 | fn 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 |
3384 | fn test() { | 3384 | fn test() { |
@@ -3482,7 +3482,7 @@ fn test() { (&S).foo()<|>; } | |||
3482 | 3482 | ||
3483 | #[test] | 3483 | #[test] |
3484 | fn method_resolution_trait_from_prelude() { | 3484 | fn 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 |
3488 | struct S; | 3488 | struct 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 | ||
4654 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | 4654 | fn 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 | ||
4662 | fn type_at(content: &str) -> String { | 4662 | fn 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 | ||
4667 | fn infer(content: &str) -> String { | 4667 | fn 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] |
4750 | fn typing_whitespace_inside_a_function_should_not_invalidate_types() { | 4750 | fn 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] |
4790 | fn no_such_field_diagnostics() { | 4790 | fn 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: () } |