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 ++-------------------------------------- crates/test_utils/src/lib.rs | 2 +- 2 files changed, 4 insertions(+), 60 deletions(-) (limited to 'crates/test_utils') 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. diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index f22fcc8b2..f99786606 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; pub use ra_cfg::CfgOptions; pub use rustc_hash::FxHashMap; -pub use crate::fixture::{parse_fixture, parse_single_fixture, FixtureEntry, FixtureMeta}; +pub use crate::fixture::{parse_fixture, parse_single_fixture, FileMeta, FixtureEntry}; pub const CURSOR_MARKER: &str = "<|>"; -- cgit v1.2.3