2016-12-11 15:53:35 +08:00
|
|
|
package jsoniter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-01-05 21:23:08 +08:00
|
|
|
"testing"
|
2017-05-05 17:44:09 +08:00
|
|
|
"github.com/json-iterator/go/require"
|
2016-12-11 15:53:35 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_bind_api_demo(t *testing.T) {
|
2017-05-05 17:44:09 +08:00
|
|
|
should := require.New(t)
|
2016-12-11 15:53:35 +08:00
|
|
|
val := []int{}
|
2017-05-05 17:44:09 +08:00
|
|
|
err := UnmarshalFromString(`[0,1,2,3] `, &val)
|
|
|
|
should.Nil(err)
|
|
|
|
should.Equal([]int{0, 1, 2, 3}, val)
|
2016-12-11 15:53:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func Test_iterator_api_demo(t *testing.T) {
|
|
|
|
iter := ParseString(`[0,1,2,3]`)
|
|
|
|
total := 0
|
|
|
|
for iter.ReadArray() {
|
|
|
|
total += iter.ReadInt()
|
|
|
|
}
|
|
|
|
fmt.Println(total)
|
2017-06-02 16:52:20 +08:00
|
|
|
}
|