1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-12 22:47:42 +02:00

ReadArrayCB

This commit is contained in:
Tao Wen
2017-01-20 13:54:51 +08:00
parent 80c86e63b1
commit 928bc4ce72
4 changed files with 69 additions and 47 deletions

View File

@ -8,26 +8,28 @@ import (
)
func Test_empty_array(t *testing.T) {
should := require.New(t)
iter := ParseString(`[]`)
cont := iter.ReadArray()
if cont != false {
t.FailNow()
}
should.False(cont)
iter = ParseString(`[]`)
iter.ReadArrayCB(func(iter *Iterator) bool {
should.FailNow("should not call")
return true
})
}
func Test_one_element(t *testing.T) {
should := require.New(t)
iter := ParseString(`[1]`)
cont := iter.ReadArray()
if cont != true {
t.FailNow()
}
if iter.ReadInt64() != 1 {
t.FailNow()
}
cont = iter.ReadArray()
if cont != false {
t.FailNow()
}
should.True(iter.ReadArray())
should.Equal(1, iter.ReadInt())
should.False(iter.ReadArray())
iter = ParseString(`[1]`)
iter.ReadArrayCB(func(iter *Iterator) bool {
should.Equal(1, iter.ReadInt())
return true
})
}
func Test_two_elements(t *testing.T) {
@ -136,7 +138,7 @@ func Test_write_array(t *testing.T) {
func Test_write_val_array(t *testing.T) {
should := require.New(t)
val := []int{1,2,3}
val := []int{1, 2, 3}
str, err := MarshalToString(val)
should.Nil(err)
should.Equal("[1,2,3]", str)