aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-01-29 13:06:23 +0000
committerAleksey Kladov <[email protected]>2020-01-29 13:06:23 +0000
commitd2fd252f9de23d5801b1ca10c067654bf7d6ef4f (patch)
tree20af3ef139e40eb0b506e41abfb316485205284a /crates
parent7cc0a8652870402db3b072cab030ba28d6b96b39 (diff)
Simplify fixture parsing
Diffstat (limited to 'crates')
-rw-r--r--crates/test_utils/src/lib.rs39
1 files changed, 19 insertions, 20 deletions
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index 265fcf8da..5666445aa 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -176,7 +176,7 @@ pub fn parse_fixture(fixture: &str) -> Vec<FixtureEntry> {
176 .next() 176 .next()
177 .expect("empty fixture"); 177 .expect("empty fixture");
178 178
179 let lines = fixture 179 let mut lines = fixture
180 .split('\n') // don't use `.lines` to not drop `\r\n` 180 .split('\n') // don't use `.lines` to not drop `\r\n`
181 .filter_map(|line| { 181 .filter_map(|line| {
182 if line.len() >= margin { 182 if line.len() >= margin {
@@ -189,29 +189,28 @@ pub fn parse_fixture(fixture: &str) -> Vec<FixtureEntry> {
189 }); 189 });
190 190
191 let mut res = Vec::new(); 191 let mut res = Vec::new();
192 let mut buf = String::new(); 192 let mut meta = None;
193 let mut meta: Option<&str> = None; 193 loop {
194 194 let mut next_meta = None;
195 macro_rules! flush { 195 let mut text = String::new();
196 () => { 196 for line in lines.by_ref() {
197 if let Some(meta) = meta { 197 if line.starts_with("//-") {
198 res.push(FixtureEntry { meta: meta.to_string(), text: buf.clone() }); 198 next_meta = Some(line["//-".len()..].trim().to_string());
199 buf.clear(); 199 break;
200 } 200 }
201 }; 201 text.push_str(line);
202 }; 202 text.push('\n');
203 }
203 204
204 for line in lines { 205 if let Some(meta) = meta {
205 if line.starts_with("//-") { 206 res.push(FixtureEntry { meta, text });
206 flush!(); 207 }
207 buf.clear(); 208 meta = next_meta;
208 meta = Some(line["//-".len()..].trim()); 209 if meta.is_none() {
209 continue; 210 break;
210 } 211 }
211 buf.push_str(line);
212 buf.push('\n');
213 } 212 }
214 flush!(); 213
215 res 214 res
216} 215}
217 216