From f2d3f78aad4eb0a6eb0ee1dd1dcbca3afb5c3496 Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Wed, 17 Jan 2024 15:47:47 -0500 Subject: [PATCH] gopls/internal/lsp/protocol: fix TestURIFromPath on windows Update TestURIFromPath not to assume the drive name for the default volume. Fixes golang/go#63366 Change-Id: I0196f11e628821b941d418831f3a3da7cf125ddf Reviewed-on: https://go-review.googlesource.com/c/tools/+/556496 Reviewed-by: Alan Donovan LUCI-TryBot-Result: Go LUCI --- .../internal/lsp/protocol/uri_windows_test.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gopls/internal/lsp/protocol/uri_windows_test.go b/gopls/internal/lsp/protocol/uri_windows_test.go index e607468a322..03b3af28924 100644 --- a/gopls/internal/lsp/protocol/uri_windows_test.go +++ b/gopls/internal/lsp/protocol/uri_windows_test.go @@ -8,6 +8,7 @@ package protocol_test import ( + "path/filepath" "testing" "golang.org/x/tools/gopls/internal/lsp/protocol" @@ -18,6 +19,15 @@ import ( // tests by using only forward slashes, assuming that the standard library // functions filepath.ToSlash and filepath.FromSlash do not need testing. func TestURIFromPath(t *testing.T) { + rootPath, err := filepath.Abs("/") + if err != nil { + t.Fatal(err) + } + if len(rootPath) < 2 || rootPath[1] != ':' { + t.Fatalf("malformed root path %q", rootPath) + } + driveLetter := string(rootPath[0]) + for _, test := range []struct { path, wantFile string wantURI protocol.DocumentURI @@ -44,13 +54,13 @@ func TestURIFromPath(t *testing.T) { }, { path: `\path\to\dir`, - wantFile: `C:\path\to\dir`, - wantURI: protocol.DocumentURI("file:///C:/path/to/dir"), + wantFile: driveLetter + `:\path\to\dir`, + wantURI: protocol.DocumentURI("file:///" + driveLetter + ":/path/to/dir"), }, { path: `\a\b\c\src\bob.go`, - wantFile: `C:\a\b\c\src\bob.go`, - wantURI: protocol.DocumentURI("file:///C:/a/b/c/src/bob.go"), + wantFile: driveLetter + `:\a\b\c\src\bob.go`, + wantURI: protocol.DocumentURI("file:///" + driveLetter + ":/a/b/c/src/bob.go"), }, { path: `c:\Go\src\bob george\george\george.go`,