Fix ELSE IF pretty formatting ()

This commit is contained in:
Micha de Vries 2024-06-28 12:15:03 +02:00 committed by GitHub
parent af80c1ccce
commit b3b19fd7da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -81,7 +81,7 @@ impl Display for IfelseStatement {
})
}),
if is_pretty() {
fmt_separated_by("ELSE")
fmt_separated_by("ELSE ")
} else {
fmt_separated_by(" ELSE ")
},
@ -118,7 +118,7 @@ impl Display for IfelseStatement {
})
}),
if is_pretty() {
fmt_separated_by("ELSE")
fmt_separated_by("ELSE ")
} else {
fmt_separated_by(" ELSE ")
},
@ -144,3 +144,15 @@ impl Display for IfelseStatement {
}
}
}
#[cfg(test)]
mod tests {
use crate::syn::parse;
#[test]
fn format_pretty() {
let query = parse("IF 1 { 1 } ELSE IF 2 { 2 }").unwrap();
assert_eq!(format!("{}", query), "IF 1 { 1 } ELSE IF 2 { 2 };");
assert_eq!(format!("{:#}", query), "IF 1\n\t{ 1 }\nELSE IF 2\n\t{ 2 }\n;");
}
}