diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/mock_analysis.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index 58fafecab..981bdf924 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs | |||
@@ -3,7 +3,7 @@ use std::{str::FromStr, sync::Arc}; | |||
3 | 3 | ||
4 | use ra_cfg::CfgOptions; | 4 | use ra_cfg::CfgOptions; |
5 | use ra_db::{CrateName, Env, FileSet, SourceRoot, VfsPath}; | 5 | use ra_db::{CrateName, Env, FileSet, SourceRoot, VfsPath}; |
6 | use test_utils::{extract_offset, extract_range, parse_fixture, FixtureEntry, CURSOR_MARKER}; | 6 | use test_utils::{extract_offset, extract_range, Fixture, CURSOR_MARKER}; |
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange, | 9 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange, |
@@ -12,7 +12,7 @@ use crate::{ | |||
12 | #[derive(Debug)] | 12 | #[derive(Debug)] |
13 | enum MockFileData { | 13 | enum MockFileData { |
14 | Plain { path: String, content: String }, | 14 | Plain { path: String, content: String }, |
15 | Fixture(FixtureEntry), | 15 | Fixture(Fixture), |
16 | } | 16 | } |
17 | 17 | ||
18 | impl MockFileData { | 18 | impl MockFileData { |
@@ -25,7 +25,7 @@ impl MockFileData { | |||
25 | fn path(&self) -> &str { | 25 | fn path(&self) -> &str { |
26 | match self { | 26 | match self { |
27 | MockFileData::Plain { path, .. } => path.as_str(), | 27 | MockFileData::Plain { path, .. } => path.as_str(), |
28 | MockFileData::Fixture(f) => f.meta.path(), | 28 | MockFileData::Fixture(f) => f.path.as_str(), |
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
@@ -39,7 +39,10 @@ impl MockFileData { | |||
39 | fn cfg_options(&self) -> CfgOptions { | 39 | fn cfg_options(&self) -> CfgOptions { |
40 | match self { | 40 | match self { |
41 | MockFileData::Fixture(f) => { | 41 | MockFileData::Fixture(f) => { |
42 | f.meta.cfg_options().map_or_else(Default::default, |o| o.clone()) | 42 | let mut cfg = CfgOptions::default(); |
43 | f.cfg_atoms.iter().for_each(|it| cfg.insert_atom(it.into())); | ||
44 | f.cfg_key_values.iter().for_each(|(k, v)| cfg.insert_key_value(k.into(), v.into())); | ||
45 | cfg | ||
43 | } | 46 | } |
44 | _ => CfgOptions::default(), | 47 | _ => CfgOptions::default(), |
45 | } | 48 | } |
@@ -48,7 +51,7 @@ impl MockFileData { | |||
48 | fn edition(&self) -> Edition { | 51 | fn edition(&self) -> Edition { |
49 | match self { | 52 | match self { |
50 | MockFileData::Fixture(f) => { | 53 | MockFileData::Fixture(f) => { |
51 | f.meta.edition().map_or(Edition::Edition2018, |v| Edition::from_str(v).unwrap()) | 54 | f.edition.as_ref().map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()) |
52 | } | 55 | } |
53 | _ => Edition::Edition2018, | 56 | _ => Edition::Edition2018, |
54 | } | 57 | } |
@@ -56,14 +59,14 @@ impl MockFileData { | |||
56 | 59 | ||
57 | fn env(&self) -> Env { | 60 | fn env(&self) -> Env { |
58 | match self { | 61 | match self { |
59 | MockFileData::Fixture(f) => Env::from(f.meta.env()), | 62 | MockFileData::Fixture(f) => Env::from(f.env.iter()), |
60 | _ => Env::default(), | 63 | _ => Env::default(), |
61 | } | 64 | } |
62 | } | 65 | } |
63 | } | 66 | } |
64 | 67 | ||
65 | impl From<FixtureEntry> for MockFileData { | 68 | impl From<Fixture> for MockFileData { |
66 | fn from(fixture: FixtureEntry) -> Self { | 69 | fn from(fixture: Fixture) -> Self { |
67 | Self::Fixture(fixture) | 70 | Self::Fixture(fixture) |
68 | } | 71 | } |
69 | } | 72 | } |
@@ -91,7 +94,7 @@ impl MockAnalysis { | |||
91 | /// ``` | 94 | /// ``` |
92 | pub fn with_files(fixture: &str) -> MockAnalysis { | 95 | pub fn with_files(fixture: &str) -> MockAnalysis { |
93 | let mut res = MockAnalysis::new(); | 96 | let mut res = MockAnalysis::new(); |
94 | for entry in parse_fixture(fixture) { | 97 | for entry in Fixture::parse(fixture) { |
95 | res.add_file_fixture(entry); | 98 | res.add_file_fixture(entry); |
96 | } | 99 | } |
97 | res | 100 | res |
@@ -102,7 +105,7 @@ impl MockAnalysis { | |||
102 | pub fn with_files_and_position(fixture: &str) -> (MockAnalysis, FilePosition) { | 105 | pub fn with_files_and_position(fixture: &str) -> (MockAnalysis, FilePosition) { |
103 | let mut position = None; | 106 | let mut position = None; |
104 | let mut res = MockAnalysis::new(); | 107 | let mut res = MockAnalysis::new(); |
105 | for entry in parse_fixture(fixture) { | 108 | for entry in Fixture::parse(fixture) { |
106 | if entry.text.contains(CURSOR_MARKER) { | 109 | if entry.text.contains(CURSOR_MARKER) { |
107 | assert!(position.is_none(), "only one marker (<|>) per fixture is allowed"); | 110 | assert!(position.is_none(), "only one marker (<|>) per fixture is allowed"); |
108 | position = Some(res.add_file_fixture_with_position(entry)); | 111 | position = Some(res.add_file_fixture_with_position(entry)); |
@@ -114,13 +117,13 @@ impl MockAnalysis { | |||
114 | (res, position) | 117 | (res, position) |
115 | } | 118 | } |
116 | 119 | ||
117 | pub fn add_file_fixture(&mut self, fixture: FixtureEntry) -> FileId { | 120 | pub fn add_file_fixture(&mut self, fixture: Fixture) -> FileId { |
118 | let file_id = self.next_id(); | 121 | let file_id = self.next_id(); |
119 | self.files.push(MockFileData::from(fixture)); | 122 | self.files.push(MockFileData::from(fixture)); |
120 | file_id | 123 | file_id |
121 | } | 124 | } |
122 | 125 | ||
123 | pub fn add_file_fixture_with_position(&mut self, mut fixture: FixtureEntry) -> FilePosition { | 126 | pub fn add_file_fixture_with_position(&mut self, mut fixture: Fixture) -> FilePosition { |
124 | let (offset, text) = extract_offset(&fixture.text); | 127 | let (offset, text) = extract_offset(&fixture.text); |
125 | fixture.text = text; | 128 | fixture.text = text; |
126 | let file_id = self.next_id(); | 129 | let file_id = self.next_id(); |