From 22847d1ec30c4e2ec81614d3142ab7cf4fad2d18 Mon Sep 17 00:00:00 2001 From: zakuro Date: Tue, 26 Jan 2021 18:36:21 +0900 Subject: [PATCH] fmt: assert (a == b) -> assert a == b (#8351) --- vlib/builtin/array_test.v | 18 +++++++++--------- vlib/v/fmt/fmt.v | 8 ++++++++ vlib/v/fmt/tests/asserts_expected.vv | 5 +++++ vlib/v/fmt/tests/asserts_input.vv | 5 +++++ 4 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 vlib/v/fmt/tests/asserts_expected.vv create mode 100644 vlib/v/fmt/tests/asserts_input.vv diff --git a/vlib/builtin/array_test.v b/vlib/builtin/array_test.v index 8e00a0af50..0253193435 100644 --- a/vlib/builtin/array_test.v +++ b/vlib/builtin/array_test.v @@ -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' diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index b77d8c0974..0e4f5405f7 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -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('') } diff --git a/vlib/v/fmt/tests/asserts_expected.vv b/vlib/v/fmt/tests/asserts_expected.vv new file mode 100644 index 0000000000..08dd71ab77 --- /dev/null +++ b/vlib/v/fmt/tests/asserts_expected.vv @@ -0,0 +1,5 @@ +fn f() { + assert 0 == 0 + assert 0 < 1 + assert (1 + 2) == 3 +} diff --git a/vlib/v/fmt/tests/asserts_input.vv b/vlib/v/fmt/tests/asserts_input.vv new file mode 100644 index 0000000000..ae2a01a791 --- /dev/null +++ b/vlib/v/fmt/tests/asserts_input.vv @@ -0,0 +1,5 @@ +fn f() { + assert (0 == 0) + assert (0 < 1) + assert ((1 + 2) == 3) +}