From 2c00bd8c6a9476dbac427c84941fe6f54a8a95b1 Mon Sep 17 00:00:00 2001 From: vsrs Date: Sat, 16 May 2020 15:23:43 +0300 Subject: Propogate fixture meta to AnalysisHost Except crate name. --- crates/test_utils/src/lib.rs | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'crates/test_utils/src') 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 { #[derive(Debug, Eq, PartialEq)] pub struct FileMeta { pub path: RelativePathBuf, - pub krate: Option, + pub crate_name: Option, pub deps: Vec, pub cfg: CfgOptions, pub edition: Option, @@ -189,12 +189,52 @@ impl FixtureMeta { } } + pub fn crate_name(&self) -> Option<&String> { + match self { + FixtureMeta::File(f) => f.crate_name.as_ref(), + _ => None, + } + } + pub fn cfg_options(&self) -> Option<&CfgOptions> { match self { FixtureMeta::File(f) => Some(&f.cfg), _ => None, } } + + pub fn edition(&self) -> Option<&String> { + match self { + FixtureMeta::File(f) => f.edition.as_ref(), + _ => None, + } + } + + pub fn env(&self) -> impl Iterator { + struct EnvIter<'a> { + iter: Option>, + } + + impl<'a> EnvIter<'a> { + fn new(meta: &'a FixtureMeta) -> Self { + Self { + iter: match meta { + FixtureMeta::File(f) => Some(f.env.iter()), + _ => None, + }, + } + } + } + + impl<'a> Iterator for EnvIter<'a> { + type Item = (&'a String, &'a String); + fn next(&mut self) -> Option { + self.iter.as_mut().and_then(|i| i.next()) + } + } + + EnvIter::new(self) + } } /// Parses text which looks like this: @@ -289,7 +329,7 @@ fn parse_meta(meta: &str) -> FixtureMeta { } } - FixtureMeta::File(FileMeta { path, krate, deps, edition, cfg, env }) + FixtureMeta::File(FileMeta { path, crate_name: krate, deps, edition, cfg, env }) } fn split1(haystack: &str, delim: char) -> Option<(&str, &str)> { -- cgit v1.2.3