diff --git a/uri.go b/uri.go index 5a4c3dd..0e512e0 100644 --- a/uri.go +++ b/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 { diff --git a/uri_test.go b/uri_test.go index dbd2110..c059313 100644 --- a/uri_test.go +++ b/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