internal/lsp/tests: fix regexp for removing links that contain versions

This change fixes the regex that removes the versions for links so that tests will still run under GOPATH mode. It also removes a link for an import that needed to be downloaded.

Change-Id: I7ed4f500d1bd9d2136188d30952eedb8d8aee6e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220140
Run-TryBot: Rohan Challa <rohan@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/internal/lsp/testdata/lsp/primarymod/links/links.go b/internal/lsp/testdata/lsp/primarymod/links/links.go
index b5766ab..be15ddb 100644
--- a/internal/lsp/testdata/lsp/primarymod/links/links.go
+++ b/internal/lsp/testdata/lsp/primarymod/links/links.go
@@ -7,8 +7,6 @@
 
 	_ "database/sql" //@link(`database/sql`, `https://pkg.go.dev/database/sql`)
 
-	errors "golang.org/x/xerrors" //@link(`golang.org/x/xerrors`, `https://pkg.go.dev/golang.org/x/xerrors`)
-
 	_ "example.com/extramodule/pkg" //@link(`example.com/extramodule/pkg`,`https://pkg.go.dev/example.com/extramodule@v1.0.0/pkg`)
 )
 
diff --git a/internal/lsp/testdata/lsp/summary.txt.golden b/internal/lsp/testdata/lsp/summary.txt.golden
index 4ab35ea..4845142 100644
--- a/internal/lsp/testdata/lsp/summary.txt.golden
+++ b/internal/lsp/testdata/lsp/summary.txt.golden
@@ -23,6 +23,6 @@
 FuzzyWorkspaceSymbolsCount = 3
 CaseSensitiveWorkspaceSymbolsCount = 2
 SignaturesCount = 23
-LinksCount = 9
+LinksCount = 8
 ImplementationsCount = 5
 
diff --git a/internal/lsp/tests/tests.go b/internal/lsp/tests/tests.go
index c605b07..741df0f 100644
--- a/internal/lsp/tests/tests.go
+++ b/internal/lsp/tests/tests.go
@@ -704,9 +704,9 @@
 			// If we are testing GOPATH, then we do not want links with
 			// the versions attached (pkg.go.dev/repoa/moda@v1.1.0/pkg).
 			if data.Exported.Exporter == packagestest.GOPATH {
-				re := regexp.MustCompile(`@(.+?)/`)
+				re := regexp.MustCompile(`@v\d+\.\d+\.[\w-]+`)
 				for i, link := range wantLinks {
-					wantLinks[i].Target = re.ReplaceAllString(link.Target, "/")
+					wantLinks[i].Target = re.ReplaceAllString(link.Target, "")
 				}
 			}
 			t.Run(uriName(uri), func(t *testing.T) {
diff --git a/internal/lsp/tests/util.go b/internal/lsp/tests/util.go
index dcea466..b81cfd0 100644
--- a/internal/lsp/tests/util.go
+++ b/internal/lsp/tests/util.go
@@ -49,7 +49,7 @@
 		if target, ok := links[spn]; ok {
 			delete(links, spn)
 			if target != link.Target {
-				return fmt.Sprintf("for %v want %v, got %v\n", spn, link.Target, target)
+				return fmt.Sprintf("for %v want %v, got %v\n", spn, target, link.Target)
 			}
 		} else {
 			return fmt.Sprintf("unexpected link %v:%v\n", spn, link.Target)