...
1
16
17 package issue_test
18
19 import (
20 `encoding/json`
21 `testing`
22 `reflect`
23
24 `github.com/stretchr/testify/require`
25 .`github.com/bytedance/sonic`
26 )
27
28 type Issue141_Case_Insentive1 struct {
29 Field0 int `json:"foo"`
30 Field1 int `json:"FOO"`
31 Field2 int `json:"FoO"`
32 FOo int
33 }
34
35 type Issue141_Case_Insentive2 struct {
36 Field0 int `json:"FOO"`
37 Field1 int `json:"foo"`
38 Field2 int `json:"FoO"`
39 FOo int
40 }
41
42 type Issue141_Case_Insentive3 struct {
43 FOo int
44 Field0 int `json:"FoO"`
45 Field1 int `json:"foo"`
46 Field2 int `json:"FOO"`
47 }
48
49 type Issue141_Case_Insentive4 struct {
50 foo int
51 Field0 int `json:"FoO"`
52 Field1 int `json:"foo"`
53 Field2 int `json:"FOO"`
54 }
55
56 type Issue141_Matched1 struct {
57 Field0 int `json:"FOO"`
58 Field1 int `json:"foo"`
59 Field2 int `json:"FoO"`
60 Foo int
61 }
62
63 type Issue141_Matched2 struct {
64 Field0 int `json:"FOO"`
65 Field1 int `json:"foo"`
66 Field2 int `json:"FoO"`
67 Foo int
68 Field3 int `json:"Foo"`
69 }
70
71
72 func TestIssue141_StructFieldPriority(t *testing.T) {
73 data := []byte("{\"Foo\":1}")
74 for _, factory := range []func() interface{}{
75 func() interface{} { return new(Issue141_Case_Insentive1) },
76 func() interface{} { return new(Issue141_Case_Insentive2) },
77 func() interface{} { return new(Issue141_Case_Insentive3) },
78 func() interface{} { return new(Issue141_Case_Insentive4) },
79 func() interface{} { return new(Issue141_Matched1) },
80 func() interface{} { return new(Issue141_Matched2) },
81 }{
82 v1, v2 := factory(), factory()
83 err1 := json.Unmarshal(data, &v1)
84 err2 := Unmarshal(data, &v2)
85 require.NoError(t, err1)
86 require.NoError(t, err2)
87 require.Equal(t, v1, v2)
88
89 switch reflect.TypeOf(v2).Elem() {
90 case reflect.TypeOf(Issue141_Case_Insentive1{}):
91 println("Issue141_Case_Insentive1.Field0(tag foo) is ", v2.(*Issue141_Case_Insentive1).Field0)
92 case reflect.TypeOf(Issue141_Case_Insentive2{}):
93 println("Issue141_Case_Insentive2.Field0(tag FOO) is ", v2.(*Issue141_Case_Insentive2).Field0)
94 case reflect.TypeOf(Issue141_Case_Insentive3{}):
95 println("Issue141_Case_Insentive3.FOo is ", v2.(*Issue141_Case_Insentive3).FOo)
96 case reflect.TypeOf(Issue141_Case_Insentive4{}):
97 println("Issue141_Case_Insentive4.Field0(tag FoO) is ", v2.(*Issue141_Case_Insentive4).Field0)
98 case reflect.TypeOf(Issue141_Matched1{}):
99 println("Issue141_Matched1.Foo is ", v2.(*Issue141_Matched1).Foo)
100 case reflect.TypeOf(Issue141_Matched2{}):
101 println("Issue141_Matched2.Field3(tag Foo) is ", v2.(*Issue141_Matched2).Field3)
102 println("Issue141_Matched2.Foo is ", v2.(*Issue141_Matched2).Foo)
103 }
104 }
105 }
106
View as plain text