Fix 'Pair' formatter inside forced unbroken components.

This commit is contained in:
KtorZ 2024-08-13 17:05:41 +02:00
parent 7501538053
commit 5067aad0d8
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
6 changed files with 107 additions and 34 deletions

View File

@ -998,14 +998,12 @@ impl<'comments> Formatter<'comments> {
wrap_args(elems.iter().map(|e| (self.wrap_expr(e), false))).group()
}
UntypedExpr::Pair { fst, snd, .. } => "Pair"
.to_doc()
.append("(")
.append(self.expr(fst, false))
.append(break_(",", ", "))
.append(self.expr(snd, false))
.append(")")
.group(),
UntypedExpr::Pair { fst, snd, .. } => {
let elems = [fst, snd];
"Pair"
.to_doc()
.append(wrap_args(elems.iter().map(|e| (self.wrap_expr(e), false))).group())
}
UntypedExpr::TupleIndex { index, tuple, .. } => {
let suffix = Ordinal(*index + 1).suffix().to_doc();

View File

@ -1116,3 +1116,27 @@ fn format_long_imports() {
"#
);
}
#[test]
fn format_long_pair() {
assert_format!(
r#"
test foo() {
expect(Some([
Pair(GovernanceActionId { transaction: only7s, proposal_procedure: 2 },
Abstain),
])) == whatever
expect(Some([
Foo(GovernanceActionId { transaction: only7s, proposal_procedure: 2 },
Abstain),
])) == whatever
expect(Some([
(GovernanceActionId { transaction: only7s, proposal_procedure: 2 },
Abstain),
])) == whatever
}
"#
);
}

View File

@ -0,0 +1,35 @@
---
source: crates/aiken-lang/src/tests/format.rs
description: "Code:\n\ntest foo() {\n expect(Some([\n Pair(GovernanceActionId { transaction: only7s, proposal_procedure: 2 },\n Abstain),\n ])) == whatever\n\n expect(Some([\n Foo(GovernanceActionId { transaction: only7s, proposal_procedure: 2 },\n Abstain),\n ])) == whatever\n\n expect(Some([\n (GovernanceActionId { transaction: only7s, proposal_procedure: 2 },\n Abstain),\n ])) == whatever\n}\n"
---
test foo() {
expect
Some(
[
Pair(
GovernanceActionId { transaction: only7s, proposal_procedure: 2 },
Abstain,
),
],
) == whatever
expect
Some(
[
Foo(
GovernanceActionId { transaction: only7s, proposal_procedure: 2 },
Abstain,
),
],
) == whatever
expect
Some(
[
(
GovernanceActionId { transaction: only7s, proposal_procedure: 2 },
Abstain,
),
],
) == whatever
}

View File

@ -46,10 +46,12 @@ validator {
expect
TreasuryWithdrawal {
beneficiaries: [
Pair(VerificationKey(
#"11111111111111111111111111111111111111111111111111111111",
Pair(
VerificationKey(
#"11111111111111111111111111111111111111111111111111111111",
),
1_000_000,
),
1_000_000),
],
guardrails: None,
} == action

View File

@ -75,13 +75,15 @@ fn assert_inputs(inputs: List<Input>) {
fn assert_redeemers(redeemers: Pairs<ScriptPurpose, Data>) {
expect
[
Pair(Spend(
OutputReference {
transaction_id: #"0000000000000000000000000000000000000000000000000000000000000000",
output_index: 0,
},
Pair(
Spend(
OutputReference {
transaction_id: #"0000000000000000000000000000000000000000000000000000000000000000",
output_index: 0,
},
),
void(),
),
void()),
] == redeemers
Void
}

View File

@ -35,14 +35,18 @@ validator {
expect
Some(
Pair(ConstitutionalCommitteeMember(VerificationKey(only0s)),
[
Pair(GovernanceActionId {
transaction: only9s,
proposal_procedure: 152,
},
No),
]),
Pair(
ConstitutionalCommitteeMember(VerificationKey(only0s)),
[
Pair(
GovernanceActionId {
transaction: only9s,
proposal_procedure: 152,
},
No,
),
],
),
) == list.at(votes, 1)
expect Some(Pair(DelegateRepresentative(Script(..)), [_, ..])) =
@ -50,15 +54,23 @@ validator {
expect
Some(
Pair(DelegateRepresentative(VerificationKey(only0s)),
[
Pair(GovernanceActionId { transaction: only7s, proposal_procedure: 2 },
Abstain),
Pair(GovernanceActionId { transaction: only8s, proposal_procedure: 1 },
Abstain),
Pair(GovernanceActionId { transaction: only9s, proposal_procedure: 0 },
Abstain),
]),
Pair(
DelegateRepresentative(VerificationKey(only0s)),
[
Pair(
GovernanceActionId { transaction: only7s, proposal_procedure: 2 },
Abstain,
),
Pair(
GovernanceActionId { transaction: only8s, proposal_procedure: 1 },
Abstain,
),
Pair(
GovernanceActionId { transaction: only9s, proposal_procedure: 0 },
Abstain,
),
],
),
) == list.at(votes, 3)
expect Some(Pair(StakePool(pool_id), [_, ..])) = list.at(votes, 4)