mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: assert (a == b) -> assert a == b (#8351)
This commit is contained in:
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('')
|
||||
}
|
||||
|
5
vlib/v/fmt/tests/asserts_expected.vv
Normal file
5
vlib/v/fmt/tests/asserts_expected.vv
Normal file
@ -0,0 +1,5 @@
|
||||
fn f() {
|
||||
assert 0 == 0
|
||||
assert 0 < 1
|
||||
assert (1 + 2) == 3
|
||||
}
|
5
vlib/v/fmt/tests/asserts_input.vv
Normal file
5
vlib/v/fmt/tests/asserts_input.vv
Normal file
@ -0,0 +1,5 @@
|
||||
fn f() {
|
||||
assert (0 == 0)
|
||||
assert (0 < 1)
|
||||
assert ((1 + 2) == 3)
|
||||
}
|
Loading…
Reference in New Issue
Block a user