You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-15 22:50:24 +02:00
write object
This commit is contained in:
@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
"github.com/json-iterator/go/require"
|
||||
"bytes"
|
||||
)
|
||||
|
||||
func Test_empty_object(t *testing.T) {
|
||||
@ -66,6 +68,23 @@ func Test_two_field(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_write_object(t *testing.T) {
|
||||
should := require.New(t)
|
||||
buf := &bytes.Buffer{}
|
||||
stream := NewStream(buf, 4096)
|
||||
stream.IndentionStep = 2
|
||||
stream.WriteObjectStart()
|
||||
stream.WriteObjectField("hello")
|
||||
stream.WriteInt(1)
|
||||
stream.WriteMore()
|
||||
stream.WriteObjectField("world")
|
||||
stream.WriteInt(2)
|
||||
stream.WriteObjectEnd()
|
||||
stream.Flush()
|
||||
should.Nil(stream.Error)
|
||||
should.Equal("{\n hello:1,\n world:2\n}", buf.String())
|
||||
}
|
||||
|
||||
type TestObj struct {
|
||||
Field1 string
|
||||
Field2 uint64
|
||||
|
Reference in New Issue
Block a user