Fix few formatter annoyances.
This commit is contained in:
parent
799546b654
commit
a9a7a4f977
|
@ -12,7 +12,8 @@
|
|||
- **aiken-lang**: Aiken IR now interns variables while building up to ensure uniqueness for local vars. @Microproofs
|
||||
- **aiken-lang**: Fix reification of `Data` (failing to reify) & `PRNG` (missing variants' arguments). @KtorZ
|
||||
- **aiken-lang**: Adjust reification of `String` to be shown as plain UTF-8 text strings (instead of hex-encoded byte array). @KtorZ
|
||||
|
||||
- **aiken-lang**: Fix formatting of long if-condition over multiline. @KtorZ & @Microproofs
|
||||
- **aiken-lang**: Fix formatting of standalone logical binary chains (`and` & `or`) in functions. @KtorZ
|
||||
|
||||
### Removed
|
||||
|
||||
|
|
|
@ -712,9 +712,9 @@ impl<'comments> Formatter<'comments> {
|
|||
) -> Document<'a> {
|
||||
let args = wrap_args(args.iter().map(|e| (self.fn_arg(e), false))).group();
|
||||
let body = match body {
|
||||
UntypedExpr::Trace { .. } | UntypedExpr::When { .. } => {
|
||||
self.expr(body, true).force_break()
|
||||
}
|
||||
UntypedExpr::Trace { .. }
|
||||
| UntypedExpr::When { .. }
|
||||
| UntypedExpr::LogicalOpChain { .. } => self.expr(body, true).force_break(),
|
||||
_ => self.expr(body, true),
|
||||
};
|
||||
|
||||
|
@ -1268,7 +1268,7 @@ impl<'comments> Formatter<'comments> {
|
|||
final_else: &'a UntypedExpr,
|
||||
) -> Document<'a> {
|
||||
let if_branches = self
|
||||
.if_branch(break_("if", "if "), branches.first())
|
||||
.if_branch(Document::Str("if "), branches.first())
|
||||
.append(join(
|
||||
branches[1..].iter().map(|branch| {
|
||||
self.if_branch(line().append(break_("} else if", "} else if ")), branch)
|
||||
|
@ -1330,7 +1330,7 @@ impl<'comments> Formatter<'comments> {
|
|||
}
|
||||
None => nil(),
|
||||
})
|
||||
.append(break_("{", " {"))
|
||||
.append(Document::Str(" {"))
|
||||
.group();
|
||||
|
||||
let if_body = line().append(self.expr(&branch.body, true)).nest(INDENT);
|
||||
|
|
|
@ -1352,3 +1352,38 @@ fn multiline_constant() {
|
|||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiline_if_condition() {
|
||||
assert_format!(
|
||||
r#"
|
||||
fn foo() {
|
||||
if
|
||||
list.is_empty(outputs) && (
|
||||
!list.is_empty(mint_redeemers) || !list.is_empty(cert_redeemers)
|
||||
){
|
||||
True
|
||||
} else {
|
||||
False
|
||||
}
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn callback_and_op() {
|
||||
assert_format!(
|
||||
r#"
|
||||
fn foo() {
|
||||
let labels = list.filter(labels, fn(lbl) {
|
||||
and {
|
||||
lbl != sc_missing_admin_approval_for_foreign_assets,
|
||||
lbl != sc_missing_admin_approval_for_certificate_publish,
|
||||
}
|
||||
})
|
||||
labels
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/format.rs
|
||||
description: "Code:\n\nfn foo() {\n let labels = list.filter(labels, fn(lbl) {\n and {\n lbl != sc_missing_admin_approval_for_foreign_assets,\n lbl != sc_missing_admin_approval_for_certificate_publish,\n }\n })\n labels\n}\n"
|
||||
---
|
||||
fn foo() {
|
||||
let labels =
|
||||
list.filter(
|
||||
labels,
|
||||
fn(lbl) {
|
||||
and {
|
||||
lbl != sc_missing_admin_approval_for_foreign_assets,
|
||||
lbl != sc_missing_admin_approval_for_certificate_publish,
|
||||
}
|
||||
},
|
||||
)
|
||||
labels
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/format.rs
|
||||
description: "Code:\n\nfn foo() {\n if\n list.is_empty(outputs) && (\n !list.is_empty(mint_redeemers) || !list.is_empty(cert_redeemers)\n ){\n True\n } else {\n False\n }\n}\n"
|
||||
---
|
||||
fn foo() {
|
||||
if list.is_empty(outputs) && (
|
||||
!list.is_empty(mint_redeemers) || !list.is_empty(cert_redeemers)
|
||||
) {
|
||||
True
|
||||
} else {
|
||||
False
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue