start top-level entry point tests

This commit is contained in:
Aleksey Kladov 2022-01-02 15:15:04 +03:00
parent e366b3c730
commit f2ea7853ee
2 changed files with 70 additions and 2 deletions

View file

@ -86,22 +86,34 @@ fn parse(entry: TopEntryPoint, text: &str) -> (String, bool) {
let mut buf = String::new();
let mut errors = Vec::new();
let mut indent = String::new();
let mut depth = 0;
let mut len = 0;
lexed.intersperse_trivia(&output, &mut |step| match step {
crate::StrStep::Token { kind, text } => {
assert!(depth > 0);
len += text.len();
write!(buf, "{}", indent).unwrap();
write!(buf, "{:?} {:?}\n", kind, text).unwrap();
}
crate::StrStep::Enter { kind } => {
assert!(depth > 0 || len == 0);
depth += 1;
write!(buf, "{}", indent).unwrap();
write!(buf, "{:?}\n", kind).unwrap();
indent.push_str(" ");
}
crate::StrStep::Exit => {
assert!(depth > 0);
depth -= 1;
indent.pop();
indent.pop();
}
crate::StrStep::Error { msg, pos } => errors.push(format!("error {}: {}\n", pos, msg)),
crate::StrStep::Error { msg, pos } => {
assert!(depth > 0);
errors.push(format!("error {}: {}\n", pos, msg))
}
});
assert_eq!(len, text.len());
for (token, msg) in lexed.errors() {
let pos = lexed.text_start(token);