internal/lsp: refactor query definition test to allow adding a new test
Change-Id: I360f21012f26118947dbac7c39e17c9c1f599379 Reviewed-on: https://go-review.googlesource.com/c/tools/+/168177 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
63e6ed9258
commit
a41300a290
|
@ -26,11 +26,14 @@ type Definition struct {
|
|||
Description string `json:"description"` // description of the denoted object
|
||||
}
|
||||
|
||||
// This constant is printed in the help, and then used in a test to verify the
|
||||
// These constant is printed in the help, and then used in a test to verify the
|
||||
// help is still valid.
|
||||
// It should be the byte offset in this file of the "Set" in "flag.FlagSet" from
|
||||
// the DetailedHelp method below.
|
||||
const exampleOffset = 1311
|
||||
// They refer to "Set" in "flag.FlagSet" from the DetailedHelp method below.
|
||||
const (
|
||||
exampleLine = 46
|
||||
exampleColumn = 47
|
||||
exampleOffset = 1319
|
||||
)
|
||||
|
||||
// definition implements the definition noun for the query command.
|
||||
type definition struct {
|
||||
|
@ -44,10 +47,11 @@ func (d *definition) DetailedHelp(f *flag.FlagSet) {
|
|||
fmt.Fprintf(f.Output(), `
|
||||
Example: show the definition of the identifier at syntax at offset %[1]v in this file (flag.FlagSet):
|
||||
|
||||
$ gopls definition internal/lsp/cmd/definition.go:#%[1]v
|
||||
$ gopls definition internal/lsp/cmd/definition.go:%[1]v:%[2]v
|
||||
$ gopls definition internal/lsp/cmd/definition.go:#%[3]v
|
||||
|
||||
gopls definition flags are:
|
||||
`, exampleOffset)
|
||||
`, exampleLine, exampleColumn, exampleOffset)
|
||||
f.PrintDefaults()
|
||||
}
|
||||
|
||||
|
|
|
@ -37,14 +37,17 @@ func TestDefinitionHelpExample(t *testing.T) {
|
|||
return
|
||||
}
|
||||
thisFile := filepath.Join(dir, "definition.go")
|
||||
args := []string{"query", "definition", fmt.Sprintf("%v:#%v", thisFile, cmd.ExampleOffset)}
|
||||
baseArgs := []string{"query", "definition"}
|
||||
expect := regexp.MustCompile(`^[\w/\\:_]+flag[/\\]flag.go:\d+:\d+-\d+: defined here as type flag.FlagSet struct{.*}$`)
|
||||
for _, query := range []string{fmt.Sprintf("%v:#%v", thisFile, cmd.ExampleOffset)} {
|
||||
args := append(baseArgs, query)
|
||||
got := captureStdOut(t, func() {
|
||||
tool.Main(context.Background(), &cmd.Application{}, args)
|
||||
})
|
||||
if !expect.MatchString(got) {
|
||||
t.Errorf("test with %v\nexpected:\n%s\ngot:\n%s", args, expect, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefinition(t *testing.T) {
|
||||
|
|
|
@ -4,4 +4,8 @@
|
|||
|
||||
package cmd
|
||||
|
||||
const ExampleOffset = exampleOffset
|
||||
const (
|
||||
ExampleLine = exampleLine
|
||||
ExampleColumn = exampleColumn
|
||||
ExampleOffset = exampleOffset
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue