Fix else/if formatter.
This commit is contained in:
parent
bae8267f18
commit
f2e716dd86
|
@ -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(),
|
||||
));
|
||||
|
||||
|
|
|
@ -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#"
|
||||
|
|
Loading…
Reference in New Issue