diff --git a/internal/lsp/lsp_test.go b/internal/lsp/lsp_test.go index 32cd597acf..8a6673012c 100644 --- a/internal/lsp/lsp_test.go +++ b/internal/lsp/lsp_test.go @@ -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 { diff --git a/internal/lsp/source/source_test.go b/internal/lsp/source/source_test.go index 83ce712c83..d0e6b8a2eb 100644 --- a/internal/lsp/source/source_test.go +++ b/internal/lsp/source/source_test.go @@ -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)) } diff --git a/internal/lsp/tests/util.go b/internal/lsp/tests/util.go index 94c948de97..f75677a0e2 100644 --- a/internal/lsp/tests/util.go +++ b/internal/lsp/tests/util.go @@ -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) +}