From 167855b2891f75f0b39bd3982b81c80e2c0f3fc0 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Wed, 21 Feb 2024 00:06:51 -0500 Subject: [PATCH] fix(test): edge case when parsing `UNEXPECTED`/`MISSING` nodes with an indentation level greater than 0 --- cli/src/test.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cli/src/test.rs b/cli/src/test.rs index 86462565..cdc3b994 100644 --- a/cli/src/test.rs +++ b/cli/src/test.rs @@ -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:" @@ -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() );