mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-17 02:08:30 +00:00
Merge #2939
2939: Simplify fixture parsing r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
a0be39296d
1 changed files with 20 additions and 21 deletions
|
@ -176,7 +176,7 @@ pub fn parse_fixture(fixture: &str) -> Vec<FixtureEntry> {
|
||||||
.next()
|
.next()
|
||||||
.expect("empty fixture");
|
.expect("empty fixture");
|
||||||
|
|
||||||
let lines = fixture
|
let mut lines = fixture
|
||||||
.split('\n') // don't use `.lines` to not drop `\r\n`
|
.split('\n') // don't use `.lines` to not drop `\r\n`
|
||||||
.filter_map(|line| {
|
.filter_map(|line| {
|
||||||
if line.len() >= margin {
|
if line.len() >= margin {
|
||||||
|
@ -189,29 +189,28 @@ pub fn parse_fixture(fixture: &str) -> Vec<FixtureEntry> {
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
let mut buf = String::new();
|
let mut meta = None;
|
||||||
let mut meta: Option<&str> = None;
|
loop {
|
||||||
|
let mut next_meta = None;
|
||||||
macro_rules! flush {
|
let mut text = String::new();
|
||||||
() => {
|
for line in lines.by_ref() {
|
||||||
if let Some(meta) = meta {
|
if line.starts_with("//-") {
|
||||||
res.push(FixtureEntry { meta: meta.to_string(), text: buf.clone() });
|
next_meta = Some(line["//-".len()..].trim().to_string());
|
||||||
buf.clear();
|
break;
|
||||||
}
|
}
|
||||||
};
|
text.push_str(line);
|
||||||
};
|
text.push('\n');
|
||||||
|
}
|
||||||
for line in lines {
|
|
||||||
if line.starts_with("//-") {
|
if let Some(meta) = meta {
|
||||||
flush!();
|
res.push(FixtureEntry { meta, text });
|
||||||
buf.clear();
|
}
|
||||||
meta = Some(line["//-".len()..].trim());
|
meta = next_meta;
|
||||||
continue;
|
if meta.is_none() {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
buf.push_str(line);
|
|
||||||
buf.push('\n');
|
|
||||||
}
|
}
|
||||||
flush!();
|
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue