...
1
16
17 package issue_test
18
19 import (
20 `testing`
21 `encoding/json`
22 `github.com/stretchr/testify/require`
23
24 `github.com/bytedance/sonic`
25 )
26
27 func TestDecodeStringToJsonNumber(t *testing.T) {
28 var objs json.Number
29 errs := sonic.UnmarshalString(`"1234"`, &objs)
30 var obje json.Number
31 erre := json.Unmarshal([]byte(`"1234"`), &obje)
32 require.Equal(t, erre, errs)
33 require.Equal(t, obje, objs)
34
35 errs = sonic.UnmarshalString(`"12x4"`, &objs)
36 erre = json.Unmarshal([]byte(`"12x4"`), &obje)
37 require.Error(t, errs)
38 require.Error(t, erre)
39
40 errs = sonic.UnmarshalString(`"1234`, &objs)
41 erre = json.Unmarshal([]byte(`"1234`), &obje)
42 require.Error(t, errs)
43 require.Error(t, erre)
44
45 errs = sonic.UnmarshalString(`1234"`, &objs)
46 erre = json.Unmarshal([]byte(`1234"`), &obje)
47 require.Error(t, errs)
48 require.Error(t, erre)
49 }
View as plain text