...
1
16 package issue_test
17 import (
18 `encoding/json`
19 `testing`
20 `github.com/bytedance/sonic`
21 `github.com/stretchr/testify/require`
22 )
23
24 func TestIssue460_UnmarshalMaxFloat32(t *testing.T) {
25 tests := []string {
26
27 "3.40282346638528859811704183484516925440e+38",
28
29
30 "3.402823469e+38",
31 "3.40282346e+38",
32 "3.40282347e+38",
33 "3.40282348e+38",
34 "3.4028235e+38",
35
36
37
38
39 "3.402823567797337e+38",
40 "3.402823567797338e+38",
41 "3.4028236e+38",
42 }
43
44 t.Run("max float32", func(t *testing.T) {
45 for _, data := range(tests) {
46 var f1, f2 float32
47 se := sonic.UnmarshalString(data, &f1)
48 je := json.Unmarshal([]byte(data), &f2)
49 require.Equal(t, se != nil, je != nil, data, se, je)
50 require.Equal(t, f2, f1, data)
51 }
52 })
53
54 t.Run("min float32", func(t *testing.T) {
55 for _, data := range(tests) {
56 data = string("-") + data
57 var f1, f2 float32
58 se := sonic.UnmarshalString(data, &f1)
59 je := json.Unmarshal([]byte(data), &f2)
60 require.Equal(t, se != nil, je != nil, data, se, je)
61 require.Equal(t, f2, f1, data)
62 }
63 })
64 }
65
View as plain text