33 lines
827 B
Go
33 lines
827 B
Go
package bookfile
|
|
|
|
import "testing"
|
|
|
|
func TestFormatFromExt(t *testing.T) {
|
|
cases := map[string]string{
|
|
"a.cbz": "cbz", "B.PDF": "pdf", "x.epub": "epub", "y.txt": "txt", "z.md": "md",
|
|
"w.rar": "", "noext": "", "cbr.cbZ": "cbz", "tar.gz": "",
|
|
}
|
|
for in, want := range cases {
|
|
if got := FormatFromExt(in); got != want {
|
|
t.Errorf("FormatFromExt(%q)=%q want %q", in, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSafeName(t *testing.T) {
|
|
cases := map[string]string{
|
|
"my book.cbz": "my book.cbz",
|
|
"../../etc/passwd": "passwd",
|
|
"/abs/name.pdf": "name.pdf",
|
|
"a\\b\\c.epub": "c.epub",
|
|
" spaced .txt ": "spaced .txt",
|
|
"con\ntl.bin": "contl.bin",
|
|
"": "",
|
|
}
|
|
for in, want := range cases {
|
|
if got := SafeName(in); got != want {
|
|
t.Errorf("SafeName(%q)=%q want %q", in, got, want)
|
|
}
|
|
}
|
|
}
|