1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-15 22:50:24 +02:00

#62 SkipAndReturnBytes should support reader

This commit is contained in:
Tao Wen
2017-06-18 16:28:43 +08:00
parent 7a049ec79c
commit 54dbcda64d
3 changed files with 56 additions and 6 deletions

View File

@ -3,6 +3,8 @@ package jsoniter
import (
"encoding/json"
"testing"
"github.com/json-iterator/go/require"
"bytes"
)
func Test_skip_number(t *testing.T) {
@ -75,6 +77,22 @@ func Test_skip_nested(t *testing.T) {
}
}
func Test_skip_and_return_bytes(t *testing.T) {
should := require.New(t)
iter := ParseString(ConfigDefault, `[ {"a" : [{"b": "c"}], "d": 102 }, "b"]`)
iter.ReadArray()
skipped := iter.SkipAndReturnBytes()
should.Equal(`{"a" : [{"b": "c"}], "d": 102 }`, string(skipped))
}
func Test_skip_and_return_bytes_with_reader(t *testing.T) {
should := require.New(t)
iter := Parse(ConfigDefault, bytes.NewBufferString(`[ {"a" : [{"b": "c"}], "d": 102 }, "b"]`), 4)
iter.ReadArray()
skipped := iter.SkipAndReturnBytes()
should.Equal(`{"a" : [{"b": "c"}], "d": 102 }`, string(skipped))
}
type TestResp struct {
Code uint64
}