aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils/src/fixture.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/test_utils/src/fixture.rs')
-rw-r--r--crates/test_utils/src/fixture.rs25
1 files changed, 9 insertions, 16 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}