Skip to content

Commit

Permalink
fix(test): edge case when parsing UNEXPECTED/MISSING nodes with a…
Browse files Browse the repository at this point in the history
…n indentation level greater than 0
  • Loading branch information
amaanq committed Feb 21, 2024
1 parent 5811503 commit 62812c1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cli/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,14 @@ fn format_sexp_indented(sexp: &str, initial_indent_level: u32) -> String {
// "(MISSING node_name" or "(UNEXPECTED 'x'"
if s.starts_with("(MISSING") || s.starts_with("(UNEXPECTED") {
fetch_next_str(&mut s).unwrap();
write!(formatted, " {s}").unwrap();
if s.is_empty() {
while indent_level > 0 {
indent_level -= 1;
write!(formatted, ")").unwrap();
}
} else {
write!(formatted, " {s}").unwrap();
}
}
} else if s.ends_with(':') {
// "field:"
Expand Down Expand Up @@ -753,6 +760,16 @@ abc
r#"
(source_file
(MISSING ")"))
"#
.trim()
);
assert_eq!(
format_sexp(r#"(source_file (ERROR (UNEXPECTED 'f') (UNEXPECTED '+')))"#),
r#"
(source_file
(ERROR
(UNEXPECTED 'f')
(UNEXPECTED '+')))
"#
.trim()
);
Expand Down

0 comments on commit 62812c1

Please sign in to comment.