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
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
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)
self.expr(fun)
.append(wrap_args(
args.iter()
.map(|a| (self.call_arg(a, needs_curly), needs_curly)),
))
.group(),
}
.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);
}

View File

@ -19,8 +19,8 @@ pub fn insert(
value v: value,
) -> Dict<key, value> {
Dict {
inner: do_insert_with(self.inner, k, v, fn(_, left, _right) { Some(left) })}
inner: do_insert_with(self.inner, k, v, fn(_, left, _right) { Some(left) }),
}
}
pub fn union_with(

View File

@ -32,15 +32,18 @@ test expect_ford1() {
owner == #"" && wheels == 4 && truck_bed_limit == 10000
}
test expect_ford2() {
let initial_car = Ford {remote_connect: #"", owner: #[34,34,34,34,34], wheels: 6, truck_bed_limit: 15000, car_doors: []}
expect Ford { owner, wheels, remote_connect, .. } = initial_car
owner == #[34,34,34,34,34] && wheels == 6 && remote_connect == #""
let initial_car =
Ford {
remote_connect: #"",
owner: #"2222222222",
wheels: 6,
truck_bed_limit: 15000,
car_doors: [],
}
expect Ford { owner, wheels, remote_connect, .. } = initial_car
owner == #"2222222222" && wheels == 6 && remote_connect == #""
}
test expect_list1() {
let initial_car = [5, 6, 7]
@ -48,18 +51,15 @@ test expect_list1() {
a == 5 && b == 6 && c == 7
}
test expect_list2() {
let initial_car = [5, 6, 7]
expect [a, ..d] = initial_car
a == 5 && d == [6, 7]
}
test expect_list3() {
let initial_car = builtin.list_data([builtin.i_data(5), builtin.i_data(6), builtin.i_data(7)])
let initial_car =
builtin.list_data([builtin.i_data(5), builtin.i_data(6), builtin.i_data(7)])
expect [a, ..d]: List<Int> = initial_car
a == 5 && d == [6, 7]
}

View File

@ -20,10 +20,10 @@ for convenience.
## Test Coverage
- [ ] Purpose
- [x] Spend
- [x] Mint
- [x] Withdraw
- [ ] Publish
- [x] spend
- [x] mint
- [x] withdraw
- [ ] publish
- [ ] Transaction
- [ ] inputs
@ -35,15 +35,15 @@ for convenience.
- [ ] pointer
- [x] value
- [x] datum
- [x] None
- [x] Hash
- [x] Inline
- [x] none
- [x] hash
- [x] inline
- [x] script
- [x] None
- [x] Reference
- [x] none
- [x] reference
- [x] values
- [x] Pure Ada
- [x] Native assets
- [x] pure ada
- [x] native assets
- [x] fee
- [x] mint
- [ ] certificates

View File

@ -60,9 +60,9 @@ fn assert_second_output(output) {
Inline(
VerificationKeyCredential(
#"66666666666666666666666666666666666666666666666666666666",
))
)
,
),
),
),
when output.datum is {
InlineDatum(_) -> True
_ -> error("expected inline datum")

View File

@ -10,15 +10,15 @@ fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
Inline(
VerificationKeyCredential(
#"22222222222222222222222222222222222222222222222222222222",
))
),
)
let bob =
Inline(
ScriptCredential(
#"afddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72",
))
),
)
[
when dict.get(ctx.transaction.withdrawals, alice) is {