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
|
||||
};
|
||||
|
||||
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>(
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -32,34 +32,34 @@ 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: []}
|
||||
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 == #[34,34,34,34,34] && wheels == 6 && remote_connect == #""
|
||||
owner == #"2222222222" && wheels == 6 && remote_connect == #""
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
test expect_list1() {
|
||||
let initial_car = [5,6,7]
|
||||
expect [a,b,c] = initial_car
|
||||
let initial_car = [5, 6, 7]
|
||||
expect [a, b, c] = initial_car
|
||||
a == 5 && b == 6 && c == 7
|
||||
}
|
||||
|
||||
|
||||
|
||||
test expect_list2() {
|
||||
let initial_car = [5,6,7]
|
||||
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]
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -60,9 +60,9 @@ fn assert_second_output(output) {
|
|||
Inline(
|
||||
VerificationKeyCredential(
|
||||
#"66666666666666666666666666666666666666666666666666666666",
|
||||
))
|
||||
)
|
||||
,
|
||||
),
|
||||
),
|
||||
),
|
||||
when output.datum is {
|
||||
InlineDatum(_) -> True
|
||||
_ -> error("expected inline datum")
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue