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>
diff --git a/internal/lsp/lsp_test.go b/internal/lsp/lsp_test.go
index 32cd597..8a66730 100644
--- a/internal/lsp/lsp_test.go
+++ b/internal/lsp/lsp_test.go
@@ -722,8 +722,10 @@
 		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 83ce712..d0e6b8a 100644
--- a/internal/lsp/source/source_test.go
+++ b/internal/lsp/source/source_test.go
@@ -580,6 +580,8 @@
 		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 94c948d..f75677a 100644
--- a/internal/lsp/tests/util.go
+++ b/internal/lsp/tests/util.go
@@ -551,3 +551,22 @@
 	}
 	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)
+}