...
1
16
17 package issue_test
18
19 import (
20 `encoding/json`
21 `fmt`
22 `testing`
23
24 `github.com/bytedance/sonic`
25 `github.com/davecgh/go-spew/spew`
26 `github.com/stretchr/testify/require`
27 )
28
29
30 type M1 map[string]int
31
32 func (m *M1) MarshalJSON() ([]byte, error) {
33 return []byte(fmt.Sprintf(`{"m":%q}`, spew.Sprintf("%#+v", m))), nil
34 }
35
36 type M2 map[string]int
37
38 func (m M2) MarshalJSON() ([]byte, error) {
39 return []byte(fmt.Sprintf(`{"m":%q}`, spew.Sprintf("%#+v", m))), nil
40 }
41
42 func TestIssue258(t *testing.T) {
43 m1 := M1{}
44 oe,ee := json.Marshal(m1)
45 os,es := sonic.Marshal(m1)
46 require.Equal(t, ee, es)
47 require.Equal(t, oe, os)
48
49 m1p := &M1{}
50 oe,ee = json.Marshal(m1p)
51 os,es = sonic.Marshal(m1p)
52 require.Equal(t, ee, es)
53 require.Equal(t, oe, os)
54
55 m2 := M2{}
56 oe,ee = json.Marshal(m2)
57 os,es = sonic.Marshal(m2)
58 require.Equal(t, ee, es)
59 require.Equal(t, oe, os)
60
61 m2p := &M2{}
62 oe,ee = json.Marshal(m2p)
63 os,es = sonic.Marshal(m2p)
64 require.Equal(t, ee, es)
65 require.Equal(t, oe, os)
66 }
View as plain text