fmt: assert (a == b) -> assert a == b (#8351)
parent
7bb9c0e7b3
commit
22847d1ec3
|
@ -715,17 +715,17 @@ fn test_sort() {
|
|||
//
|
||||
mut users := [User{22, 'Peter'}, User{20, 'Bob'}, User{25, 'Alice'}]
|
||||
users.sort(a.age < b.age)
|
||||
assert (users[0].age == 20)
|
||||
assert (users[1].age == 22)
|
||||
assert (users[2].age == 25)
|
||||
assert (users[0].name == 'Bob')
|
||||
assert (users[1].name == 'Peter')
|
||||
assert (users[2].name == 'Alice')
|
||||
assert users[0].age == 20
|
||||
assert users[1].age == 22
|
||||
assert users[2].age == 25
|
||||
assert users[0].name == 'Bob'
|
||||
assert users[1].name == 'Peter'
|
||||
assert users[2].name == 'Alice'
|
||||
//
|
||||
users.sort(a.age > b.age)
|
||||
assert (users[0].age == 25)
|
||||
assert (users[1].age == 22)
|
||||
assert (users[2].age == 20)
|
||||
assert users[0].age == 25
|
||||
assert users[1].age == 22
|
||||
assert users[2].age == 20
|
||||
//
|
||||
users.sort(a.name < b.name) // Test sorting by string fields
|
||||
// assert users.map(it.name).join(' ') == 'Alice Bob Peter'
|
||||
|
|
|
@ -2209,6 +2209,14 @@ pub fn (mut f Fmt) assign_stmt(node ast.AssignStmt) {
|
|||
|
||||
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
|
||||
}
|
||||
}
|
||||
f.expr(node.expr)
|
||||
f.writeln('')
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
fn f() {
|
||||
assert 0 == 0
|
||||
assert 0 < 1
|
||||
assert (1 + 2) == 3
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
fn f() {
|
||||
assert (0 == 0)
|
||||
assert (0 < 1)
|
||||
assert ((1 + 2) == 3)
|
||||
}
|
Loading…
Reference in New Issue