mirror of https://github.com/golang/go.git
internal/lsp: temporarily strip subscripts from generic hover
To enable removing subscripts from go/types without breaking x/tools tests, temporarily normalize test hover strings to strip subscripts. Change-Id: I373122150e9ca889e2dcbc77875fe1b0dbbe3e15 Reviewed-on: https://go-review.googlesource.com/c/tools/+/358014 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
316ba0b740
commit
affba5001c
|
|
@ -722,8 +722,10 @@ func (r *runner) Definition(t *testing.T, spn span.Span, d tests.Definition) {
|
|||
expectHover := string(r.data.Golden(tag, d.Src.URI().Filename(), func() ([]byte, error) {
|
||||
return []byte(hover.Contents.Value), nil
|
||||
}))
|
||||
if hover.Contents.Value != expectHover {
|
||||
t.Errorf("%s:\n%s", d.Src, tests.Diff(t, expectHover, hover.Contents.Value))
|
||||
got := tests.StripSubscripts(hover.Contents.Value)
|
||||
expectHover = tests.StripSubscripts(expectHover)
|
||||
if got != expectHover {
|
||||
t.Errorf("%s:\n%s", d.Src, tests.Diff(t, expectHover, got))
|
||||
}
|
||||
}
|
||||
if !d.OnlyHover {
|
||||
|
|
|
|||
|
|
@ -580,6 +580,8 @@ func (r *runner) Definition(t *testing.T, spn span.Span, d tests.Definition) {
|
|||
expectHover := string(r.data.Golden(tag, d.Src.URI().Filename(), func() ([]byte, error) {
|
||||
return []byte(hover), nil
|
||||
}))
|
||||
hover = tests.StripSubscripts(hover)
|
||||
expectHover = tests.StripSubscripts(expectHover)
|
||||
if hover != expectHover {
|
||||
t.Errorf("hoverdef for %s failed:\n%s", d.Src, tests.Diff(t, expectHover, hover))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -551,3 +551,22 @@ func Diff(t *testing.T, want, got string) string {
|
|||
}
|
||||
return fmt.Sprintf("%q", diff.ToUnified("want", "got", want, d))
|
||||
}
|
||||
|
||||
// StripSubscripts removes type parameter id subscripts.
|
||||
//
|
||||
// TODO(rfindley): remove this function once subscripts are removed from the
|
||||
// type parameter type string.
|
||||
func StripSubscripts(s string) string {
|
||||
var runes []rune
|
||||
for _, r := range s {
|
||||
// For debugging/uniqueness purposes, TypeString on a type parameter adds a
|
||||
// subscript corresponding to the type parameter's unique id. This is going
|
||||
// to be removed, but in the meantime we skip the subscript runes to get a
|
||||
// deterministic output.
|
||||
if '₀' <= r && r < '₀'+10 {
|
||||
continue // trim type parameter subscripts
|
||||
}
|
||||
runes = append(runes, r)
|
||||
}
|
||||
return string(runes)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue