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:
parent
47e77aa819
commit
7251b2d01e
|
@ -843,30 +843,12 @@ impl<'comments> Formatter<'comments> {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
match args {
|
self.expr(fun)
|
||||||
[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(
|
.append(wrap_args(
|
||||||
args.iter()
|
args.iter()
|
||||||
.map(|a| (self.call_arg(a, needs_curly), needs_curly)),
|
.map(|a| (self.call_arg(a, needs_curly), needs_curly)),
|
||||||
))
|
))
|
||||||
.group(),
|
.group()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn if_expr<'a>(
|
pub fn if_expr<'a>(
|
||||||
|
|
|
@ -305,3 +305,46 @@ fn test_format_bytearray_literals() {
|
||||||
|
|
||||||
assert_fmt(src, expected);
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@ pub fn insert(
|
||||||
value v: value,
|
value v: value,
|
||||||
) -> Dict<key, value> {
|
) -> Dict<key, value> {
|
||||||
Dict {
|
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(
|
pub fn union_with(
|
||||||
|
|
|
@ -32,34 +32,34 @@ test expect_ford1() {
|
||||||
owner == #"" && wheels == 4 && truck_bed_limit == 10000
|
owner == #"" && wheels == 4 && truck_bed_limit == 10000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
test expect_ford2() {
|
test expect_ford2() {
|
||||||
let initial_car = Ford {remote_connect: #"", owner: #[34,34,34,34,34], wheels: 6, truck_bed_limit: 15000, car_doors: []}
|
let initial_car =
|
||||||
|
Ford {
|
||||||
|
remote_connect: #"",
|
||||||
|
owner: #"2222222222",
|
||||||
|
wheels: 6,
|
||||||
|
truck_bed_limit: 15000,
|
||||||
|
car_doors: [],
|
||||||
|
}
|
||||||
expect Ford { owner, wheels, remote_connect, .. } = initial_car
|
expect Ford { owner, wheels, remote_connect, .. } = initial_car
|
||||||
owner == #[34,34,34,34,34] && wheels == 6 && remote_connect == #""
|
owner == #"2222222222" && wheels == 6 && remote_connect == #""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test expect_list1() {
|
test expect_list1() {
|
||||||
let initial_car = [5,6,7]
|
let initial_car = [5, 6, 7]
|
||||||
expect [a,b,c] = initial_car
|
expect [a, b, c] = initial_car
|
||||||
a == 5 && b == 6 && c == 7
|
a == 5 && b == 6 && c == 7
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test expect_list2() {
|
test expect_list2() {
|
||||||
let initial_car = [5,6,7]
|
let initial_car = [5, 6, 7]
|
||||||
expect [a, ..d] = initial_car
|
expect [a, ..d] = initial_car
|
||||||
a == 5 && d == [6, 7]
|
a == 5 && d == [6, 7]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test expect_list3() {
|
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
|
expect [a, ..d]: List<Int> = initial_car
|
||||||
a == 5 && d == [6, 7]
|
a == 5 && d == [6, 7]
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,10 @@ for convenience.
|
||||||
## Test Coverage
|
## Test Coverage
|
||||||
|
|
||||||
- [ ] Purpose
|
- [ ] Purpose
|
||||||
- [x] Spend
|
- [x] spend
|
||||||
- [x] Mint
|
- [x] mint
|
||||||
- [x] Withdraw
|
- [x] withdraw
|
||||||
- [ ] Publish
|
- [ ] publish
|
||||||
|
|
||||||
- [ ] Transaction
|
- [ ] Transaction
|
||||||
- [ ] inputs
|
- [ ] inputs
|
||||||
|
@ -35,15 +35,15 @@ for convenience.
|
||||||
- [ ] pointer
|
- [ ] pointer
|
||||||
- [x] value
|
- [x] value
|
||||||
- [x] datum
|
- [x] datum
|
||||||
- [x] None
|
- [x] none
|
||||||
- [x] Hash
|
- [x] hash
|
||||||
- [x] Inline
|
- [x] inline
|
||||||
- [x] script
|
- [x] script
|
||||||
- [x] None
|
- [x] none
|
||||||
- [x] Reference
|
- [x] reference
|
||||||
- [x] values
|
- [x] values
|
||||||
- [x] Pure Ada
|
- [x] pure ada
|
||||||
- [x] Native assets
|
- [x] native assets
|
||||||
- [x] fee
|
- [x] fee
|
||||||
- [x] mint
|
- [x] mint
|
||||||
- [ ] certificates
|
- [ ] certificates
|
||||||
|
|
|
@ -60,9 +60,9 @@ fn assert_second_output(output) {
|
||||||
Inline(
|
Inline(
|
||||||
VerificationKeyCredential(
|
VerificationKeyCredential(
|
||||||
#"66666666666666666666666666666666666666666666666666666666",
|
#"66666666666666666666666666666666666666666666666666666666",
|
||||||
))
|
),
|
||||||
)
|
),
|
||||||
,
|
),
|
||||||
when output.datum is {
|
when output.datum is {
|
||||||
InlineDatum(_) -> True
|
InlineDatum(_) -> True
|
||||||
_ -> error("expected inline datum")
|
_ -> error("expected inline datum")
|
||||||
|
|
|
@ -10,15 +10,15 @@ fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
|
||||||
Inline(
|
Inline(
|
||||||
VerificationKeyCredential(
|
VerificationKeyCredential(
|
||||||
#"22222222222222222222222222222222222222222222222222222222",
|
#"22222222222222222222222222222222222222222222222222222222",
|
||||||
))
|
),
|
||||||
|
)
|
||||||
|
|
||||||
let bob =
|
let bob =
|
||||||
Inline(
|
Inline(
|
||||||
ScriptCredential(
|
ScriptCredential(
|
||||||
#"afddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72",
|
#"afddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72",
|
||||||
))
|
),
|
||||||
|
)
|
||||||
|
|
||||||
[
|
[
|
||||||
when dict.get(ctx.transaction.withdrawals, alice) is {
|
when dict.get(ctx.transaction.withdrawals, alice) is {
|
||||||
|
|
Loading…
Reference in New Issue