diff --git a/Cargo.lock b/Cargo.lock index 634480e5fb..61fd24ef7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1771,7 +1771,6 @@ dependencies = [ name = "xtask" version = "0.1.0" dependencies = [ - "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 4fc1c744bf..023f6a859f 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 e09b6fcfec..0f550d9488 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 {