mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Basic formatting of multi-abilities
This commit is contained in:
parent
0642952d05
commit
1053c11907
2 changed files with 44 additions and 4 deletions
|
@ -546,8 +546,8 @@ impl<'a> Formattable for Tag<'a> {
|
|||
|
||||
impl<'a> Formattable for HasClause<'a> {
|
||||
fn is_multiline(&self) -> bool {
|
||||
// TODO(abilities)
|
||||
self.abilities[0].is_multiline()
|
||||
// No, always put abilities in a "has" clause on one line
|
||||
false
|
||||
}
|
||||
|
||||
fn format_with_options<'buf>(
|
||||
|
@ -561,8 +561,15 @@ impl<'a> Formattable for HasClause<'a> {
|
|||
buf.spaces(1);
|
||||
buf.push_str("has");
|
||||
buf.spaces(1);
|
||||
// TODO(abilities)
|
||||
self.abilities[0].format_with_options(buf, parens, newlines, indent);
|
||||
|
||||
for (i, ab) in self.abilities.iter().enumerate() {
|
||||
if i > 0 {
|
||||
buf.spaces(1);
|
||||
buf.push('&');
|
||||
buf.spaces(1);
|
||||
}
|
||||
ab.format_with_options(buf, parens, newlines, indent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5705,6 +5705,39 @@ mod test_fmt {
|
|||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clauses_with_multiple_abilities() {
|
||||
expr_formats_same(indoc!(
|
||||
r#"
|
||||
f : {} -> a | a has Eq & Hash & Decode
|
||||
|
||||
f
|
||||
"#
|
||||
));
|
||||
|
||||
expr_formats_to(
|
||||
indoc!(
|
||||
r#"
|
||||
f : {} -> a | a has Eq & Hash & Decode,
|
||||
b has Eq & Hash
|
||||
|
||||
f
|
||||
"#
|
||||
),
|
||||
indoc!(
|
||||
// TODO: ideally, this would look a bit nicer - consider
|
||||
// f : {} -> a
|
||||
// | a has Eq & Hash & Decode,
|
||||
// b has Eq & Hash
|
||||
r#"
|
||||
f : {} -> a | a has Eq & Hash & Decode, b has Eq & Hash
|
||||
|
||||
f
|
||||
"#
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// this is a parse error atm
|
||||
// #[test]
|
||||
// fn multiline_apply() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue