Fix formatting of long multiline if/is expressions.
This commit is contained in:
@@ -1323,10 +1323,7 @@ impl<'comments> Formatter<'comments> {
|
||||
.group()
|
||||
};
|
||||
|
||||
break_("", " ")
|
||||
.append("is")
|
||||
.append(break_("", " "))
|
||||
.append(is)
|
||||
break_("", " ").append("is ").append(is)
|
||||
}
|
||||
None => nil(),
|
||||
})
|
||||
|
||||
@@ -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 { .. }))
|
||||
))
|
||||
}
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
12
crates/aiken-lang/src/tests/snapshots/multiline_if_is.snap
vendored
Normal file
12
crates/aiken-lang/src/tests/snapshots/multiline_if_is.snap
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
15
crates/aiken-lang/src/tests/snapshots/multiline_if_is_2.snap
vendored
Normal file
15
crates/aiken-lang/src/tests/snapshots/multiline_if_is_2.snap
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user