File: kind_test.go

package info (click to toggle)
golang-gopkg-h2non-filetype.v1 1.0.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, buster-backports
  • size: 172 kB
  • sloc: makefile: 4
file content (40 lines) | stat: -rw-r--r-- 744 bytes parent folder | download | duplicates (3)
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
package filetype

import (
	"testing"
)

func TestKind(t *testing.T) {
	var cases = []struct {
		buf []byte
		ext string
	}{
		{[]byte{0xFF, 0xD8, 0xFF}, "jpg"},
		{[]byte{0x89, 0x50, 0x4E, 0x47}, "png"},
		{[]byte{0x89, 0x0, 0x0}, "unknown"},
	}

	for _, test := range cases {
		kind, _ := Image(test.buf)
		if kind.Extension != test.ext {
			t.Fatalf("Invalid match: %s != %s", kind.Extension, test.ext)
		}
	}
}

func TestIsKind(t *testing.T) {
	var cases = []struct {
		buf   []byte
		match bool
	}{
		{[]byte{0xFF, 0xD8, 0xFF}, true},
		{[]byte{0x89, 0x50, 0x4E, 0x47}, true},
		{[]byte{0x89, 0x0, 0x0}, false},
	}

	for _, test := range cases {
		if IsImage(test.buf) != test.match {
			t.Fatalf("Invalid match: %t", test.match)
		}
	}
}