...
1 package test
2
3 import (
4 "encoding/json"
5 "github.com/json-iterator/go"
6 "github.com/stretchr/testify/require"
7 "testing"
8 )
9
10 func Test_marshal_indent(t *testing.T) {
11 should := require.New(t)
12 obj := struct {
13 F1 int
14 F2 []int
15 }{1, []int{2, 3, 4}}
16 output, err := json.MarshalIndent(obj, "", " ")
17 should.Nil(err)
18 should.Equal("{\n \"F1\": 1,\n \"F2\": [\n 2,\n 3,\n 4\n ]\n}", string(output))
19 output, err = jsoniter.MarshalIndent(obj, "", " ")
20 should.Nil(err)
21 should.Equal("{\n \"F1\": 1,\n \"F2\": [\n 2,\n 3,\n 4\n ]\n}", string(output))
22 }
23
24 func Test_marshal_indent_map(t *testing.T) {
25 should := require.New(t)
26 obj := map[int]int{1: 2}
27 output, err := json.MarshalIndent(obj, "", " ")
28 should.Nil(err)
29 should.Equal("{\n \"1\": 2\n}", string(output))
30 output, err = jsoniter.MarshalIndent(obj, "", " ")
31 should.Nil(err)
32 should.Equal("{\n \"1\": 2\n}", string(output))
33 output, err = jsoniter.ConfigCompatibleWithStandardLibrary.MarshalIndent(obj, "", " ")
34 should.Nil(err)
35 should.Equal("{\n \"1\": 2\n}", string(output))
36 }
37
View as plain text