@@ -4,10 +4,11 @@ import (
4
4
"bytes"
5
5
"encoding/json"
6
6
"fmt"
7
- "github.com/json-iterator/go"
8
- "github.com/stretchr/testify/require"
9
7
"strconv"
10
8
"testing"
9
+
10
+ jsoniter "github.com/json-iterator/go"
11
+ "github.com/stretchr/testify/require"
11
12
)
12
13
13
14
func Test_read_float (t * testing.T ) {
@@ -86,9 +87,13 @@ func Test_write_float32(t *testing.T) {
86
87
should .Nil (stream .Error )
87
88
should .Equal ("abcdefg1.123456" , buf .String ())
88
89
90
+ val := float32 (0.0000001 )
89
91
stream = jsoniter .NewStream (jsoniter .ConfigDefault , nil , 0 )
90
- stream .WriteFloat32 (float32 (0.0000001 ))
91
- should .Equal ("1e-07" , string (stream .Buffer ()))
92
+ stream .WriteFloat32 (val )
93
+ output , err := json .Marshal (val )
94
+ should .Nil (err )
95
+ should .Equal ("1e-7" , string (stream .Buffer ()))
96
+ should .Equal (string (output ), string (stream .Buffer ()))
92
97
}
93
98
94
99
func Test_write_float64 (t * testing.T ) {
@@ -123,7 +128,11 @@ func Test_write_float64(t *testing.T) {
123
128
should .Nil (stream .Error )
124
129
should .Equal ("abcdefg1.123456" , buf .String ())
125
130
131
+ val := float64 (0.0000001 )
126
132
stream = jsoniter .NewStream (jsoniter .ConfigDefault , nil , 0 )
127
- stream .WriteFloat64 (float64 (0.0000001 ))
128
- should .Equal ("1e-07" , string (stream .Buffer ()))
133
+ stream .WriteFloat64 (val )
134
+ output , err := json .Marshal (val )
135
+ should .Nil (err )
136
+ should .Equal ("1e-7" , string (stream .Buffer ()))
137
+ should .Equal (string (output ), string (stream .Buffer ()))
129
138
}
0 commit comments