mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Merge pull request #3079 from rtfeldman/formatter-empty-record-patterns
Formatter empty record patterns
This commit is contained in:
commit
3bbfb397d2
10 changed files with 77 additions and 20 deletions
|
@ -85,10 +85,10 @@ impl<'a> Formattable for Pattern<'a> {
|
|||
RecordDestructure(loc_patterns) => {
|
||||
buf.indent(indent);
|
||||
buf.push_str("{");
|
||||
|
||||
if !loc_patterns.is_empty() {
|
||||
buf.spaces(1);
|
||||
|
||||
let mut it = loc_patterns.iter().peekable();
|
||||
|
||||
while let Some(loc_pattern) = it.next() {
|
||||
loc_pattern.format(buf, indent);
|
||||
|
||||
|
@ -97,6 +97,8 @@ impl<'a> Formattable for Pattern<'a> {
|
|||
buf.spaces(1);
|
||||
}
|
||||
}
|
||||
buf.spaces(1);
|
||||
}
|
||||
|
||||
buf.push_str("}");
|
||||
}
|
||||
|
|
|
@ -2727,6 +2727,61 @@ mod test_fmt {
|
|||
#[test]
|
||||
fn empty_record() {
|
||||
expr_formats_same("{}");
|
||||
expr_formats_to("{ }", "{}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_record_patterns() {
|
||||
expr_formats_to(
|
||||
indoc!(
|
||||
r#"
|
||||
f = \{ } -> "Hello World"
|
||||
|
||||
f
|
||||
"#
|
||||
),
|
||||
indoc!(
|
||||
r#"
|
||||
f = \{} -> "Hello World"
|
||||
|
||||
f
|
||||
"#
|
||||
),
|
||||
);
|
||||
|
||||
expr_formats_to(
|
||||
indoc!(
|
||||
r#"
|
||||
f = \a, b -> { }
|
||||
|
||||
f
|
||||
"#
|
||||
),
|
||||
indoc!(
|
||||
r#"
|
||||
f = \a, b -> {}
|
||||
|
||||
f
|
||||
"#
|
||||
),
|
||||
);
|
||||
|
||||
expr_formats_to(
|
||||
indoc!(
|
||||
r#"
|
||||
{ } <- f a b
|
||||
|
||||
{}
|
||||
"#
|
||||
),
|
||||
indoc!(
|
||||
r#"
|
||||
{} <- f a b
|
||||
|
||||
{}
|
||||
"#
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue