-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_test.go
51 lines (47 loc) · 1.02 KB
/
format_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
package gnfmt_test
import (
"testing"
"github.com/gnames/gnfmt"
"github.com/matryer/is"
)
func TestNewFormat(t *testing.T) {
is := is.New(t)
tests := []struct {
name string
input string
output gnfmt.Format
errNil bool
}{
{"csv", "csv", gnfmt.CSV, true},
{"compact", "compact", gnfmt.CompactJSON, true},
{"pretty", "pretty", gnfmt.PrettyJSON, true},
{"tsv", "tsv", gnfmt.TSV, true},
{"bad", "bad", gnfmt.FormatNone, false},
}
for _, v := range tests {
t.Run(v.name, func(_ *testing.T) {
gf, err := gnfmt.NewFormat(v.input)
is.Equal(v.output, gf)
is.Equal(v.errNil, err == nil)
})
}
}
func TestString(t *testing.T) {
is := is.New(t)
tests := []struct {
name string
input gnfmt.Format
output string
}{
{"csv", gnfmt.CSV, "CSV"},
{"tsv", gnfmt.TSV, "TSV"},
{"compact", gnfmt.CompactJSON, "compact JSON"},
{"pretty", gnfmt.PrettyJSON, "pretty JSON"},
}
for _, v := range tests {
t.Run(v.name, func(_ *testing.T) {
s := v.input.String()
is.Equal(v.output, s)
})
}
}