internal/lsp: first pass at some hover tests

This uses golden files to hold the hover text as they are no more fragile than
hard coding the text in the tests, and much easier to update.
We need a lot more tests, and ones with actual comments, but this is a start and
at least adds the machienery it would take.

Change-Id: Ia2f79257642759e4c2f972d4037f258134e0fb33
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174380
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Ian Cottrell 2019-04-29 20:58:12 -04:00
parent 08ecc9edd9
commit 2d28432af7
16 changed files with 34 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"go/token"
"io/ioutil"
"os"
"os/exec"
"sort"
@ -340,10 +341,15 @@ func (r *runner) Definition(t *testing.T, data tests.Definitions) {
Position: loc.Range.Start,
}
var locs []protocol.Location
var hover *protocol.Hover
if d.IsType {
locs, err = r.server.TypeDefinition(context.Background(), params)
} else {
locs, err = r.server.Definition(context.Background(), params)
if err != nil {
t.Fatalf("failed for %v: %v", d.Src, err)
}
hover, err = r.server.Hover(context.Background(), params)
}
if err != nil {
t.Fatalf("failed for %v: %v", d.Src, err)
@ -358,6 +364,19 @@ func (r *runner) Definition(t *testing.T, data tests.Definitions) {
} else if def != d.Def {
t.Errorf("for %v got %v want %v", d.Src, def, d.Def)
}
if hover != nil {
tag := fmt.Sprintf("hover-%d-%d", d.Def.Start().Line(), d.Def.Start().Column())
filename, err := d.Def.URI().Filename()
if err != nil {
t.Fatalf("failed for %v: %v", d.Def, err)
}
expectHover := string(r.data.Golden(tag, filename, func(golden string) error {
return ioutil.WriteFile(golden, []byte(hover.Contents.Value), 0666)
}))
if hover.Contents.Value != expectHover {
t.Errorf("for %v got %q want %q", d.Src, hover.Contents.Value, expectHover)
}
}
}
}

View File

@ -0,0 +1 @@
var err error

View File

@ -0,0 +1 @@
type a.A string

View File

@ -0,0 +1 @@
func a.Stuff()

View File

@ -0,0 +1 @@
field x int

View File

@ -0,0 +1 @@
func (*Pos).Sum() int

View File

@ -0,0 +1 @@
func Random() int

View File

@ -0,0 +1 @@
var y int

View File

@ -0,0 +1 @@
func Random2(y int) int

View File

@ -0,0 +1 @@
type S2 struct{F1 string; F2 int; *a.A}

View File

@ -0,0 +1 @@
field F1 string

View File

@ -0,0 +1 @@
field F2 int

View File

@ -0,0 +1 @@
type S1 struct{F1 int; S2; a.A}

View File

@ -0,0 +1 @@
field F1 int

View File

@ -0,0 +1 @@
field S2 S2

View File

@ -0,0 +1 @@
var myUnclosedIf string