aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/test_utils/src')
-rw-r--r--crates/test_utils/src/lib.rs44
1 files changed, 42 insertions, 2 deletions
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index 584ca5c39..e7fa201e9 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -174,7 +174,7 @@ pub enum FixtureMeta {
174#[derive(Debug, Eq, PartialEq)] 174#[derive(Debug, Eq, PartialEq)]
175pub struct FileMeta { 175pub struct FileMeta {
176 pub path: RelativePathBuf, 176 pub path: RelativePathBuf,
177 pub krate: Option<String>, 177 pub crate_name: Option<String>,
178 pub deps: Vec<String>, 178 pub deps: Vec<String>,
179 pub cfg: CfgOptions, 179 pub cfg: CfgOptions,
180 pub edition: Option<String>, 180 pub edition: Option<String>,
@@ -189,12 +189,52 @@ impl FixtureMeta {
189 } 189 }
190 } 190 }
191 191
192 pub fn crate_name(&self) -> Option<&String> {
193 match self {
194 FixtureMeta::File(f) => f.crate_name.as_ref(),
195 _ => None,
196 }
197 }
198
192 pub fn cfg_options(&self) -> Option<&CfgOptions> { 199 pub fn cfg_options(&self) -> Option<&CfgOptions> {
193 match self { 200 match self {
194 FixtureMeta::File(f) => Some(&f.cfg), 201 FixtureMeta::File(f) => Some(&f.cfg),
195 _ => None, 202 _ => None,
196 } 203 }
197 } 204 }
205
206 pub fn edition(&self) -> Option<&String> {
207 match self {
208 FixtureMeta::File(f) => f.edition.as_ref(),
209 _ => None,
210 }
211 }
212
213 pub fn env(&self) -> impl Iterator<Item = (&String, &String)> {
214 struct EnvIter<'a> {
215 iter: Option<std::collections::hash_map::Iter<'a, String, String>>,
216 }
217
218 impl<'a> EnvIter<'a> {
219 fn new(meta: &'a FixtureMeta) -> Self {
220 Self {
221 iter: match meta {
222 FixtureMeta::File(f) => Some(f.env.iter()),
223 _ => None,
224 },
225 }
226 }
227 }
228
229 impl<'a> Iterator for EnvIter<'a> {
230 type Item = (&'a String, &'a String);
231 fn next(&mut self) -> Option<Self::Item> {
232 self.iter.as_mut().and_then(|i| i.next())
233 }
234 }
235
236 EnvIter::new(self)
237 }
198} 238}
199 239
200/// Parses text which looks like this: 240/// Parses text which looks like this:
@@ -289,7 +329,7 @@ fn parse_meta(meta: &str) -> FixtureMeta {
289 } 329 }
290 } 330 }
291 331
292 FixtureMeta::File(FileMeta { path, krate, deps, edition, cfg, env }) 332 FixtureMeta::File(FileMeta { path, crate_name: krate, deps, edition, cfg, env })
293} 333}
294 334
295fn split1(haystack: &str, delim: char) -> Option<(&str, &str)> { 335fn split1(haystack: &str, delim: char) -> Option<(&str, &str)> {