fix: binop associativity formatting
it seems we can fix this by changing which side gets subtracted by 1 depending on the op associativity. BinOp::Or & BinOp::And are right associative while the other bin ops are left associative. closes #893 Co-authored-by: Kasey White <kwhitemsg@gmail.com>
This commit is contained in:
@@ -755,3 +755,25 @@ fn fuzzer_annotations() {
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preserve_associativity_parens_in_binop() {
|
||||
assert_format!(
|
||||
r#"
|
||||
pub fn bar() {
|
||||
( a || b ) || c
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn superfluous_parens_in_binop() {
|
||||
assert_format!(
|
||||
r#"
|
||||
pub fn bar() {
|
||||
a && ( b && c )
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,5 +11,5 @@ fn bar() {
|
||||
}
|
||||
|
||||
fn baz() {
|
||||
a || ( b && c || d )
|
||||
a || b && c || d
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/tests/format.rs
|
||||
description: "Code:\n\npub fn bar() {\n ( a || b ) || c\n}\n"
|
||||
---
|
||||
pub fn bar() {
|
||||
( a || b ) || c
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/tests/format.rs
|
||||
description: "Code:\n\npub fn bar() {\n a && ( b && c )\n}\n"
|
||||
---
|
||||
pub fn bar() {
|
||||
a && b && c
|
||||
}
|
||||
Reference in New Issue
Block a user