Skip to content

Commit 573ec6b

Browse files
author
Tao Wen
committed
write float64
1 parent 0c5b094 commit 573ec6b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

stream_tests/number_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,32 @@ func Test_write_float32(t *testing.T) {
201201
})
202202
}
203203
}
204+
205+
func Test_write_float64(t *testing.T) {
206+
vals := []float64{0, 1, -1, 99, 0xff, 0xfff, 0xffff, 0xfffff, 0xffffff, 0x4ffffff, 0xfffffff,
207+
-0x4ffffff, -0xfffffff, 1.2345, 1.23456, 1.234567, 1.001}
208+
for _, val := range vals {
209+
t.Run(fmt.Sprintf("%v", val), func(t *testing.T) {
210+
stream := jsoniter.NewStream()
211+
stream.WriteFloat64(val)
212+
output, err := json.Marshal(val)
213+
if err != nil {
214+
t.Fatal()
215+
}
216+
if string(output) != string(stream.Buffer()) {
217+
t.Fatal()
218+
}
219+
})
220+
t.Run(fmt.Sprintf("%v", val), func(t *testing.T) {
221+
stream := jsoniter.NewStream()
222+
stream.WriteInterface(val)
223+
output, err := json.Marshal(val)
224+
if err != nil {
225+
t.Fatal()
226+
}
227+
if string(output) != string(stream.Buffer()) {
228+
t.Fatal()
229+
}
230+
})
231+
}
232+
}

0 commit comments

Comments
 (0)