From 09281b52a140843e6a2aeacde239aa4ea0511a5d Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Thu, 16 May 2019 20:44:44 -0400 Subject: [PATCH] godoc: re-add test for ignoring //line comments in source code The original CL 84050044 added a test case, and it happened to be in between various CLI test cases. CLI support was removed from x/tools/cmd/godoc in CL 141397, as part of golang/go#25443. Re-add a test case for this behavior to prevent regressions. Updates golang/go#32092 Updates golang/go#25443 Updates golang/go#5247 Change-Id: I0cea74cfe40d120e398a9005676134c5bad6136c Reviewed-on: https://go-review.googlesource.com/c/tools/+/177737 Reviewed-by: Robert Griesemer --- godoc/parser.go | 2 +- godoc/server_test.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/godoc/parser.go b/godoc/parser.go index 4e644d6fc0..c864a0a34a 100644 --- a/godoc/parser.go +++ b/godoc/parser.go @@ -53,7 +53,7 @@ func (c *Corpus) parseFile(fset *token.FileSet, filename string, mode parser.Mod } // Temporary ad-hoc fix for issue 5247. - // TODO(gri) Remove this in favor of a better fix, eventually (see issue 7702). + // TODO(gri,dmitshur) Remove this in favor of a better fix, eventually (see issue 32092). replaceLinePrefixCommentsWithBlankLine(src) return parser.ParseFile(fset, filename, src, mode) diff --git a/godoc/server_test.go b/godoc/server_test.go index 656e5f5874..a7ed5142f5 100644 --- a/godoc/server_test.go +++ b/godoc/server_test.go @@ -46,3 +46,24 @@ package main`})) t.Error("pInfo.FSet = nil; want non-nil.") } } + +func TestIssue5247(t *testing.T) { + const packagePath = "example.com/p" + c := NewCorpus(mapfs.New(map[string]string{ + "src/" + packagePath + "/p.go": `package p + +//line notgen.go:3 +// F doc //line 1 should appear +// line 2 should appear +func F() +//line foo.go:100`})) // No newline at end to check corner cases. + + srv := &handlerServer{ + p: &Presentation{Corpus: c}, + c: c, + } + pInfo := srv.GetPageInfo("/src/"+packagePath, packagePath, 0, "linux", "amd64") + if got, want := pInfo.PDoc.Funcs[0].Doc, "F doc //line 1 should appear\nline 2 should appear\n"; got != want { + t.Errorf("pInfo.PDoc.Funcs[0].Doc = %q; want %q", got, want) + } +}