aboutsummaryrefslogtreecommitdiff
path: root/xtask
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-10-23 16:24:40 +0100
committerAleksey Kladov <[email protected]>2019-10-23 16:57:18 +0100
commit6048d294009f0f58593747e0870aa174e29a32af (patch)
tree3af21aaefe1efdabafeb5702959e1094504813e7 /xtask
parenta669049ef327db5be04f076eff83932ac1f95d91 (diff)
xtask: don't depend on itertools
xtask should be fast to compiler, as it's a gateway to rust-analyzer
Diffstat (limited to 'xtask')
-rw-r--r--xtask/Cargo.toml1
-rw-r--r--xtask/src/codegen/gen_parser_tests.rs39
2 files changed, 22 insertions, 18 deletions
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
7 7
8[dependencies] 8[dependencies]
9walkdir = "2.1.3" 9walkdir = "2.1.3"
10itertools = "0.8.0"
11pico-args = "0.3.0" 10pico-args = "0.3.0"
12quote = "1.0.2" 11quote = "1.0.2"
13proc-macro2 = "1.0.1" 12proc-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::{
7 path::{Path, PathBuf}, 7 path::{Path, PathBuf},
8}; 8};
9 9
10use itertools::Itertools;
11
12use crate::{ 10use crate::{
13 codegen::{self, update, Mode}, 11 codegen::{self, update, Mode},
14 project_root, Result, 12 project_root, Result,
@@ -61,38 +59,45 @@ struct Tests {
61fn collect_tests(s: &str) -> Vec<(usize, Test)> { 59fn collect_tests(s: &str) -> Vec<(usize, Test)> {
62 let mut res = vec![]; 60 let mut res = vec![];
63 let prefix = "// "; 61 let prefix = "// ";
64 let comment_blocks = s 62 let lines = s.lines().map(str::trim_start).enumerate();
65 .lines()
66 .map(str::trim_start)
67 .enumerate()
68 .group_by(|(_idx, line)| line.starts_with(prefix));
69 63
70 'outer: for (is_comment, block) in comment_blocks.into_iter() { 64 let mut block = vec![];
71 if !is_comment { 65 for (line_idx, line) in lines {
72 continue; 66 let is_comment = line.starts_with(prefix);
67 if is_comment {
68 block.push((line_idx, &line[prefix.len()..]));
69 } else {
70 process_block(&mut res, &block);
71 block.clear();
73 } 72 }
74 let mut block = block.map(|(idx, line)| (idx, &line[prefix.len()..])); 73 }
74 process_block(&mut res, &block);
75 return res;
75 76
77 fn process_block(acc: &mut Vec<(usize, Test)>, block: &[(usize, &str)]) {
78 if block.is_empty() {
79 return;
80 }
76 let mut ok = true; 81 let mut ok = true;
82 let mut block = block.iter();
77 let (start_line, name) = loop { 83 let (start_line, name) = loop {
78 match block.next() { 84 match block.next() {
79 Some((idx, line)) if line.starts_with("test ") => { 85 Some(&(idx, line)) if line.starts_with("test ") => {
80 break (idx, line["test ".len()..].to_string()); 86 break (idx, line["test ".len()..].to_string());
81 } 87 }
82 Some((idx, line)) if line.starts_with("test_err ") => { 88 Some(&(idx, line)) if line.starts_with("test_err ") => {
83 ok = false; 89 ok = false;
84 break (idx, line["test_err ".len()..].to_string()); 90 break (idx, line["test_err ".len()..].to_string());
85 } 91 }
86 Some(_) => (), 92 Some(_) => (),
87 None => continue 'outer, 93 None => return,
88 } 94 }
89 }; 95 };
90 let text: String = 96 let text: String =
91 itertools::join(block.map(|(_, line)| line).chain(::std::iter::once("")), "\n"); 97 block.map(|(_, line)| *line).chain(std::iter::once("")).collect::<Vec<_>>().join("\n");
92 assert!(!text.trim().is_empty() && text.ends_with('\n')); 98 assert!(!text.trim().is_empty() && text.ends_with('\n'));
93 res.push((start_line, Test { name, text, ok })) 99 acc.push((start_line, Test { name, text, ok }))
94 } 100 }
95 res
96} 101}
97 102
98fn tests_from_dir(dir: &Path) -> Result<Tests> { 103fn tests_from_dir(dir: &Path) -> Result<Tests> {