mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-02 19:32:17 +00:00
Format has clauses with impls
This commit is contained in:
parent
85cbab0193
commit
3c65fbcf35
3 changed files with 67 additions and 2 deletions
|
@ -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();
|
||||
|
|
|
@ -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(',');
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue