-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathskip_test.go
45 lines (41 loc) · 919 Bytes
/
skip_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package skip_tests
import (
"encoding/json"
"errors"
"github.com/json-iterator/go"
"github.com/stretchr/testify/require"
"io"
"reflect"
"testing"
)
type testCase struct {
ptr interface{}
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)
}
})
}
}
}