-
Notifications
You must be signed in to change notification settings - Fork 175
/
text_utils_test.go
44 lines (38 loc) · 1.39 KB
/
text_utils_test.go
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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseMimeType(t *testing.T) {
var mimeType = parseMimeType("application/json")
assert.Equal(t, "application", mimeType.Type)
assert.Equal(t, "json", mimeType.subType)
assert.Equal(t, "", mimeType.scope)
assert.True(t, mimeType.isTextContent())
assert.False(t, mimeType.isBinaryContent())
}
func TestParseXMimeType(t *testing.T) {
var mimeType = parseMimeType("application/x-msdownload")
assert.Equal(t, "application", mimeType.Type)
assert.Equal(t, "msdownload", mimeType.subType)
assert.Equal(t, "x", mimeType.scope)
assert.False(t, mimeType.isTextContent())
assert.True(t, mimeType.isBinaryContent())
}
func TestVndMimeType(t *testing.T) {
var mimeType = parseMimeType("application/vnd.ms-powerpoint.template.macroenabled.12")
assert.Equal(t, "application", mimeType.Type)
assert.Equal(t, "ms-powerpoint", mimeType.subType)
assert.Equal(t, "vnd", mimeType.scope)
assert.False(t, mimeType.isTextContent())
assert.True(t, mimeType.isBinaryContent())
}
func TestWildcardMatch(t *testing.T) {
assert.True(t, wildcardMatch("test", "test"))
assert.True(t, wildcardMatch("test", "tes*"))
assert.True(t, wildcardMatch("test", "tes?"))
assert.True(t, wildcardMatch("test", "t*"))
assert.True(t, wildcardMatch("test", "*t*"))
assert.False(t, wildcardMatch("test", "tt*"))
assert.False(t, wildcardMatch("test", "es"))
}