diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_db/src/fixture.rs | 30 | ||||
-rw-r--r-- | crates/ra_ide/src/mock_analysis.rs | 16 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/support.rs | 2 | ||||
-rw-r--r-- | crates/test_utils/src/fixture.rs | 62 | ||||
-rw-r--r-- | crates/test_utils/src/lib.rs | 2 |
5 files changed, 27 insertions, 85 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index bf897baff..7f006487a 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, parse_fixture, parse_single_fixture, FixtureMeta, CURSOR_MARKER}; | 64 | use test_utils::{extract_offset, parse_fixture, parse_single_fixture, CURSOR_MARKER}; |
65 | use vfs::{file_set::FileSet, VfsPath}; | 65 | use vfs::{file_set::FileSet, VfsPath}; |
66 | 66 | ||
67 | use crate::{ | 67 | use crate::{ |
@@ -243,20 +243,18 @@ struct FileMeta { | |||
243 | env: Env, | 243 | env: Env, |
244 | } | 244 | } |
245 | 245 | ||
246 | impl From<&FixtureMeta> for ParsedMeta { | 246 | impl From<&test_utils::FileMeta> for ParsedMeta { |
247 | fn from(meta: &FixtureMeta) -> Self { | 247 | fn from(f: &test_utils::FileMeta) -> Self { |
248 | match meta { | 248 | Self::File(FileMeta { |
249 | FixtureMeta::File(f) => Self::File(FileMeta { | 249 | path: f.path.to_owned(), |
250 | path: f.path.to_owned(), | 250 | krate: f.crate_name.to_owned(), |
251 | krate: f.crate_name.to_owned(), | 251 | deps: f.deps.to_owned(), |
252 | deps: f.deps.to_owned(), | 252 | cfg: f.cfg.to_owned(), |
253 | cfg: f.cfg.to_owned(), | 253 | edition: f |
254 | edition: f | 254 | .edition |
255 | .edition | 255 | .as_ref() |
256 | .as_ref() | 256 | .map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()), |
257 | .map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()), | 257 | env: Env::from(f.env.iter()), |
258 | env: Env::from(f.env.iter()), | 258 | }) |
259 | }), | ||
260 | } | ||
261 | } | 259 | } |
262 | } | 260 | } |
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index 58fafecab..c0840c6ea 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs | |||
@@ -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.meta.path.as_str(), |
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
@@ -38,25 +38,25 @@ impl MockFileData { | |||
38 | 38 | ||
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) => f.meta.cfg.clone(), |
42 | f.meta.cfg_options().map_or_else(Default::default, |o| o.clone()) | ||
43 | } | ||
44 | _ => CfgOptions::default(), | 42 | _ => CfgOptions::default(), |
45 | } | 43 | } |
46 | } | 44 | } |
47 | 45 | ||
48 | fn edition(&self) -> Edition { | 46 | fn edition(&self) -> Edition { |
49 | match self { | 47 | match self { |
50 | MockFileData::Fixture(f) => { | 48 | MockFileData::Fixture(f) => f |
51 | f.meta.edition().map_or(Edition::Edition2018, |v| Edition::from_str(v).unwrap()) | 49 | .meta |
52 | } | 50 | .edition |
51 | .as_ref() | ||
52 | .map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()), | ||
53 | _ => Edition::Edition2018, | 53 | _ => Edition::Edition2018, |
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
57 | fn env(&self) -> Env { | 57 | fn env(&self) -> Env { |
58 | match self { | 58 | match self { |
59 | MockFileData::Fixture(f) => Env::from(f.meta.env()), | 59 | MockFileData::Fixture(f) => Env::from(f.meta.env.iter()), |
60 | _ => Env::default(), | 60 | _ => Env::default(), |
61 | } | 61 | } |
62 | } | 62 | } |
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs index bb8585355..3bbfb43aa 100644 --- a/crates/rust-analyzer/tests/heavy_tests/support.rs +++ b/crates/rust-analyzer/tests/heavy_tests/support.rs | |||
@@ -69,7 +69,7 @@ impl<'a> Project<'a> { | |||
69 | let mut paths = vec![]; | 69 | let mut paths = vec![]; |
70 | 70 | ||
71 | for entry in parse_fixture(self.fixture) { | 71 | for entry in parse_fixture(self.fixture) { |
72 | let path = tmp_dir.path().join(&entry.meta.path()['/'.len_utf8()..]); | 72 | let path = tmp_dir.path().join(&entry.meta.path['/'.len_utf8()..]); |
73 | fs::create_dir_all(path.parent().unwrap()).unwrap(); | 73 | fs::create_dir_all(path.parent().unwrap()).unwrap(); |
74 | fs::write(path.as_path(), entry.text.as_bytes()).unwrap(); | 74 | fs::write(path.as_path(), entry.text.as_bytes()).unwrap(); |
75 | paths.push((path, entry.text)); | 75 | paths.push((path, entry.text)); |
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index 0dbeb01b1..a07d057e1 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs | |||
@@ -4,16 +4,11 @@ use stdx::split1; | |||
4 | 4 | ||
5 | #[derive(Debug, Eq, PartialEq)] | 5 | #[derive(Debug, Eq, PartialEq)] |
6 | pub struct FixtureEntry { | 6 | pub struct FixtureEntry { |
7 | pub meta: FixtureMeta, | 7 | pub meta: FileMeta, |
8 | pub text: String, | 8 | pub text: String, |
9 | } | 9 | } |
10 | 10 | ||
11 | #[derive(Debug, Eq, PartialEq)] | 11 | #[derive(Debug, Eq, PartialEq)] |
12 | pub enum FixtureMeta { | ||
13 | File(FileMeta), | ||
14 | } | ||
15 | |||
16 | #[derive(Debug, Eq, PartialEq)] | ||
17 | pub struct FileMeta { | 12 | pub struct FileMeta { |
18 | pub path: String, | 13 | pub path: String, |
19 | pub crate_name: Option<String>, | 14 | pub crate_name: Option<String>, |
@@ -23,57 +18,6 @@ pub struct FileMeta { | |||
23 | pub env: FxHashMap<String, String>, | 18 | pub env: FxHashMap<String, String>, |
24 | } | 19 | } |
25 | 20 | ||
26 | impl FixtureMeta { | ||
27 | pub fn path(&self) -> &str { | ||
28 | match self { | ||
29 | FixtureMeta::File(f) => &f.path, | ||
30 | } | ||
31 | } | ||
32 | |||
33 | pub fn crate_name(&self) -> Option<&String> { | ||
34 | match self { | ||
35 | FixtureMeta::File(f) => f.crate_name.as_ref(), | ||
36 | } | ||
37 | } | ||
38 | |||
39 | pub fn cfg_options(&self) -> Option<&CfgOptions> { | ||
40 | match self { | ||
41 | FixtureMeta::File(f) => Some(&f.cfg), | ||
42 | } | ||
43 | } | ||
44 | |||
45 | pub fn edition(&self) -> Option<&String> { | ||
46 | match self { | ||
47 | FixtureMeta::File(f) => f.edition.as_ref(), | ||
48 | } | ||
49 | } | ||
50 | |||
51 | pub fn env(&self) -> impl Iterator<Item = (&String, &String)> { | ||
52 | struct EnvIter<'a> { | ||
53 | iter: Option<std::collections::hash_map::Iter<'a, String, String>>, | ||
54 | } | ||
55 | |||
56 | impl<'a> EnvIter<'a> { | ||
57 | fn new(meta: &'a FixtureMeta) -> Self { | ||
58 | Self { | ||
59 | iter: match meta { | ||
60 | FixtureMeta::File(f) => Some(f.env.iter()), | ||
61 | }, | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | |||
66 | impl<'a> Iterator for EnvIter<'a> { | ||
67 | type Item = (&'a String, &'a String); | ||
68 | fn next(&mut self) -> Option<Self::Item> { | ||
69 | self.iter.as_mut().and_then(|i| i.next()) | ||
70 | } | ||
71 | } | ||
72 | |||
73 | EnvIter::new(self) | ||
74 | } | ||
75 | } | ||
76 | |||
77 | /// Same as `parse_fixture`, except it allow empty fixture | 21 | /// Same as `parse_fixture`, except it allow empty fixture |
78 | pub fn parse_single_fixture(ra_fixture: &str) -> Option<FixtureEntry> { | 22 | pub fn parse_single_fixture(ra_fixture: &str) -> Option<FixtureEntry> { |
79 | if !ra_fixture.lines().any(|it| it.trim_start().starts_with("//-")) { | 23 | if !ra_fixture.lines().any(|it| it.trim_start().starts_with("//-")) { |
@@ -137,7 +81,7 @@ The offending line: {:?}"#, | |||
137 | } | 81 | } |
138 | 82 | ||
139 | //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo | 83 | //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo |
140 | fn parse_meta(meta: &str) -> FixtureMeta { | 84 | fn parse_meta(meta: &str) -> FileMeta { |
141 | let components = meta.split_ascii_whitespace().collect::<Vec<_>>(); | 85 | let components = meta.split_ascii_whitespace().collect::<Vec<_>>(); |
142 | 86 | ||
143 | let path = components[0].to_string(); | 87 | let path = components[0].to_string(); |
@@ -173,7 +117,7 @@ fn parse_meta(meta: &str) -> FixtureMeta { | |||
173 | } | 117 | } |
174 | } | 118 | } |
175 | 119 | ||
176 | FixtureMeta::File(FileMeta { path, crate_name: krate, deps, edition, cfg, env }) | 120 | FileMeta { path, crate_name: krate, deps, edition, cfg, env } |
177 | } | 121 | } |
178 | 122 | ||
179 | /// Adjusts the indentation of the first line to the minimum indentation of the rest of the lines. | 123 | /// Adjusts the indentation of the first line to the minimum indentation of the rest of the lines. |
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index f22fcc8b2..f99786606 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs | |||
@@ -22,7 +22,7 @@ pub use difference::Changeset as __Changeset; | |||
22 | pub use ra_cfg::CfgOptions; | 22 | pub use ra_cfg::CfgOptions; |
23 | pub use rustc_hash::FxHashMap; | 23 | pub use rustc_hash::FxHashMap; |
24 | 24 | ||
25 | pub use crate::fixture::{parse_fixture, parse_single_fixture, FixtureEntry, FixtureMeta}; | 25 | pub use crate::fixture::{parse_fixture, parse_single_fixture, FileMeta, FixtureEntry}; |
26 | 26 | ||
27 | pub const CURSOR_MARKER: &str = "<|>"; | 27 | pub const CURSOR_MARKER: &str = "<|>"; |
28 | 28 | ||