-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmimetype_match_text_test.go
86 lines (75 loc) · 1.65 KB
/
mimetype_match_text_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package mimeheader_test
import (
"fmt"
"testing"
mimeheader "github.com/Jake-Convictional/mimeheaderTMP"
)
func ExampleMimeType_MatchText() {
// Parse media type
mediaType := "application/json; q=1; param=test;"
mimeType, err := mimeheader.ParseMediaType(mediaType)
if err != nil {
panic(err)
}
// Parse input and match it.
fmt.Println(mimeType.MatchText("application/json; param=test"))
fmt.Println(mimeType.MatchText("application/xml; q=1"))
fmt.Println(mimeType.MatchText("text/plain"))
// Output:
// true
// false
// false
}
func TestMimeType_MatchText(t *testing.T) {
t.Parallel()
for _, prov := range providerMimeTypeMatchText() {
prov := prov
t.Run(prov.name, func(t *testing.T) {
t.Parallel()
act := prov.b.MatchText(prov.t)
if prov.exp != act {
t.Fatalf("Match is not equal to expected value. Expected: %t. Actual: %t", prov.exp, act)
}
})
}
}
type mimeTypeMatchText struct {
name string
b mimeheader.MimeType
t string
exp bool
}
func providerMimeTypeMatchText() []mimeTypeMatchText {
return []mimeTypeMatchText{
{
name: "Match application/*, positive",
b: mimeheader.MimeType{
Type: "application",
Subtype: "*",
Params: nil,
},
t: "application/json;t=1;q=0.9",
exp: true,
},
{
name: "Match application/*, positive",
b: mimeheader.MimeType{
Type: "application",
Subtype: "json",
Params: nil,
},
t: "application/*;t=1;q=0.9",
exp: true,
},
{
name: "Match application/*, positive",
b: mimeheader.MimeType{
Type: "text",
Subtype: "json",
Params: nil,
},
t: "application/*;t=1;q=0.9",
exp: false,
},
}
}