1
0
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:
Tao Wen
2017-01-07 22:08:45 +08:00
parent 5e50b3e11c
commit 21549b9fd8
4 changed files with 113 additions and 6 deletions

View File

@ -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