From 30748161f0b4699ba9bc699a38ac9fc2fae49461 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 23 Jun 2020 18:20:32 +0200 Subject: Simplify --- crates/test_utils/src/fixture.rs | 62 ++-------------------------------------- 1 file changed, 3 insertions(+), 59 deletions(-) (limited to 'crates/test_utils/src/fixture.rs') diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index 0dbeb01b1..a07d057e1 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs @@ -4,15 +4,10 @@ use stdx::split1; #[derive(Debug, Eq, PartialEq)] pub struct FixtureEntry { - pub meta: FixtureMeta, + pub meta: FileMeta, pub text: String, } -#[derive(Debug, Eq, PartialEq)] -pub enum FixtureMeta { - File(FileMeta), -} - #[derive(Debug, Eq, PartialEq)] pub struct FileMeta { pub path: String, @@ -23,57 +18,6 @@ pub struct FileMeta { pub env: FxHashMap, } -impl FixtureMeta { - pub fn path(&self) -> &str { - match self { - FixtureMeta::File(f) => &f.path, - } - } - - pub fn crate_name(&self) -> Option<&String> { - match self { - FixtureMeta::File(f) => f.crate_name.as_ref(), - } - } - - pub fn cfg_options(&self) -> Option<&CfgOptions> { - match self { - FixtureMeta::File(f) => Some(&f.cfg), - } - } - - pub fn edition(&self) -> Option<&String> { - match self { - FixtureMeta::File(f) => f.edition.as_ref(), - } - } - - 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()), - }, - } - } - } - - 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) - } -} - /// Same as `parse_fixture`, except it allow empty fixture pub fn parse_single_fixture(ra_fixture: &str) -> Option { if !ra_fixture.lines().any(|it| it.trim_start().starts_with("//-")) { @@ -137,7 +81,7 @@ The offending line: {:?}"#, } //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo -fn parse_meta(meta: &str) -> FixtureMeta { +fn parse_meta(meta: &str) -> FileMeta { let components = meta.split_ascii_whitespace().collect::>(); let path = components[0].to_string(); @@ -173,7 +117,7 @@ fn parse_meta(meta: &str) -> FixtureMeta { } } - FixtureMeta::File(FileMeta { path, crate_name: krate, deps, edition, cfg, env }) + FileMeta { path, crate_name: krate, deps, edition, cfg, env } } /// Adjusts the indentation of the first line to the minimum indentation of the rest of the lines. -- cgit v1.2.3