Format has clauses with impls

This commit is contained in:
Ayaz Hafiz 2022-07-15 11:45:53 -04:00
parent 85cbab0193
commit 3c65fbcf35
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 67 additions and 2 deletions

View file

@ -584,7 +584,7 @@ impl<'a> Formattable for HasImpls<'a> {
buf.newline();
buf.indent(indent);
}
impls.format_with_options(buf, parens, newlines, indent);
fmt_collection(buf, indent, Braces::Curly, *impls, Newlines::No);
}
HasImpls::SpaceBefore(impls, spaces) => {
buf.newline();
@ -666,7 +666,7 @@ impl<'a> Formattable for HasAbilities<'a> {
}
buf.push_str("has");
buf.spaces(1);
fmt_collection(buf, indent, Braces::Square, *has_abilities, newlines);
fmt_collection(buf, indent, Braces::Square, *has_abilities, Newlines::No);
}
HasAbilities::SpaceBefore(has_abilities, spaces) => {
buf.newline();

View file

@ -82,6 +82,7 @@ pub fn fmt_collection<'a, 'buf, T: ExtractSpaces<'a> + Formattable>(
}
}
buf.indent(item_indent);
item.item.format(buf, item_indent);
buf.push(',');

View file

@ -5121,6 +5121,70 @@ mod test_fmt {
);
}
#[test]
fn opaque_has_with_impls() {
expr_formats_same(indoc!(
r#"
A := U8 has [Eq { eq }, Hash { hash }]
0
"#
));
expr_formats_same(indoc!(
r#"
A := U8 has [Eq { eq, eq1 }]
0
"#
));
expr_formats_to(
indoc!(
r#"
A := U8 has [Eq { eq, eq1 }]
A := U8 has [Eq {
eq,
eq1
}]
0
"#
),
indoc!(
r#"
A := U8 has [Eq { eq, eq1 }]
A := U8
has [
Eq {
eq,
eq1,
},
]
0
"#
),
);
expr_formats_same(indoc!(
r#"
A := a | a has Other
has [Eq { eq }, Hash { hash }]
0
"#
));
expr_formats_same(indoc!(
r#"
A := U8 has [Eq {}]
0
"#
));
}
#[test]
fn comments_in_multiline_tag_union_annotation() {
expr_formats_to(