Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Commit c3b6c1e

Browse files
committed
consolidate skip tests
1 parent 0ed9de9 commit c3b6c1e

File tree

14 files changed

+122
-195
lines changed

14 files changed

+122
-195
lines changed

skip_tests/array/inputs.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

skip_tests/array/skip_test.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

skip_tests/array_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package skip_tests
2+
3+
func init() {
4+
testCases = append(testCases, testCase{
5+
ptr: (*[]interface{})(nil),
6+
inputs: []string{
7+
`[]`, // valid
8+
`[1]`, // valid
9+
`[ 1, "hello"]`, // valid
10+
`[abc]`, // invalid
11+
`[`, // invalid
12+
`[[]`, // invalid
13+
},
14+
})
15+
}

skip_tests/float64_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package skip_tests
2+
3+
func init() {
4+
testCases = append(testCases, testCase{
5+
ptr: (*float64)(nil),
6+
inputs: []string{
7+
"+1", // invalid
8+
"-a", // invalid
9+
"-\x00", // invalid, zero byte
10+
"0.1", // valid
11+
"0..1", // invalid, more dot
12+
"1e+1", // valid
13+
"1+1", // invalid
14+
"1E1", // valid, e or E
15+
"1ee1", // invalid
16+
"100a", // invalid
17+
"10.", // invalid
18+
},
19+
})
20+
}

skip_tests/number/inputs.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

skip_tests/number/skip_test.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

skip_tests/object/inputs.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

skip_tests/object/skip_test.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

skip_tests/skip_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package skip_tests
2+
3+
import (
4+
"encoding/json"
5+
"errors"
6+
"github.com/json-iterator/go"
7+
"github.com/stretchr/testify/require"
8+
"io"
9+
"testing"
10+
"reflect"
11+
)
12+
13+
type testCase struct {
14+
ptr interface{}
15+
inputs []string
16+
}
17+
18+
var testCases []testCase
19+
20+
func Test_skip(t *testing.T) {
21+
for _, testCase := range testCases {
22+
valType := reflect.TypeOf(testCase.ptr).Elem()
23+
for _, input := range testCase.inputs {
24+
t.Run(input, func(t *testing.T) {
25+
should := require.New(t)
26+
ptrVal := reflect.New(valType)
27+
stdErr := json.Unmarshal([]byte(input), ptrVal.Interface())
28+
iter := jsoniter.ParseString(jsoniter.ConfigDefault, input)
29+
iter.Skip()
30+
iter.ReadNil() // trigger looking forward
31+
err := iter.Error
32+
if err == io.EOF {
33+
err = nil
34+
} else {
35+
err = errors.New("remaining bytes")
36+
}
37+
if stdErr == nil {
38+
should.Nil(err)
39+
} else {
40+
should.NotNil(err)
41+
}
42+
})
43+
}
44+
}
45+
}

skip_tests/string/inputs.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)