Record updating format

This commit is contained in:
Chad Stearns 2020-01-05 16:34:34 -05:00
parent 1706e24fd1
commit b3bce7b0c4
2 changed files with 66 additions and 0 deletions

View File

@ -537,6 +537,19 @@ pub fn fmt_record<'a>(
) {
buf.push('{');
match _update {
None => {},
// We are presuming this to be a Var()
// If it wasnt a Var() we would not have made
// it this far. For example "{ 4 & hello = 9 }"
// doesnt make sense.
Some(record_var) => {
buf.push(' ');
fmt_expr(buf, &record_var.value, indent, false, false);
buf.push_str(" &");
},
}
let is_multiline = loc_fields
.iter()
.any(|loc_field| is_multiline_field(&loc_field.value));

View File

@ -515,6 +515,59 @@ mod test_format {
));
}
#[test]
fn record_updating() {
expr_formats_same(indoc!(
r#"
{ shoes & leftShoe: nothing }
"#
));
expr_formats_to(indoc!(
r#"
{ shoes & rightShoe : nothing }
"#
),indoc!(
r#"
{ shoes & rightShoe: nothing }
"#
));
expr_formats_to(indoc!(
r#"
{ shoes & rightShoe : nothing }
"#
),indoc!(
r#"
{ shoes & rightShoe: nothing }
"#
));
expr_formats_same(indoc!(
r#"
{ shoes &
rightShoe: newRightShoe,
leftShoe: newLeftShoe
}
"#
));
expr_formats_to(indoc!(
r#"
{ shoes
& rightShoe: bareFoot
, leftShoe: bareFoot }
"#
), indoc!(
r#"
{ shoes &
rightShoe: bareFoot,
leftShoe: bareFoot
}
"#
));
}
// #[test]
// fn record_field_destructuring() {
// expr_formats_same(indoc!(