Make sure unary operators around function calls get parens

This commit is contained in:
Joshua Warner 2021-11-26 17:17:20 -08:00
parent 0a58d6e60e
commit e9d22699ed
2 changed files with 20 additions and 1 deletions

View File

@ -258,7 +258,7 @@ impl<'a> Formattable<'a> for Expr<'a> {
}
}
sub_expr.format_with_options(buf, parens, newlines, indent);
sub_expr.format_with_options(buf, Parens::InApply, newlines, indent);
}
AccessorFunction(key) => {
buf.push('.');

View File

@ -2324,6 +2324,25 @@ mod test_fmt {
));
}
#[test]
fn unary_call_parens() {
expr_formats_same(indoc!(
r#"
!(f 1)
"#
));
}
#[test]
fn unary_call_no_parens() {
// TIL: Negating a function "does what you might expect"... which is cool!
expr_formats_same(indoc!(
r#"
!f 1
"#
));
}
// BINARY OP
#[test]