| 1 |
package test |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/json-iterator/go" |
| 5 |
"github.com/stretchr/testify/require" |
| 6 |
"reflect" |
| 7 |
"testing" |
| 8 |
) |
| 9 |
|
| 10 |
func Test_errorInput(t *testing.T) { |
| 11 |
for _, testCase := range unmarshalCases { |
| 12 |
if testCase.obj != nil { |
| 13 |
continue |
| 14 |
} |
| 15 |
valType := reflect.TypeOf(testCase.ptr).Elem() |
| 16 |
t.Run(valType.String(), func(t *testing.T) { |
| 17 |
for _, data := range []string{ |
| 18 |
`x`, |
| 19 |
`n`, |
| 20 |
`nul`, |
| 21 |
`{x}`, |
| 22 |
`{"x"}`, |
| 23 |
`{"x": "y"x}`, |
| 24 |
`{"x": "y"`, |
| 25 |
`{"x": "y", "a"}`, |
| 26 |
`[`, |
| 27 |
`[{"x": "y"}`, |
| 28 |
} { |
| 29 |
ptrVal := reflect.New(valType) |
| 30 |
ptr := ptrVal.Interface() |
| 31 |
err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(data), ptr) |
| 32 |
require.Error(t, err, "on input %q", data) |
| 33 |
} |
| 34 |
}) |
| 35 |
} |
| 36 |
} |