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
|
let if_branches = self
|
||||||
.if_branch(break_("if", "if "), branches.first())
|
.if_branch(break_("if", "if "), branches.first())
|
||||||
.append(join(
|
.append(join(
|
||||||
branches[1..]
|
branches[1..].iter().map(|branch| {
|
||||||
.iter()
|
self.if_branch(line().append(break_("} else if", "} else if ")), branch)
|
||||||
.map(|branch| self.if_branch("else if".to_doc(), branch)),
|
}),
|
||||||
nil(),
|
nil(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -173,6 +173,23 @@ fn test_format_nested_when() {
|
||||||
assert_fmt(src, expected)
|
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]
|
#[test]
|
||||||
fn test_format_imports() {
|
fn test_format_imports() {
|
||||||
let src = indoc! {r#"
|
let src = indoc! {r#"
|
||||||
|
|
Loading…
Reference in New Issue