fix: panic in formatter when substracting u8 0 - 1
This commit is contained in:
parent
6869f73033
commit
7680d33663
|
@ -1146,7 +1146,7 @@ impl<'comments> Formatter<'comments> {
|
|||
let precedence = name.precedence();
|
||||
|
||||
let left_precedence = left.binop_precedence();
|
||||
let right_precedence = right.binop_precedence();
|
||||
let right_precedence = dbg!(right).binop_precedence();
|
||||
|
||||
let left = self.expr(left, false);
|
||||
let right = self.expr(right, false);
|
||||
|
@ -1155,7 +1155,7 @@ impl<'comments> Formatter<'comments> {
|
|||
.append(" ")
|
||||
.append(name)
|
||||
.append(" ")
|
||||
.append(self.operator_side(right, precedence, right_precedence - 1))
|
||||
.append(self.operator_side(right, precedence, right_precedence.saturating_sub(1)))
|
||||
}
|
||||
|
||||
pub fn operator_side<'a>(&mut self, doc: Document<'a>, op: u8, side: u8) -> Document<'a> {
|
||||
|
@ -1745,7 +1745,7 @@ impl<'comments> Formatter<'comments> {
|
|||
let right = self.clause_guard(right);
|
||||
self.operator_side(left, name_precedence, left_precedence)
|
||||
.append(name)
|
||||
.append(self.operator_side(right, name_precedence, right_precedence - 1))
|
||||
.append(self.operator_side(right, name_precedence, right_precedence.saturating_sub(1)))
|
||||
}
|
||||
|
||||
fn clause_guard<'a>(&mut self, clause_guard: &'a UntypedClauseGuard) -> Document<'a> {
|
||||
|
|
|
@ -87,6 +87,39 @@ fn format_grouped_expression() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_grouped_expression_2() {
|
||||
assert_format!(
|
||||
r#"
|
||||
fn foo() {
|
||||
( y == x ) |> f
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_grouped_expression_3() {
|
||||
assert_format!(
|
||||
r#"
|
||||
fn foo() {
|
||||
{ x |> f } == y
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_grouped_expression_4() {
|
||||
assert_format!(
|
||||
r#"
|
||||
fn foo() {
|
||||
x |> { f == y }
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_validator() {
|
||||
assert_format!(
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/format.rs
|
||||
description: "Code:\n\nfn foo() {\n y == { x |> f }\n}\n"
|
||||
---
|
||||
fn foo() {
|
||||
y == ( x |> f )
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/format.rs
|
||||
description: "Code:\n\nfn foo() {\n ( y == x ) |> f\n}\n"
|
||||
---
|
||||
fn foo() {
|
||||
( y == x ) |> f
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/format.rs
|
||||
description: "Code:\n\nfn foo() {\n { x |> f } == y\n}\n"
|
||||
---
|
||||
fn foo() {
|
||||
( x |> f ) == y
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/format.rs
|
||||
description: "Code:\n\nfn foo() {\n x |> { f == y }\n}\n"
|
||||
---
|
||||
fn foo() {
|
||||
x |> f == y
|
||||
}
|
||||
|
Loading…
Reference in New Issue