46 lines
1,010 B
Go
46 lines
1,010 B
Go
// SPDX-FileCopyrightText: 2021 Luke Granger-Brown <depot@lukegb.com>
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package fuphttp
|
|
|
|
import "testing"
|
|
|
|
func TestFileExt(t *testing.T) {
|
|
tcs := []struct {
|
|
inp string
|
|
wantPrefix string
|
|
wantSuffix string
|
|
}{{
|
|
inp: "foo.txt",
|
|
wantPrefix: "foo",
|
|
wantSuffix: ".txt",
|
|
}, {
|
|
inp: "foo",
|
|
wantPrefix: "foo",
|
|
wantSuffix: "",
|
|
}, {
|
|
inp: "foo.bar.tbz2",
|
|
wantPrefix: "foo.bar",
|
|
wantSuffix: ".tbz2",
|
|
}, {
|
|
inp: "foo.tar.bz2",
|
|
wantPrefix: "foo",
|
|
wantSuffix: ".tar.bz2",
|
|
}, {
|
|
inp: "foo.tar.ppp",
|
|
wantPrefix: "foo.tar",
|
|
wantSuffix: ".ppp",
|
|
}, {
|
|
inp: "my-github.deadbeef.zip",
|
|
wantPrefix: "my-github.deadbeef",
|
|
wantSuffix: ".zip",
|
|
}}
|
|
|
|
for _, tc := range tcs {
|
|
gotPrefix, gotSuffix := fileExt(tc.inp)
|
|
if gotPrefix != tc.wantPrefix || gotSuffix != tc.wantSuffix {
|
|
t.Errorf("fileExt(%q) = (%q, %q); want (%q, %q)", tc.inp, gotPrefix, gotSuffix, tc.wantPrefix, tc.wantSuffix)
|
|
}
|
|
}
|
|
}
|