Fix test output formatting for rules starting with M/U

Previously the rule names could not begin with an uppercase M or U
because the test output formatter assumed that they represent special
tokens: MISSING or UEXPECTED.

Fixes #1940.
This commit is contained in:
mliszcz 2022-11-02 15:36:59 +01:00
parent 36b5b6c89e
commit 7bf2484d81
2 changed files with 13 additions and 10 deletions

View file

@ -294,15 +294,10 @@ fn format_sexp_indented(sexp: &String, initial_indent_level: u32) -> String {
// "(node_name"
write!(formatted, "{}", s).unwrap();
let mut c_iter = s.chars();
c_iter.next();
match c_iter.next() {
Some('M') | Some('U') => {
// "(MISSING node_name" or "(UNEXPECTED 'x'"
let s = s_iter.next().unwrap();
write!(formatted, " {}", s).unwrap();
}
Some(_) | None => {}
// "(MISSING node_name" or "(UNEXPECTED 'x'"
if s.starts_with("(MISSING") || s.starts_with("(UNEXPECTED") {
let s = s_iter.next().unwrap();
write!(formatted, " {}", s).unwrap();
}
} else if s.ends_with(':') {
// "field:"
@ -597,6 +592,14 @@ abc
.to_string()
);
assert_eq!(format_sexp(&"()".to_string()), "()".to_string());
assert_eq!(
format_sexp(&"(A (M (B)))".to_string()),
"(A\n (M\n (B)))"
);
assert_eq!(
format_sexp(&"(A (U (B)))".to_string()),
"(A\n (U\n (B)))"
);
}
#[test]