Remove single-argument function call special-case in formatter

Not sure what this special case was trying to achieve, but it's not right. There's no need to handle function call with a single argument differently than the others.
This commit is contained in:
KtorZ
2023-02-15 17:20:58 +01:00
parent 47e77aa819
commit 7251b2d01e
7 changed files with 91 additions and 66 deletions

View File

@@ -843,30 +843,12 @@ impl<'comments> Formatter<'comments> {
false
};
match args {
[arg] if is_breakable_expr(&arg.value) => self
.expr(fun)
.append(if needs_curly {
break_(" {", " { ")
} else {
break_("(", "(")
})
.append(self.call_arg(arg, needs_curly))
.append(if needs_curly {
break_("}", " }")
} else {
break_(")", ")")
})
.group(),
_ => self
.expr(fun)
.append(wrap_args(
args.iter()
.map(|a| (self.call_arg(a, needs_curly), needs_curly)),
))
.group(),
}
self.expr(fun)
.append(wrap_args(
args.iter()
.map(|a| (self.call_arg(a, needs_curly), needs_curly)),
))
.group()
}
pub fn if_expr<'a>(

View File

@@ -305,3 +305,46 @@ fn test_format_bytearray_literals() {
assert_fmt(src, expected);
}
#[test]
fn test_nested_function_calls() {
let src = indoc! {r#"
fn foo(output) {
[
output.address.stake_credential == Some(
Inline(
VerificationKeyCredential(
#"66666666666666666666666666666666666666666666666666666666",
))
)
,
when output.datum is {
InlineDatum(_) -> True
_ -> error("expected inline datum")
},
]
|> list.and
}
"#};
let expected = indoc! {r#"
fn foo(output) {
[
output.address.stake_credential == Some(
Inline(
VerificationKeyCredential(
#"66666666666666666666666666666666666666666666666666666666",
),
),
),
when output.datum is {
InlineDatum(_) -> True
_ -> error("expected inline datum")
},
]
|> list.and
}
"#};
assert_fmt(src, expected);
}