Fix formatting of long multiline if/is expressions.

This commit is contained in:
KtorZ 2024-09-15 14:59:47 +02:00
parent 12c0d0bc04
commit 47a15cf8b2
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
6 changed files with 73 additions and 4 deletions

View File

@ -10,6 +10,7 @@
- **aiken-project**: Fix documentation link-tree generation messing up with modules when re-inserting the same module. @KtorZ
- **aiken-lang**: Fix formatter adding extra unnecessary newlines after literal lists clause values or assignments. @KtorZ
- **aiken0lang**: Fix formatting of long multi-line if/is expressions. @KtorZ
### Removed

View File

@ -1323,10 +1323,7 @@ impl<'comments> Formatter<'comments> {
.group()
};
break_("", " ")
.append("is")
.append(break_("", " "))
.append(is)
break_("", " ").append("is ").append(is)
}
None => nil(),
})

View File

@ -3264,3 +3264,15 @@ fn constant_usage() {
}] if name == "some_string_constant"
));
}
#[test]
fn wrong_arity_on_known_builtin() {
let source_code = r#"
const foo: Option<Int> = Some()
"#;
assert!(matches!(
check_validator(parse(source_code)),
Err((_, Error::IncorrectFunctionCallArity { .. }))
))
}

View File

@ -1388,3 +1388,35 @@ fn callback_and_op() {
"#
);
}
#[test]
fn multiline_if_is() {
assert_format!(
r#"
fn foo() {
if first_asset
is
Pair(first_asset_policy, first_asset_tokens): Pair<PolicyId, Data> {
True
} else {
False }
}
"#
);
}
#[test]
fn multiline_if_is_2() {
assert_format!(
r#"
fn foo() {
if [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
is
Pair(first_asset_policy, first_asset_tokens): Pair<PolicyId, Data> {
True
} else {
False }
}
"#
);
}

View File

@ -0,0 +1,12 @@
---
source: crates/aiken-lang/src/tests/format.rs
description: "Code:\n\nfn foo() {\n if first_asset\n is\n Pair(first_asset_policy, first_asset_tokens): Pair<PolicyId, Data> {\n True\n } else {\n False }\n}\n"
---
fn foo() {
if first_asset
is Pair(first_asset_policy, first_asset_tokens): Pair<PolicyId, Data> {
True
} else {
False
}
}

View File

@ -0,0 +1,15 @@
---
source: crates/aiken-lang/src/tests/format.rs
description: "Code:\n\nfn foo() {\n if [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]\n is\n Pair(first_asset_policy, first_asset_tokens): Pair<PolicyId, Data> {\n True\n } else {\n False }\n}\n"
---
fn foo() {
if [
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 0,
]
is Pair(first_asset_policy, first_asset_tokens): Pair<PolicyId, Data> {
True
} else {
False
}
}