Basic formatting of multi-abilities

This commit is contained in:
Ayaz Hafiz 2022-10-17 10:31:07 -05:00
parent 0642952d05
commit 1053c11907
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 44 additions and 4 deletions

View file

@ -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);
}
}
}

View file

@ -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() {