From 6048d294009f0f58593747e0870aa174e29a32af Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 23 Oct 2019 18:24:40 +0300 Subject: xtask: don't depend on itertools xtask should be fast to compiler, as it's a gateway to rust-analyzer --- xtask/Cargo.toml | 1 - xtask/src/codegen/gen_parser_tests.rs | 39 ++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 18 deletions(-) (limited to 'xtask') diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 4fc1c744b..023f6a859 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -7,7 +7,6 @@ publish = false [dependencies] walkdir = "2.1.3" -itertools = "0.8.0" pico-args = "0.3.0" quote = "1.0.2" proc-macro2 = "1.0.1" diff --git a/xtask/src/codegen/gen_parser_tests.rs b/xtask/src/codegen/gen_parser_tests.rs index e09b6fcfe..0f550d948 100644 --- a/xtask/src/codegen/gen_parser_tests.rs +++ b/xtask/src/codegen/gen_parser_tests.rs @@ -7,8 +7,6 @@ use std::{ path::{Path, PathBuf}, }; -use itertools::Itertools; - use crate::{ codegen::{self, update, Mode}, project_root, Result, @@ -61,38 +59,45 @@ struct Tests { fn collect_tests(s: &str) -> Vec<(usize, Test)> { let mut res = vec![]; let prefix = "// "; - let comment_blocks = s - .lines() - .map(str::trim_start) - .enumerate() - .group_by(|(_idx, line)| line.starts_with(prefix)); + let lines = s.lines().map(str::trim_start).enumerate(); - 'outer: for (is_comment, block) in comment_blocks.into_iter() { - if !is_comment { - continue; + let mut block = vec![]; + for (line_idx, line) in lines { + let is_comment = line.starts_with(prefix); + if is_comment { + block.push((line_idx, &line[prefix.len()..])); + } else { + process_block(&mut res, &block); + block.clear(); } - let mut block = block.map(|(idx, line)| (idx, &line[prefix.len()..])); + } + process_block(&mut res, &block); + return res; + fn process_block(acc: &mut Vec<(usize, Test)>, block: &[(usize, &str)]) { + if block.is_empty() { + return; + } let mut ok = true; + let mut block = block.iter(); let (start_line, name) = loop { match block.next() { - Some((idx, line)) if line.starts_with("test ") => { + Some(&(idx, line)) if line.starts_with("test ") => { break (idx, line["test ".len()..].to_string()); } - Some((idx, line)) if line.starts_with("test_err ") => { + Some(&(idx, line)) if line.starts_with("test_err ") => { ok = false; break (idx, line["test_err ".len()..].to_string()); } Some(_) => (), - None => continue 'outer, + None => return, } }; let text: String = - itertools::join(block.map(|(_, line)| line).chain(::std::iter::once("")), "\n"); + block.map(|(_, line)| *line).chain(std::iter::once("")).collect::>().join("\n"); assert!(!text.trim().is_empty() && text.ends_with('\n')); - res.push((start_line, Test { name, text, ok })) + acc.push((start_line, Test { name, text, ok })) } - res } fn tests_from_dir(dir: &Path) -> Result { -- cgit v1.2.3