Fix else/if formatter.

This commit is contained in:
KtorZ 2022-12-28 17:55:11 +01:00
parent bae8267f18
commit f2e716dd86
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 20 additions and 3 deletions

View File

@ -905,9 +905,9 @@ impl<'comments> Formatter<'comments> {
let if_branches = self
.if_branch(break_("if", "if "), branches.first())
.append(join(
branches[1..]
.iter()
.map(|branch| self.if_branch("else if".to_doc(), branch)),
branches[1..].iter().map(|branch| {
self.if_branch(line().append(break_("} else if", "} else if ")), branch)
}),
nil(),
));

View File

@ -173,6 +173,23 @@ fn test_format_nested_when() {
assert_fmt(src, expected)
}
#[test]
fn test_format_else_if() {
let src = indoc! {r#"
pub fn foo(xs: List<a>, n: Int) -> List<a> {
if n <= 0 {
xs
} else if n <= 10 {
xs
} else {
xs
}
}
"#};
assert_fmt(src, src)
}
#[test]
fn test_format_imports() {
let src = indoc! {r#"