-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
color_test.go
49 lines (46 loc) · 842 Bytes
/
color_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
package json_test
import (
"testing"
"github.com/goccy/go-json"
)
func TestColorize(t *testing.T) {
v := struct {
A int
B uint
C float32
D string
E bool
F []byte
G []int
H *struct{}
I map[string]interface{}
}{
A: 123,
B: 456,
C: 3.14,
D: "hello",
E: true,
F: []byte("binary"),
G: []int{1, 2, 3, 4},
H: nil,
I: map[string]interface{}{
"mapA": -10,
"mapB": 10,
"mapC": nil,
},
}
t.Run("marshal with color", func(t *testing.T) {
b, err := json.MarshalWithOption(v, json.Colorize(json.DefaultColorScheme))
if err != nil {
t.Fatal(err)
}
t.Log(string(b))
})
t.Run("marshal indent with color", func(t *testing.T) {
b, err := json.MarshalIndentWithOption(v, "", "\t", json.Colorize(json.DefaultColorScheme))
if err != nil {
t.Fatal(err)
}
t.Log("\n" + string(b))
})
}