mirror of
https://github.com/laravel-ls/uri
synced 2026-07-03 08:03:40 +02:00
uri: fix testcases
This commit is contained in:
parent
2f7ed69ad1
commit
1cfdb9025b
1 changed files with 27 additions and 27 deletions
40
uri_test.go
40
uri_test.go
|
|
@ -25,7 +25,6 @@ func TestParse(t *testing.T) {
|
||||||
s: "file://code.visualstudio.com/docs/extensions/overview.md",
|
s: "file://code.visualstudio.com/docs/extensions/overview.md",
|
||||||
want: &uri.URI{
|
want: &uri.URI{
|
||||||
Scheme: uri.FileScheme,
|
Scheme: uri.FileScheme,
|
||||||
Authority: "code.visualstudio.com",
|
|
||||||
Path: "/docs/extensions/overview.md",
|
Path: "/docs/extensions/overview.md",
|
||||||
FsPath: filepath.FromSlash("/docs/extensions/overview.md"),
|
FsPath: filepath.FromSlash("/docs/extensions/overview.md"),
|
||||||
},
|
},
|
||||||
|
|
@ -65,7 +64,12 @@ func TestParse(t *testing.T) {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
if diff := cmp.Diff(uri.Parse(tt.s), tt.want, cmp.AllowUnexported(*tt.want)); (diff != "") != tt.wantErr {
|
got, err := uri.Parse(tt.s)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("wantErr: %t, err: %#v", tt.wantErr, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if diff := cmp.Diff(got, tt.want, cmp.AllowUnexported(*tt.want)); (diff != "") != tt.wantErr {
|
||||||
t.Errorf("%s: (-got, +want)\n%s", tt.name, diff)
|
t.Errorf("%s: (-got, +want)\n%s", tt.name, diff)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -132,11 +136,8 @@ func TestFrom(t *testing.T) {
|
||||||
},
|
},
|
||||||
want: &uri.URI{
|
want: &uri.URI{
|
||||||
Scheme: uri.FileScheme,
|
Scheme: uri.FileScheme,
|
||||||
Authority: "example.com",
|
|
||||||
Path: "/over/there",
|
Path: "/over/there",
|
||||||
FsPath: filepath.FromSlash("/over/there"),
|
FsPath: filepath.FromSlash("/over/there"),
|
||||||
Query: "name=ferret",
|
|
||||||
Fragment: "nose",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -152,7 +153,7 @@ func TestFrom(t *testing.T) {
|
||||||
Scheme: uri.HTTPScheme,
|
Scheme: uri.HTTPScheme,
|
||||||
Authority: "example.com:8042",
|
Authority: "example.com:8042",
|
||||||
Path: "/over/there",
|
Path: "/over/there",
|
||||||
Query: "name=ferret",
|
Query: "name%3Dferret",
|
||||||
Fragment: "nose",
|
Fragment: "nose",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -169,7 +170,7 @@ func TestFrom(t *testing.T) {
|
||||||
Scheme: uri.HTTPSScheme,
|
Scheme: uri.HTTPSScheme,
|
||||||
Authority: "example.com:8042",
|
Authority: "example.com:8042",
|
||||||
Path: "/over/there",
|
Path: "/over/there",
|
||||||
Query: "name=ferret",
|
Query: "name%3Dferret",
|
||||||
Fragment: "nose",
|
Fragment: "nose",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -188,12 +189,12 @@ func TestFrom(t *testing.T) {
|
||||||
|
|
||||||
func TestURI_String(t *testing.T) {
|
func TestURI_String(t *testing.T) {
|
||||||
type fields struct {
|
type fields struct {
|
||||||
Authority string
|
|
||||||
Fragment string
|
|
||||||
FsPath string
|
|
||||||
Path string
|
|
||||||
Query string
|
|
||||||
Scheme string
|
Scheme string
|
||||||
|
Authority string
|
||||||
|
Path string
|
||||||
|
FsPath string
|
||||||
|
Query string
|
||||||
|
Fragment string
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
@ -203,34 +204,33 @@ func TestURI_String(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "ValidFileScheme",
|
name: "ValidFileScheme",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
Authority: "code.visualstudio.com",
|
|
||||||
Path: "/docs/extensions/overview.md",
|
|
||||||
FsPath: filepath.FromSlash("/docs/extensions/overview.md"),
|
|
||||||
Scheme: string(uri.FileScheme),
|
Scheme: string(uri.FileScheme),
|
||||||
|
Path: "docs/extensions/overview.md",
|
||||||
|
FsPath: filepath.FromSlash("docs/extensions/overview.md"),
|
||||||
},
|
},
|
||||||
want: "file://code.visualstudio.com/docs/extensions/overview.md",
|
want: "file://docs/extensions/overview.md",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ValidHTTPScheme",
|
name: "ValidHTTPScheme",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
|
Scheme: string(uri.HTTPScheme),
|
||||||
Authority: "code.visualstudio.com",
|
Authority: "code.visualstudio.com",
|
||||||
Fragment: "frag",
|
|
||||||
Path: "/docs/extensions/overview",
|
Path: "/docs/extensions/overview",
|
||||||
FsPath: filepath.FromSlash("/docs/extensions/overview"),
|
FsPath: filepath.FromSlash("/docs/extensions/overview"),
|
||||||
Query: "test",
|
Query: "test",
|
||||||
Scheme: string(uri.HTTPScheme),
|
Fragment: "frag",
|
||||||
},
|
},
|
||||||
want: "http://code.visualstudio.com/docs/extensions/overview?test#frag",
|
want: "http://code.visualstudio.com/docs/extensions/overview?test#frag",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ValidHTTPSScheme",
|
name: "ValidHTTPSScheme",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
|
Scheme: string(uri.HTTPSScheme),
|
||||||
Authority: "code.visualstudio.com",
|
Authority: "code.visualstudio.com",
|
||||||
Fragment: "frag",
|
|
||||||
Path: "/docs/extensions/overview",
|
Path: "/docs/extensions/overview",
|
||||||
FsPath: filepath.FromSlash("/docs/extensions/overview"),
|
FsPath: filepath.FromSlash("/docs/extensions/overview"),
|
||||||
Query: "test",
|
Query: "test",
|
||||||
Scheme: string(uri.HTTPSScheme),
|
Fragment: "frag",
|
||||||
},
|
},
|
||||||
want: "https://code.visualstudio.com/docs/extensions/overview?test#frag",
|
want: "https://code.visualstudio.com/docs/extensions/overview?test#frag",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue