Allow newlines in when clause sequences.
This commit is contained in:
parent
5d4c95d538
commit
6a4f62d074
|
@ -1458,7 +1458,6 @@ impl<'comments> Formatter<'comments> {
|
||||||
|
|
||||||
fn clause<'a>(&mut self, clause: &'a UntypedClause, index: u32) -> Document<'a> {
|
fn clause<'a>(&mut self, clause: &'a UntypedClause, index: u32) -> Document<'a> {
|
||||||
let space_before = self.pop_empty_lines(clause.location.start);
|
let space_before = self.pop_empty_lines(clause.location.start);
|
||||||
let after_position = clause.location.end;
|
|
||||||
let clause_doc = join(
|
let clause_doc = join(
|
||||||
clause.patterns.iter().map(|p| self.pattern(p)),
|
clause.patterns.iter().map(|p| self.pattern(p)),
|
||||||
" | ".to_doc(),
|
" | ".to_doc(),
|
||||||
|
@ -1468,9 +1467,6 @@ impl<'comments> Formatter<'comments> {
|
||||||
Some(guard) => clause_doc.append(" if ").append(self.clause_guard(guard)),
|
Some(guard) => clause_doc.append(" if ").append(self.clause_guard(guard)),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Remove any unused empty lines within the clause
|
|
||||||
self.pop_empty_lines(after_position);
|
|
||||||
|
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
clause_doc
|
clause_doc
|
||||||
} else if space_before {
|
} else if space_before {
|
||||||
|
|
|
@ -133,17 +133,28 @@ fn test_format_when() {
|
||||||
let src = indoc! {r#"
|
let src = indoc! {r#"
|
||||||
pub fn foo( a) {
|
pub fn foo( a) {
|
||||||
when a is{
|
when a is{
|
||||||
True -> 14
|
True -> {
|
||||||
|
|
||||||
|
bar()
|
||||||
|
|
||||||
|
14
|
||||||
|
}
|
||||||
False ->
|
False ->
|
||||||
42}
|
|
||||||
|
42
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"#};
|
"#};
|
||||||
|
|
||||||
let expected = indoc! {r#"
|
let expected = indoc! {r#"
|
||||||
pub fn foo(a) {
|
pub fn foo(a) {
|
||||||
when a is {
|
when a is {
|
||||||
True ->
|
True -> {
|
||||||
|
bar()
|
||||||
|
|
||||||
14
|
14
|
||||||
|
}
|
||||||
False ->
|
False ->
|
||||||
42
|
42
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue