Skip to content

Commit

Permalink
test: generate more skip cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Jan 12, 2022
1 parent 42962d1 commit 698bdbe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
6 changes: 3 additions & 3 deletions dec_skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ var (
}
)

// skipNumber reads one JSON number.
//
// Assumes d.buf is not empty.
func (d *Decoder) skipNumber() error {
if d.head == d.tail {
return io.ErrUnexpectedEOF
}
c := d.buf[d.head]
d.head++
switch c {
Expand Down
35 changes: 22 additions & 13 deletions dec_skip_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,21 @@ func Test_skip(t *testing.T) {
`"\t"`, // valid
},
})
testCases = append(testCases, testCase{
ptr: (*[]interface{})(nil),
inputs: []string{
`[]`, // valid
`[1]`, // valid
`[ 1, "hello"]`, // valid
`[abc]`, // invalid
`[`, // invalid
`[[]`, // invalid
},
})
testCases = append(testCases, testCase{
numberCase := testCase{
ptr: (*float64)(nil),
inputs: []string{
"0", // valid
"-", // invalid
"+1", // invalid
"-a", // invalid
"-\x00", // invalid, zero byte
"0.1", // valid
"0e1", // valid
"0e+1", // valid
"0e-1", // valid
"0e-11", // valid
"0e-1a", // invalid
"0e-1+", // invalid
"0e", // invalid
"-e", // invalid
"+e", // invalid
Expand All @@ -72,7 +65,23 @@ func Test_skip(t *testing.T) {
"10.", // invalid
"-0.12", // valid
},
})
}
testCases = append(testCases, numberCase)
arrayCase := testCase{
ptr: (*[]interface{})(nil),
inputs: []string{
`[]`, // valid
`[1]`, // valid
`[ 1, "hello"]`, // valid
`[abc]`, // invalid
`[`, // invalid
`[[]`, // invalid
},
}
for _, c := range numberCase.inputs {
arrayCase.inputs = append(arrayCase.inputs, `[`+c+`]`)
}
testCases = append(testCases, arrayCase)
testCases = append(testCases, testCase{
ptr: (*struct{})(nil),
inputs: []string{
Expand Down

0 comments on commit 698bdbe

Please sign in to comment.