1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-27 23:18:42 +02:00

array lazy iterator

This commit is contained in:
Tao Wen
2017-01-24 22:47:56 +08:00
parent 8656482625
commit fa165c684f
4 changed files with 75 additions and 0 deletions

@ -67,6 +67,19 @@ func Test_read_two_element_array_as_any(t *testing.T) {
should.Equal(2, any.Size())
}
func Test_read_array_with_any_iterator(t *testing.T) {
should := require.New(t)
any, err := UnmarshalAnyFromString("[1,2]")
should.Nil(err)
var element Any
var elements []int
for next, hasNext := any.IterateArray(); hasNext; {
element, hasNext = next()
elements = append(elements, element.ToInt())
}
should.Equal([]int{1, 2}, elements)
}
func Test_invalid_array(t *testing.T) {
_, err := UnmarshalAnyFromString("[")
if err == nil || err == io.EOF {