-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuri_test.go
142 lines (132 loc) · 3.11 KB
/
uri_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2019 The Go Language Server Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package uri
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestFile(t *testing.T) {
tests := []struct {
name string
path string
want URI
wantErr bool
}{
{
name: "ValidFileScheme",
path: "/users/me/c#-projects/",
want: URI(FileScheme + hierPart + "/users/me/c%23-projects"),
wantErr: false,
},
{
name: "Invalid",
path: "users-me-c#-projects",
want: URI(""),
wantErr: true,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if diff := cmp.Diff(File(tt.path), tt.want); (diff != "") != tt.wantErr {
t.Errorf("%s: (-got, +want)\n%s", tt.name, diff)
}
})
}
}
func TestParse(t *testing.T) {
tests := []struct {
name string
s string
want URI
}{
{
name: "ValidFileScheme",
s: "file://code.visualstudio.com/docs/extensions/overview.md",
want: URI(FileScheme + hierPart + "/docs/extensions/overview.md"),
},
{
name: "ValidHTTPScheme",
s: "http://code.visualstudio.com/docs/extensions/overview#frag",
want: URI(HTTPScheme + hierPart + "code.visualstudio.com/docs/extensions/overview#frag"),
},
{
name: "ValidHTTPSScheme",
s: "https://code.visualstudio.com/docs/extensions/overview#frag",
want: URI(HTTPSScheme + hierPart + "code.visualstudio.com/docs/extensions/overview#frag"),
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := Parse(tt.s)
if err != nil {
t.Error(err)
return
}
if diff := cmp.Diff(got, tt.want); diff != "" {
t.Errorf("%s: (-got, +want)\n%s", tt.name, diff)
}
})
}
}
func TestFrom(t *testing.T) {
type args struct {
scheme string
authority string
path string
query string
fragment string
}
tests := []struct {
name string
args args
want URI
}{
{
name: "ValidFileScheme",
args: args{
scheme: "file",
authority: "example.com",
path: "/over/there",
query: "name=ferret",
fragment: "nose",
},
want: URI(FileScheme + hierPart + "/over/there"),
},
{
name: "ValidHTTPScheme",
args: args{
scheme: "http",
authority: "example.com:8042",
path: "/over/there",
query: "name=ferret",
fragment: "nose",
},
want: URI(HTTPScheme + hierPart + "example.com:8042/over/there?name%3Dferret#nose"),
},
{
name: "ValidHTTPSScheme",
args: args{
scheme: "https",
authority: "example.com:8042",
path: "/over/there",
query: "name=ferret",
fragment: "nose",
},
want: URI(HTTPSScheme + hierPart + "example.com:8042/over/there?name%3Dferret#nose"),
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if diff := cmp.Diff(From(tt.args.scheme, tt.args.authority, tt.args.path, tt.args.query, tt.args.fragment), tt.want); diff != "" {
t.Errorf("%s: (-got, +want)\n%s", tt.name, diff)
}
})
}
}