1
0
mirror of https://github.com/golang/go synced 2024-11-19 07:54:43 -07:00
go/internal/span/uri_test.go
Rebecca Stambler 0725381040 internal/span: always uppercase the drive letter for Windows
Drive letters are always case-insensitive, so we should standardize them
by always keeping them uppercase.

Updates golang/go#36904

Change-Id: I8de25b175790b01627f947600c1511edf38c316c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/217080
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-01-30 22:30:17 +00:00

75 lines
2.0 KiB
Go

// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !windows
package span_test
import (
"testing"
"golang.org/x/tools/internal/span"
)
// TestURI tests the conversion between URIs and filenames. The test cases
// include Windows-style URIs and filepaths, but we avoid having OS-specific
// tests by using only forward slashes, assuming that the standard library
// functions filepath.ToSlash and filepath.FromSlash do not need testing.
func TestURI(t *testing.T) {
for _, test := range []struct {
path, wantFile string
wantURI span.URI
}{
{
path: ``,
wantFile: ``,
wantURI: span.URI(""),
},
{
path: `C:/Windows/System32`,
wantFile: `C:/Windows/System32`,
wantURI: span.URI("file:///C:/Windows/System32"),
},
{
path: `C:/Go/src/bob.go`,
wantFile: `C:/Go/src/bob.go`,
wantURI: span.URI("file:///C:/Go/src/bob.go"),
},
{
path: `c:/Go/src/bob.go`,
wantFile: `C:/Go/src/bob.go`,
wantURI: span.URI("file:///C:/Go/src/bob.go"),
},
{
path: `/path/to/dir`,
wantFile: `/path/to/dir`,
wantURI: span.URI("file:///path/to/dir"),
},
{
path: `/a/b/c/src/bob.go`,
wantFile: `/a/b/c/src/bob.go`,
wantURI: span.URI("file:///a/b/c/src/bob.go"),
},
{
path: `c:/Go/src/bob george/george/george.go`,
wantFile: `C:/Go/src/bob george/george/george.go`,
wantURI: span.URI("file:///C:/Go/src/bob george/george/george.go"),
},
{
path: `file:///c:/Go/src/bob george/george/george.go`,
wantFile: `C:/Go/src/bob george/george/george.go`,
wantURI: span.URI("file:///C:/Go/src/bob george/george/george.go"),
},
} {
got := span.NewURI(test.path)
if got != test.wantURI {
t.Errorf("ToURI: got %s, expected %s", got, test.wantURI)
}
gotFilename := got.Filename()
if gotFilename != test.wantFile {
t.Errorf("Filename: got %s, expected %s", gotFilename, test.wantFile)
}
}
}