-
Notifications
You must be signed in to change notification settings - Fork 0
/
gontenttype_test.go
52 lines (50 loc) · 990 Bytes
/
gontenttype_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
package gontenttype
import "testing"
func TestDetect(t *testing.T) {
type args struct {
content string
}
tests := []struct {
name string
args args
want ContentType
}{
{
name: "empty",
args: args{content: ""},
want: Unsupported,
},
{
name: "random string defaults to csv",
args: args{content: "lorem ipsum dolor sit amet"},
want: CSV,
},
{
name: "random string with commas, semicolons, tabs, and pipes defaults to csv",
args: args{content: "foo,bar;baz\tqux|quux"},
want: CSV,
},
{
name: "csv comma separated",
args: args{content: "foo,bar\nbaz,qux"},
want: CSV,
},
{
name: "json",
args: args{content: "{\"foo\":\"bar\"}"},
want: JSON,
},
{
name: "xml",
args: args{content: "<foo>bar</foo>"},
want: XML,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Detect(tt.args.content); got != tt.want {
t.Errorf("Detect() = %v, want %v", got, tt.want)
}
})
}
}