Skip to content

Commit

Permalink
gopls/internal/lsp/protocol: fix TestURIFromPath on windows
Browse files Browse the repository at this point in the history
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 <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
findleyr committed Jan 17, 2024
1 parent d2200d1 commit f2d3f78
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions gopls/internal/lsp/protocol/uri_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package protocol_test

import (
"path/filepath"
"testing"

"golang.org/x/tools/gopls/internal/lsp/protocol"
Expand All @@ -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
Expand All @@ -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`,
Expand Down

0 comments on commit f2d3f78

Please sign in to comment.