diff options
author | Aleksey Kladov <[email protected]> | 2020-06-23 17:34:50 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-06-23 17:37:26 +0100 |
commit | 21f751a0e5da5dd488612e25abfc545c259050e7 (patch) | |
tree | 0ad1b22fcc5b26456ecc92f473fb2306922fd6aa | |
parent | 30748161f0b4699ba9bc699a38ac9fc2fae49461 (diff) |
Simplify
-rw-r--r-- | crates/ra_db/src/fixture.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide/src/mock_analysis.rs | 14 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/support.rs | 2 | ||||
-rw-r--r-- | crates/test_utils/src/fixture.rs | 25 | ||||
-rw-r--r-- | crates/test_utils/src/lib.rs | 2 |
5 files changed, 24 insertions, 31 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index 7f006487a..d65536bbc 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs | |||
@@ -61,7 +61,9 @@ 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, CURSOR_MARKER}; | 64 | use test_utils::{ |
65 | extract_offset, parse_fixture, parse_single_fixture, FixtureEntry, CURSOR_MARKER, | ||
66 | }; | ||
65 | use vfs::{file_set::FileSet, VfsPath}; | 67 | use vfs::{file_set::FileSet, VfsPath}; |
66 | 68 | ||
67 | use crate::{ | 69 | use crate::{ |
@@ -112,7 +114,7 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId | |||
112 | let fixture = parse_single_fixture(ra_fixture); | 114 | let fixture = parse_single_fixture(ra_fixture); |
113 | 115 | ||
114 | let crate_graph = if let Some(entry) = fixture { | 116 | let crate_graph = if let Some(entry) = fixture { |
115 | let meta = match ParsedMeta::from(&entry.meta) { | 117 | let meta = match ParsedMeta::from(&entry) { |
116 | ParsedMeta::File(it) => it, | 118 | ParsedMeta::File(it) => it, |
117 | }; | 119 | }; |
118 | 120 | ||
@@ -165,7 +167,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit | |||
165 | let mut file_position = None; | 167 | let mut file_position = None; |
166 | 168 | ||
167 | for entry in fixture.iter() { | 169 | for entry in fixture.iter() { |
168 | let meta = match ParsedMeta::from(&entry.meta) { | 170 | let meta = match ParsedMeta::from(entry) { |
169 | ParsedMeta::File(it) => it, | 171 | ParsedMeta::File(it) => it, |
170 | }; | 172 | }; |
171 | assert!(meta.path.starts_with(&source_root_prefix)); | 173 | assert!(meta.path.starts_with(&source_root_prefix)); |
@@ -243,8 +245,8 @@ struct FileMeta { | |||
243 | env: Env, | 245 | env: Env, |
244 | } | 246 | } |
245 | 247 | ||
246 | impl From<&test_utils::FileMeta> for ParsedMeta { | 248 | impl From<&FixtureEntry> for ParsedMeta { |
247 | fn from(f: &test_utils::FileMeta) -> Self { | 249 | fn from(f: &FixtureEntry) -> Self { |
248 | Self::File(FileMeta { | 250 | Self::File(FileMeta { |
249 | path: f.path.to_owned(), | 251 | path: f.path.to_owned(), |
250 | krate: f.crate_name.to_owned(), | 252 | krate: f.crate_name.to_owned(), |
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index c0840c6ea..d480fcf62 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.as_str(), | 28 | MockFileData::Fixture(f) => f.path.as_str(), |
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
@@ -38,25 +38,23 @@ 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) => f.meta.cfg.clone(), | 41 | MockFileData::Fixture(f) => f.cfg.clone(), |
42 | _ => CfgOptions::default(), | 42 | _ => CfgOptions::default(), |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
46 | fn edition(&self) -> Edition { | 46 | fn edition(&self) -> Edition { |
47 | match self { | 47 | match self { |
48 | MockFileData::Fixture(f) => f | 48 | MockFileData::Fixture(f) => { |
49 | .meta | 49 | f.edition.as_ref().map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()) |
50 | .edition | 50 | } |
51 | .as_ref() | ||
52 | .map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()), | ||
53 | _ => Edition::Edition2018, | 51 | _ => Edition::Edition2018, |
54 | } | 52 | } |
55 | } | 53 | } |
56 | 54 | ||
57 | fn env(&self) -> Env { | 55 | fn env(&self) -> Env { |
58 | match self { | 56 | match self { |
59 | MockFileData::Fixture(f) => Env::from(f.meta.env.iter()), | 57 | MockFileData::Fixture(f) => Env::from(f.env.iter()), |
60 | _ => Env::default(), | 58 | _ => Env::default(), |
61 | } | 59 | } |
62 | } | 60 | } |
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs index 3bbfb43aa..59565bf3d 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.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 a07d057e1..bda826d50 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs | |||
@@ -4,13 +4,8 @@ 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: FileMeta, | ||
8 | pub text: String, | ||
9 | } | ||
10 | |||
11 | #[derive(Debug, Eq, PartialEq)] | ||
12 | pub struct FileMeta { | ||
13 | pub path: String, | 7 | pub path: String, |
8 | pub text: String, | ||
14 | pub crate_name: Option<String>, | 9 | pub crate_name: Option<String>, |
15 | pub deps: Vec<String>, | 10 | pub deps: Vec<String>, |
16 | pub cfg: CfgOptions, | 11 | pub cfg: CfgOptions, |
@@ -71,7 +66,7 @@ The offending line: {:?}"#, | |||
71 | if line.starts_with("//-") { | 66 | if line.starts_with("//-") { |
72 | let meta = line["//-".len()..].trim().to_string(); | 67 | let meta = line["//-".len()..].trim().to_string(); |
73 | let meta = parse_meta(&meta); | 68 | let meta = parse_meta(&meta); |
74 | res.push(FixtureEntry { meta, text: String::new() }) | 69 | res.push(meta) |
75 | } else if let Some(entry) = res.last_mut() { | 70 | } else if let Some(entry) = res.last_mut() { |
76 | entry.text.push_str(line); | 71 | entry.text.push_str(line); |
77 | entry.text.push('\n'); | 72 | entry.text.push('\n'); |
@@ -81,7 +76,7 @@ The offending line: {:?}"#, | |||
81 | } | 76 | } |
82 | 77 | ||
83 | //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo | 78 | //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo |
84 | fn parse_meta(meta: &str) -> FileMeta { | 79 | fn parse_meta(meta: &str) -> FixtureEntry { |
85 | let components = meta.split_ascii_whitespace().collect::<Vec<_>>(); | 80 | let components = meta.split_ascii_whitespace().collect::<Vec<_>>(); |
86 | 81 | ||
87 | let path = components[0].to_string(); | 82 | let path = components[0].to_string(); |
@@ -117,7 +112,7 @@ fn parse_meta(meta: &str) -> FileMeta { | |||
117 | } | 112 | } |
118 | } | 113 | } |
119 | 114 | ||
120 | FileMeta { path, crate_name: krate, deps, edition, cfg, env } | 115 | FixtureEntry { path, text: String::new(), crate_name: krate, deps, edition, cfg, env } |
121 | } | 116 | } |
122 | 117 | ||
123 | /// Adjusts the indentation of the first line to the minimum indentation of the rest of the lines. | 118 | /// Adjusts the indentation of the first line to the minimum indentation of the rest of the lines. |
@@ -209,12 +204,10 @@ fn parse_fixture_gets_full_meta() { | |||
209 | ); | 204 | ); |
210 | assert_eq!(1, parsed.len()); | 205 | assert_eq!(1, parsed.len()); |
211 | 206 | ||
212 | let parsed = &parsed[0]; | 207 | let meta = &parsed[0]; |
213 | assert_eq!("mod m;\n\n", parsed.text); | 208 | assert_eq!("mod m;\n\n", meta.text); |
214 | 209 | ||
215 | let meta = &parsed.meta; | 210 | assert_eq!("foo", meta.crate_name.as_ref().unwrap()); |
216 | assert_eq!("foo", meta.crate_name().unwrap()); | 211 | assert_eq!("/lib.rs", meta.path); |
217 | assert_eq!("/lib.rs", meta.path()); | 212 | assert_eq!(2, meta.env.len()); |
218 | assert!(meta.cfg_options().is_some()); | ||
219 | assert_eq!(2, meta.env().count()); | ||
220 | } | 213 | } |
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index f99786606..0fdd1a36b 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, FileMeta, FixtureEntry}; | 25 | pub use crate::fixture::{parse_fixture, parse_single_fixture, FixtureEntry}; |
26 | 26 | ||
27 | pub const CURSOR_MARKER: &str = "<|>"; | 27 | pub const CURSOR_MARKER: &str = "<|>"; |
28 | 28 | ||