github.com/grbit/go-json@v0.11.0/color_test.go (about) 1 package json_test 2 3 import ( 4 "testing" 5 6 "github.com/grbit/go-json" 7 ) 8 9 func TestColorize(t *testing.T) { 10 v := struct { 11 A int 12 B uint 13 C float32 14 D string 15 E bool 16 F []byte 17 G []int 18 H *struct{} 19 I map[string]interface{} 20 }{ 21 A: 123, 22 B: 456, 23 C: 3.14, 24 D: "hello", 25 E: true, 26 F: []byte("binary"), 27 G: []int{1, 2, 3, 4}, 28 H: nil, 29 I: map[string]interface{}{ 30 "mapA": -10, 31 "mapB": 10, 32 "mapC": nil, 33 }, 34 } 35 t.Run("marshal with color", func(t *testing.T) { 36 b, err := json.MarshalWithOption(v, json.Colorize(json.DefaultColorScheme)) 37 if err != nil { 38 t.Fatal(err) 39 } 40 t.Log(string(b)) 41 }) 42 t.Run("marshal indent with color", func(t *testing.T) { 43 b, err := json.MarshalIndentWithOption(v, "", "\t", json.Colorize(json.DefaultColorScheme)) 44 if err != nil { 45 t.Fatal(err) 46 } 47 t.Log("\n" + string(b)) 48 }) 49 }