-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_test.go
59 lines (54 loc) · 1002 Bytes
/
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
52
53
54
55
56
57
58
59
package slog
import "testing"
type foo struct {
a, b int
}
var formatTests = []struct {
line map[string]interface{}
out string
}{
{
map[string]interface{}{"hello": 4, "world": "!"},
`hello="4" world="!"`,
},
{
map[string]interface{}{"foo": 1.2, "bar": false},
`bar="false" foo="1.2"`,
},
{
map[string]interface{}{`"`: `"`},
`"\""="\""`,
},
{
map[string]interface{}{`=`: foo{1, 5}},
`"="="{a:1 b:5}"`,
},
{
map[string]interface{}{`\`: &foo{2, 3}},
`"\\"="&{a:2 b:3}"`,
},
{
map[string]interface{}{" hello ": "世界"},
`" hello "="世界"`,
},
{
map[string]interface{}{"": "hi"},
`""="hi"`,
},
}
func TestFormat(t *testing.T) {
t.Parallel()
for _, test := range formatTests {
out := Format(test.line)
if out != test.out+"\n" {
t.Errorf("Expected Format(%v) = %q, got %q", test.line,
test.out, out)
}
}
}
func BenchmarkFormat(b *testing.B) {
for i := 0; i < b.N; i++ {
test := formatTests[i%len(formatTests)]
Format(test.line)
}
}