diff --git a/src/fmt/expr.rs b/src/fmt/expr.rs index 2775e4c622..9ecc40a03a 100644 --- a/src/fmt/expr.rs +++ b/src/fmt/expr.rs @@ -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)); diff --git a/tests/test_format.rs b/tests/test_format.rs index 2d876899c8..085b93c585 100644 --- a/tests/test_format.rs +++ b/tests/test_format.rs @@ -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!(