diff --git a/internal/identifier/id.go b/internal/identifier/id.go index 0cc8c34..e5888a9 100644 --- a/internal/identifier/id.go +++ b/internal/identifier/id.go @@ -34,9 +34,10 @@ func (i ID) Extension() (exttype string, fileext string) { if numberOfElements > 2 { exttype = elements[numberOfElements - 2] fileext = elements[numberOfElements - 1] + } else { + exttype = elements[numberOfElements - 1] } - exttype = elements[numberOfElements - 1] } - return + return exttype, fileext } diff --git a/internal/identifier/id_test.go b/internal/identifier/id_test.go index 8377ffc..d10da51 100644 --- a/internal/identifier/id_test.go +++ b/internal/identifier/id_test.go @@ -34,6 +34,22 @@ func TestID(t *testing.T) { assert.Equal(t, "", fileext) } +func TestIDExt(t *testing.T) { + for _, v := range []struct { File ID + ExpectedExt string + ExpectedType string }{ + { File: "file:///tmp/foo/bar/baz.txt", ExpectedExt: "", ExpectedType: "txt" }, + { File: "file:///tmp/foo/bar/baz.txt.gz", ExpectedExt: "gz", ExpectedType: "txt" }, + { File: "file:///tmp/foo/bar/baz.quuz.txt.gz", ExpectedExt: "gz", ExpectedType: "txt" }, + } { + u := v.File.Parse() + assert.Equal(t, "file", u.Scheme) + filetype, fileext := v.File.Extension() + assert.Equal(t, v.ExpectedType, filetype) + assert.Equal(t, v.ExpectedExt, fileext) + } +} + func TestSetID(t *testing.T) { var file ID = ID(fmt.Sprintf("file://%s", TempDir)) u := file.Parse()