aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-23 17:34:50 +0100
committerAleksey Kladov <[email protected]>2020-06-23 17:37:26 +0100
commit21f751a0e5da5dd488612e25abfc545c259050e7 (patch)
tree0ad1b22fcc5b26456ecc92f473fb2306922fd6aa /crates/test_utils
parent30748161f0b4699ba9bc699a38ac9fc2fae49461 (diff)
Simplify
Diffstat (limited to 'crates/test_utils')
-rw-r--r--crates/test_utils/src/fixture.rs25
-rw-r--r--crates/test_utils/src/lib.rs2
2 files changed, 10 insertions, 17 deletions
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)]
6pub struct FixtureEntry { 6pub struct FixtureEntry {
7 pub meta: FileMeta,
8 pub text: String,
9}
10
11#[derive(Debug, Eq, PartialEq)]
12pub 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
84fn parse_meta(meta: &str) -> FileMeta { 79fn 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;
22pub use ra_cfg::CfgOptions; 22pub use ra_cfg::CfgOptions;
23pub use rustc_hash::FxHashMap; 23pub use rustc_hash::FxHashMap;
24 24
25pub use crate::fixture::{parse_fixture, parse_single_fixture, FileMeta, FixtureEntry}; 25pub use crate::fixture::{parse_fixture, parse_single_fixture, FixtureEntry};
26 26
27pub const CURSOR_MARKER: &str = "<|>"; 27pub const CURSOR_MARKER: &str = "<|>";
28 28