1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-20 11:28:49 +02:00
json-iterator/skip_tests/skip_test.go

46 lines
919 B
Go
Raw Normal View History

2018-02-13 20:41:21 +08:00
package skip_tests
import (
"encoding/json"
"errors"
"github.com/json-iterator/go"
"github.com/stretchr/testify/require"
"io"
"reflect"
2018-02-24 22:04:41 +08:00
"testing"
2018-02-13 20:41:21 +08:00
)
type testCase struct {
2018-02-22 10:12:08 +08:00
ptr interface{}
2018-02-13 20:41:21 +08:00
inputs []string
}
var testCases []testCase
func Test_skip(t *testing.T) {
for _, testCase := range testCases {
valType := reflect.TypeOf(testCase.ptr).Elem()
for _, input := range testCase.inputs {
t.Run(input, func(t *testing.T) {
should := require.New(t)
ptrVal := reflect.New(valType)
stdErr := json.Unmarshal([]byte(input), ptrVal.Interface())
iter := jsoniter.ParseString(jsoniter.ConfigDefault, input)
iter.Skip()
iter.ReadNil() // trigger looking forward
err := iter.Error
if err == io.EOF {
err = nil
} else {
err = errors.New("remaining bytes")
}
if stdErr == nil {
should.Nil(err)
} else {
should.NotNil(err)
}
})
}
}
}