mirror of
https://github.com/golang/go
synced 2024-11-18 16:14:46 -07:00
go/expect: support markers in comments in go/packagestest
This is specifically necessary to test CL 197879. Change-Id: I2b4bbdd322d52097fc1444242d3e26a3d8ea75e7 Reviewed-on: https://go-review.googlesource.com/c/tools/+/201520 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
846f856e7d
commit
a3bc800455
@ -20,7 +20,7 @@ func TestMarker(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
const expectNotes = 11
|
||||
const expectNotes = 12
|
||||
expectMarkers := map[string]string{
|
||||
"αSimpleMarker": "α",
|
||||
"OffsetMarker": "β",
|
||||
@ -30,6 +30,7 @@ func TestMarker(t *testing.T) {
|
||||
"ηBlockMarker": "η",
|
||||
"Declared": "η",
|
||||
"Comment": "ι",
|
||||
"LineComment": "someFunc",
|
||||
"NonIdentifier": "+",
|
||||
}
|
||||
expectChecks := map[string][]interface{}{
|
||||
@ -129,6 +130,10 @@ func checkMarker(t *testing.T, fset *token.FileSet, readFile expect.ReadFile, ma
|
||||
if start != expectStart {
|
||||
t.Errorf("%v: Expected %v got %v", fset.Position(pos), fset.Position(expectStart), fset.Position(start))
|
||||
}
|
||||
// Don't check the end for the LineComment test.
|
||||
if name == "LineComment" {
|
||||
return
|
||||
}
|
||||
if expectEnd, ok := markers[name+"@"]; ok && end != expectEnd {
|
||||
t.Errorf("%v: Expected end %v got %v", fset.Position(pos), fset.Position(expectEnd), fset.Position(end))
|
||||
}
|
||||
|
@ -59,11 +59,27 @@ func Extract(fset *token.FileSet, file *ast.File) ([]*Note, error) {
|
||||
text = strings.TrimSuffix(text, "*/")
|
||||
}
|
||||
text = text[2:] // remove "//" or "/*" prefix
|
||||
|
||||
// Allow notes to appear within comments.
|
||||
// For example:
|
||||
// "// //@mark()" is valid.
|
||||
// "// @mark()" is not valid.
|
||||
// "// /*@mark()*/" is not valid.
|
||||
var adjust int
|
||||
if i := strings.Index(text, commentStart); i > 2 {
|
||||
// Get the text before the commentStart.
|
||||
pre := text[i-2 : i]
|
||||
if pre != "//" {
|
||||
continue
|
||||
}
|
||||
text = text[i:]
|
||||
adjust = i
|
||||
}
|
||||
if !strings.HasPrefix(text, commentStart) {
|
||||
continue
|
||||
}
|
||||
text = text[len(commentStart):]
|
||||
parsed, err := parse(fset, c.Pos()+4, text)
|
||||
parsed, err := parse(fset, token.Pos(int(c.Pos())+4+adjust), text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
2
go/expect/testdata/test.go
vendored
2
go/expect/testdata/test.go
vendored
@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package fake1 is used to test the expect package.
|
||||
package fake1
|
||||
|
||||
// The greek letters in this file mark points we use for marker tests.
|
||||
@ -19,6 +20,7 @@ const (
|
||||
|
||||
/*Marker ι inside ι a comment*/ //@mark(Comment,"ι inside ")
|
||||
|
||||
// someFunc is a function. //@mark(LineComment, "someFunc")
|
||||
func someFunc(a, b int) int {
|
||||
// The line below must be the first occurrence of the plus operator
|
||||
return a + b + 1 //@mark(NonIdentifier, re`\+[^\+]*`)
|
||||
|
4
internal/lsp/testdata/bad/bad1.go
vendored
4
internal/lsp/testdata/bad/bad1.go
vendored
@ -2,10 +2,6 @@
|
||||
|
||||
package bad
|
||||
|
||||
// import (
|
||||
// "github.com/bob/pkg" //@diag("\"github.com/bob/pkg\"", "LSP", "unable to import "\"github.com/bob/pkg\"")
|
||||
// )
|
||||
|
||||
var a unknown //@item(global_a, "a", "unknown", "var"),diag("unknown", "LSP", "undeclared name: unknown")
|
||||
|
||||
func random() int { //@item(random, "random", "func() int", "func")
|
||||
|
Loading…
Reference in New Issue
Block a user