From c445c72eb355dfd45d1ce1dd68087f7cf7c05877 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jan 2020 13:17:56 +0100 Subject: Simplify fixture parsing --- crates/test_utils/src/lib.rs | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'crates/test_utils') diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 5666445aa..336c594a6 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -188,29 +188,16 @@ pub fn parse_fixture(fixture: &str) -> Vec { } }); - let mut res = Vec::new(); - let mut meta = None; - loop { - let mut next_meta = None; - let mut text = String::new(); - for line in lines.by_ref() { - if line.starts_with("//-") { - next_meta = Some(line["//-".len()..].trim().to_string()); - break; - } - text.push_str(line); - text.push('\n'); - } - - if let Some(meta) = meta { - res.push(FixtureEntry { meta, text }); - } - meta = next_meta; - if meta.is_none() { - break; + let mut res: Vec = Vec::new(); + for line in lines.by_ref() { + if line.starts_with("//-") { + let meta = line["//-".len()..].trim().to_string(); + res.push(FixtureEntry { meta, text: String::new() }) + } else if let Some(entry) = res.last_mut() { + entry.text.push_str(line); + entry.text.push('\n'); } } - res } -- cgit v1.2.3