mirror of
https://github.com/laravel-ls/uri
synced 2026-06-16 01:54:57 +02:00
uri: fix Filename reciever name
This commit is contained in:
parent
695121e1f8
commit
6ea0234e36
2 changed files with 34 additions and 44 deletions
14
uri.go
14
uri.go
|
|
@ -47,8 +47,8 @@ type URI string
|
|||
|
||||
// Filename returns the file path for the given URI. It will return an error if
|
||||
// the URI is invalid, or if the URI does not have the file scheme.
|
||||
func (uri URI) Filename() (string, error) {
|
||||
filename, err := filename(uri)
|
||||
func (u URI) Filename() (string, error) {
|
||||
filename, err := filename(u)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -73,16 +73,6 @@ func filename(uri URI) (string, error) {
|
|||
return u.Path, nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (u URI) MarshalJSON() ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (u *URI) UnmarshalJSON(b []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// New parses and creates a new URI from s.
|
||||
func New(s string) URI {
|
||||
if u, err := url.PathUnescape(s); err == nil {
|
||||
|
|
|
|||
64
uri_test.go
64
uri_test.go
|
|
@ -10,6 +10,38 @@ import (
|
|||
"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
|
||||
|
|
@ -50,38 +82,6 @@ func TestParse(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
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 TestFrom(t *testing.T) {
|
||||
type args struct {
|
||||
scheme string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue