From 2912ce79fc7ba9f2efc70c3887bc067a886800d1 Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Sat, 28 Dec 2019 20:41:04 -0500 Subject: [PATCH] go/analysis/analysistest: accept comments of /* */ form Testing on analysis of location of comments, or lack of comments may need /* */-style comments to avoid interfere with the tested code. Change-Id: Id190aa243dc8ca90808c58f6d5dd4db1ade9f1c4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/212636 Reviewed-by: Michael Matloob --- go/analysis/analysistest/analysistest.go | 6 ++++-- go/analysis/analysistest/analysistest_test.go | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/go/analysis/analysistest/analysistest.go b/go/analysis/analysistest/analysistest.go index fc06c32269..74043c59de 100644 --- a/go/analysis/analysistest/analysistest.go +++ b/go/analysis/analysistest/analysistest.go @@ -193,11 +193,13 @@ func check(t Testing, gopath string, pass *analysis.Pass, diagnostics []analysis for _, c := range cgroup.List { text := strings.TrimPrefix(c.Text, "//") - if text == c.Text { - continue // not a //-comment + if text == c.Text { // not a //-comment. + text = strings.TrimPrefix(text, "/*") + text = strings.TrimSuffix(text, "*/") } // Hack: treat a comment of the form "//...// want..." + // or "/*...// want... */ // as if it starts at 'want'. // This allows us to add comments on comments, // as required when testing the buildtag analyzer. diff --git a/go/analysis/analysistest/analysistest_test.go b/go/analysis/analysistest/analysistest_test.go index c16e5079e2..f5a003c62b 100644 --- a/go/analysis/analysistest/analysistest_test.go +++ b/go/analysis/analysistest/analysistest_test.go @@ -54,6 +54,15 @@ func main() { // OK println("hello, world") // want "call of println" + // OK /* */-form. + println("안녕, 세계") /* want "call of println" */ + + // OK (nested comment) + println("Γειά σου, Κόσμε") // some comment // want "call of println" + + // OK (nested comment in /**/) + println("你好,世界") /* some comment // want "call of println" */ + // OK (multiple expectations on same line) println(); println() // want "call of println(...)" "call of println(...)" }