fmt: assert (a == b) -> assert a == b (#8351)

pull/8353/head
zakuro 2021-01-26 18:36:21 +09:00 committed by GitHub
parent 7bb9c0e7b3
commit 22847d1ec3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 9 deletions

View File

@ -715,17 +715,17 @@ fn test_sort() {
// //
mut users := [User{22, 'Peter'}, User{20, 'Bob'}, User{25, 'Alice'}] mut users := [User{22, 'Peter'}, User{20, 'Bob'}, User{25, 'Alice'}]
users.sort(a.age < b.age) users.sort(a.age < b.age)
assert (users[0].age == 20) assert users[0].age == 20
assert (users[1].age == 22) assert users[1].age == 22
assert (users[2].age == 25) assert users[2].age == 25
assert (users[0].name == 'Bob') assert users[0].name == 'Bob'
assert (users[1].name == 'Peter') assert users[1].name == 'Peter'
assert (users[2].name == 'Alice') assert users[2].name == 'Alice'
// //
users.sort(a.age > b.age) users.sort(a.age > b.age)
assert (users[0].age == 25) assert users[0].age == 25
assert (users[1].age == 22) assert users[1].age == 22
assert (users[2].age == 20) assert users[2].age == 20
// //
users.sort(a.name < b.name) // Test sorting by string fields users.sort(a.name < b.name) // Test sorting by string fields
// assert users.map(it.name).join(' ') == 'Alice Bob Peter' // assert users.map(it.name).join(' ') == 'Alice Bob Peter'

View File

@ -2209,6 +2209,14 @@ pub fn (mut f Fmt) assign_stmt(node ast.AssignStmt) {
pub fn (mut f Fmt) assert_stmt(node ast.AssertStmt) { pub fn (mut f Fmt) assert_stmt(node ast.AssertStmt) {
f.write('assert ') 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
}
}
f.expr(node.expr) f.expr(node.expr)
f.writeln('') f.writeln('')
} }

View File

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

View File

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