-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmetadata_format_test.go
More file actions
48 lines (43 loc) · 1.17 KB
/
Copy pathmetadata_format_test.go
File metadata and controls
48 lines (43 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package imgx
import "testing"
func TestNormalizeDecodedFormat(t *testing.T) {
testCases := []struct {
name string
in string
want string
}{
{name: "webp", in: "webp", want: "WEBP"},
{name: "jpeg uppercase", in: "JPEG", want: "JPEG"},
{name: "tif alias", in: "tif", want: "TIFF"},
{name: "trimmed custom", in: " heic ", want: "HEIC"},
{name: "empty", in: " ", want: "Unknown"},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := normalizeDecodedFormat(tc.in)
if got != tc.want {
t.Fatalf("normalizeDecodedFormat(%q) = %q, want %q", tc.in, got, tc.want)
}
})
}
}
func TestMimeFromDecodedFormat(t *testing.T) {
testCases := []struct {
name string
in string
want string
}{
{name: "webp", in: "webp", want: "image/webp"},
{name: "jpeg", in: "jpeg", want: "image/jpeg"},
{name: "tiff alias", in: "tif", want: "image/tiff"},
{name: "unknown", in: "heic", want: "application/octet-stream"},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := mimeFromDecodedFormat(tc.in)
if got != tc.want {
t.Fatalf("mimeFromDecodedFormat(%q) = %q, want %q", tc.in, got, tc.want)
}
})
}
}