...
1
16
17 package issue_test
18
19 import (
20 . `github.com/bytedance/sonic`
21 `fmt`
22 `reflect`
23 _ `sync`
24 `testing`
25 `unsafe`
26
27 stdjson `encoding/json`
28 )
29
30 func TestLargeMapValue(t *testing.T) {
31 var jsonStr = `{
32 "1": {},
33 "2": {},
34 "3": {},
35 "4": {},
36 "5": {},
37 "6": {},
38 "7": {},
39 "8": {},
40 "9": {}
41 }`
42 type Case struct {
43 std interface{}
44 sonic interface{}
45 }
46 cases := []Case{
47 {&map[string]TestIssue100_LargeMapValue{} , &map[string]TestIssue100_LargeMapValue{}},
48 {&map[int32]TestIssue100_LargeMapValue{} , &map[int32]TestIssue100_LargeMapValue{}},
49 {&map[int64]TestIssue100_LargeMapValue{} , &map[int64]TestIssue100_LargeMapValue{}},
50 {&map[uint32]TestIssue100_LargeMapValue{} , &map[uint32]TestIssue100_LargeMapValue{}},
51 {&map[uint64]TestIssue100_LargeMapValue{} , &map[uint64]TestIssue100_LargeMapValue{}},
52 {&map[TestIssue100_textMarshalKey]TestIssue100_LargeMapValue{} , &map[TestIssue100_textMarshalKey]TestIssue100_LargeMapValue{}},
53 {&map[TestIssue100_textMarshalKeyPtr]TestIssue100_LargeMapValue{} , &map[TestIssue100_textMarshalKeyPtr]TestIssue100_LargeMapValue{}},
54 }
55 for i, c := range cases {
56 var stdw, sonicw = c.std, c.sonic
57 if err := stdjson.Unmarshal([]byte(jsonStr), stdw); err != nil {
58 t.Fatal(i, err)
59 }
60 fmt.Printf("[%d]struct size: %d\tmap length: %d\n", i, unsafe.Sizeof(TestIssue100_LargeMapValue{}), reflect.ValueOf(stdw).Elem().Len())
61 if err := Unmarshal([]byte(jsonStr), sonicw); err != nil {
62 t.Fatal(err)
63 }
64 if !reflect.DeepEqual(stdw, sonicw) {
65 fmt.Printf("have:\n\t%#v\nwant:\n\t%#v\n", sonicw, stdw)
66 t.Fatal(i)
67 }
68 }
69 }
70
71 type TestIssue100_textMarshalKey string
72
73 func(self TestIssue100_textMarshalKey) UnmarshalText(text []byte) error {
74 _ = TestIssue100_textMarshalKey(text)
75 return nil
76 }
77
78 type TestIssue100_textMarshalKeyPtr string
79
80 func(self *TestIssue100_textMarshalKeyPtr) UnmarshalText(text []byte) error {
81 *self = TestIssue100_textMarshalKeyPtr(text)
82 return nil
83 }
84
85 type TestIssue100_LargeMapValue struct {
86 Id [129]byte
87 }
View as plain text