2
2
// Use of this source code is governed by a BSD-style
3
3
// license that can be found in the LICENSE file.
4
4
5
+ // +build !windows
6
+
5
7
package span_test
6
8
7
9
import (
8
- "path/filepath"
9
10
"testing"
10
11
11
12
"golang.org/x/tools/internal/span"
@@ -16,36 +17,58 @@ import (
16
17
// tests by using only forward slashes, assuming that the standard library
17
18
// functions filepath.ToSlash and filepath.FromSlash do not need testing.
18
19
func TestURI (t * testing.T ) {
19
- for _ , test := range []string {
20
- `` ,
21
- `C:/Windows/System32` ,
22
- `C:/Go/src/bob.go` ,
23
- `c:/Go/src/bob.go` ,
24
- `/path/to/dir` ,
25
- `/a/b/c/src/bob.go` ,
26
- `c:/Go/src/bob george/george/george.go` ,
20
+ for _ , test := range []struct {
21
+ path , wantFile string
22
+ wantURI span.URI
23
+ }{
24
+ {
25
+ path : `` ,
26
+ wantFile : `` ,
27
+ wantURI : span .URI ("" ),
28
+ },
29
+ {
30
+ path : `C:/Windows/System32` ,
31
+ wantFile : `C:/Windows/System32` ,
32
+ wantURI : span .URI ("file:///C:/Windows/System32" ),
33
+ },
34
+ {
35
+ path : `C:/Go/src/bob.go` ,
36
+ wantFile : `C:/Go/src/bob.go` ,
37
+ wantURI : span .URI ("file:///C:/Go/src/bob.go" ),
38
+ },
39
+ {
40
+ path : `c:/Go/src/bob.go` ,
41
+ wantFile : `C:/Go/src/bob.go` ,
42
+ wantURI : span .URI ("file:///C:/Go/src/bob.go" ),
43
+ },
44
+ {
45
+ path : `/path/to/dir` ,
46
+ wantFile : `/path/to/dir` ,
47
+ wantURI : span .URI ("file:///path/to/dir" ),
48
+ },
49
+ {
50
+ path : `/a/b/c/src/bob.go` ,
51
+ wantFile : `/a/b/c/src/bob.go` ,
52
+ wantURI : span .URI ("file:///a/b/c/src/bob.go" ),
53
+ },
54
+ {
55
+ path : `c:/Go/src/bob george/george/george.go` ,
56
+ wantFile : `C:/Go/src/bob george/george/george.go` ,
57
+ wantURI : span .URI ("file:///C:/Go/src/bob george/george/george.go" ),
58
+ },
59
+ {
60
+ path : `file:///c:/Go/src/bob george/george/george.go` ,
61
+ wantFile : `C:/Go/src/bob george/george/george.go` ,
62
+ wantURI : span .URI ("file:///C:/Go/src/bob george/george/george.go" ),
63
+ },
27
64
} {
28
- testPath := filepath .FromSlash (test )
29
- expectPath := testPath
30
- if len (test ) > 0 && test [0 ] == '/' {
31
- if abs , err := filepath .Abs (expectPath ); err == nil {
32
- expectPath = abs
33
- }
34
- }
35
- expectURI := filepath .ToSlash (expectPath )
36
- if len (expectURI ) > 0 {
37
- if expectURI [0 ] != '/' {
38
- expectURI = "/" + expectURI
39
- }
40
- expectURI = "file://" + expectURI
41
- }
42
- uri := span .FileURI (testPath )
43
- if expectURI != string (uri ) {
44
- t .Errorf ("ToURI: expected %s, got %s" , expectURI , uri )
65
+ got := span .NewURI (test .path )
66
+ if got != test .wantURI {
67
+ t .Errorf ("ToURI: got %s, expected %s" , got , test .wantURI )
45
68
}
46
- filename := uri .Filename ()
47
- if expectPath != filename {
48
- t .Errorf ("Filename: expected %s, got %s" , expectPath , filename )
69
+ gotFilename := got .Filename ()
70
+ if gotFilename != test . wantFile {
71
+ t .Errorf ("Filename: got %s, expected %s" , gotFilename , test . wantFile )
49
72
}
50
73
}
51
74
}
0 commit comments