From fec9f1324c889990e9fd25ef49cd632a2525955b Mon Sep 17 00:00:00 2001 From: zakuro Date: Thu, 24 Dec 2020 19:57:48 +0900 Subject: [PATCH] fmt: trim space in embedded comments (#7521) --- vlib/v/fmt/fmt.v | 2 +- vlib/v/fmt/tests/comments_expected.vv | 4 ++++ vlib/v/fmt/tests/comments_input.vv | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 7fd7f1f675..6de03eabec 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1228,7 +1228,7 @@ pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) { f.writeln(x) f.write('*/') } else { - f.write('/* $x */') + f.write('/* ${x.trim(' ')} */') } return } diff --git a/vlib/v/fmt/tests/comments_expected.vv b/vlib/v/fmt/tests/comments_expected.vv index 081ad60164..603e593128 100644 --- a/vlib/v/fmt/tests/comments_expected.vv +++ b/vlib/v/fmt/tests/comments_expected.vv @@ -18,6 +18,10 @@ fn main() { d := c // and an extra one e := c // more comments = more good + arr := [ + /* block foo bar */ /* inline foo bar */ + 0, + ] // before arg comment // after arg comment println('this is a test') diff --git a/vlib/v/fmt/tests/comments_input.vv b/vlib/v/fmt/tests/comments_input.vv index b09b4a4cc4..c53484437c 100644 --- a/vlib/v/fmt/tests/comments_input.vv +++ b/vlib/v/fmt/tests/comments_input.vv @@ -12,6 +12,11 @@ fn main() { d := c // and an extra one e := c // more comments = more good + arr := [ + /* block foo bar */ + // inline foo bar + 0, + ] println(/* before arg comment */ 'this is a test' /* after arg comment */) if /* before if expr */ true /* after if expr */ { println('if')