Skip to content

Commit

Permalink
Fix ! block formatter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Dec 11, 2022
1 parent e74e7f5 commit ca1af6e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compiler-core/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,8 +1395,11 @@ impl<'comments> Formatter<'comments> {
}
}

fn negate<'a>(&mut self, value: &'a UntypedExpr) -> Document<'a> {
docvec!["!", self.wrap_expr(value)]
fn negate<'a>(&mut self, expr: &'a UntypedExpr) -> Document<'a> {
match expr {
UntypedExpr::BinOp { .. } => docvec!["!{ ", self.expr(expr), " }"],
_ => docvec!["!", self.wrap_expr(expr)],
}
}

fn use_<'a>(&mut self, use_: &'a Use) -> Document<'a> {
Expand Down
31 changes: 31 additions & 0 deletions compiler-core/src/format/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3834,6 +3834,7 @@ fn use_pipe_call() {
"#
);
}

#[test]
fn use_pipe_everything() {
assert_format!(
Expand All @@ -3847,3 +3848,33 @@ fn use_pipe_everything() {
"#
);
}

#[test]
fn not_and() {
assert_format!(
r#"pub fn main() {
!{ True && False }
}
"#
);
}

#[test]
fn not_or() {
assert_format!(
r#"pub fn main() {
!{ True || False }
}
"#
);
}

#[test]
fn not_add() {
assert_format!(
r#"pub fn main() {
!{ 1 + 3 }
}
"#
);
}

0 comments on commit ca1af6e

Please sign in to comment.