diff options
Diffstat (limited to 'crates/ra_db')
-rw-r--r-- | crates/ra_db/src/fixture.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index 3959d7efe..541815fe7 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs | |||
@@ -61,7 +61,7 @@ use std::{str::FromStr, sync::Arc}; | |||
61 | 61 | ||
62 | use ra_cfg::CfgOptions; | 62 | use ra_cfg::CfgOptions; |
63 | use rustc_hash::FxHashMap; | 63 | use rustc_hash::FxHashMap; |
64 | use test_utils::{extract_offset, Fixture, CURSOR_MARKER}; | 64 | use test_utils::{extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER}; |
65 | use vfs::{file_set::FileSet, VfsPath}; | 65 | use vfs::{file_set::FileSet, VfsPath}; |
66 | 66 | ||
67 | use crate::{ | 67 | use crate::{ |
@@ -86,9 +86,19 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { | |||
86 | } | 86 | } |
87 | 87 | ||
88 | fn with_position(ra_fixture: &str) -> (Self, FilePosition) { | 88 | fn with_position(ra_fixture: &str) -> (Self, FilePosition) { |
89 | let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture); | ||
90 | let offset = match range_or_offset { | ||
91 | RangeOrOffset::Range(_) => panic!(), | ||
92 | RangeOrOffset::Offset(it) => it, | ||
93 | }; | ||
94 | (db, FilePosition { file_id, offset }) | ||
95 | } | ||
96 | |||
97 | fn with_range_or_offset(ra_fixture: &str) -> (Self, FileId, RangeOrOffset) { | ||
89 | let mut db = Self::default(); | 98 | let mut db = Self::default(); |
90 | let (pos, _) = with_files(&mut db, ra_fixture); | 99 | let (pos, _) = with_files(&mut db, ra_fixture); |
91 | (db, pos.unwrap()) | 100 | let (file_id, range_or_offset) = pos.unwrap(); |
101 | (db, file_id, range_or_offset) | ||
92 | } | 102 | } |
93 | 103 | ||
94 | fn test_crate(&self) -> CrateId { | 104 | fn test_crate(&self) -> CrateId { |
@@ -151,7 +161,7 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId | |||
151 | fn with_files( | 161 | fn with_files( |
152 | db: &mut dyn SourceDatabaseExt, | 162 | db: &mut dyn SourceDatabaseExt, |
153 | fixture: &str, | 163 | fixture: &str, |
154 | ) -> (Option<FilePosition>, Vec<FileId>) { | 164 | ) -> (Option<(FileId, RangeOrOffset)>, Vec<FileId>) { |
155 | let fixture = Fixture::parse(fixture); | 165 | let fixture = Fixture::parse(fixture); |
156 | 166 | ||
157 | let mut files = Vec::new(); | 167 | let mut files = Vec::new(); |
@@ -193,9 +203,9 @@ fn with_files( | |||
193 | } | 203 | } |
194 | 204 | ||
195 | let text = if entry.text.contains(CURSOR_MARKER) { | 205 | let text = if entry.text.contains(CURSOR_MARKER) { |
196 | let (offset, text) = extract_offset(&entry.text); | 206 | let (range_or_offset, text) = extract_range_or_offset(&entry.text); |
197 | assert!(file_position.is_none()); | 207 | assert!(file_position.is_none()); |
198 | file_position = Some(FilePosition { file_id, offset }); | 208 | file_position = Some((file_id, range_or_offset)); |
199 | text.to_string() | 209 | text.to_string() |
200 | } else { | 210 | } else { |
201 | entry.text.to_string() | 211 | entry.text.to_string() |