fmt: remove unnecessary paren in assert stmt (#12546)

pull/12541/head
zakuro 2021-11-23 14:30:54 +09:00 committed by GitHub
parent fbe2b5cb58
commit 93bdff5589
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 12 deletions

View File

@ -711,15 +711,11 @@ fn expr_is_single_line(expr ast.Expr) bool {
pub fn (mut f Fmt) assert_stmt(node ast.AssertStmt) {
f.write('assert ')
if node.expr is ast.ParExpr {
if node.expr.expr is ast.InfixExpr {
infix := node.expr.expr
f.expr(infix)
f.writeln('')
return
mut expr := node.expr
for expr is ast.ParExpr {
expr = (expr as ast.ParExpr).expr
}
}
f.expr(node.expr)
f.expr(expr)
f.writeln('')
}

View File

@ -2,4 +2,5 @@ fn f() {
assert 0 == 0
assert 0 < 1
assert (1 + 2) == 3
assert true
}

View File

@ -1,5 +1,6 @@
fn f() {
assert (0 == 0)
assert (0 < 1)
assert ((1 + 2) == 3)
assert (((((1 + 2) == 3))))
assert (((true)))
}

View File

@ -25,16 +25,19 @@ fn match_vec(v Vec) {
fn match_classic_num() {
match 42 {
0 {
assert (false)
assert false
(false)
}
1 {
assert (false)
assert false
(false)
}
42 {
println('life')
}
else {
assert (false)
assert false
(false)
}
}
}