Closed
Description
Consider the following test case, all 6 cases are valid json values. Only number will cause a not nil LastError()
package any_test
import (
"github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
"testing"
)
func TestAny(t *testing.T) {
for _, s := range []string{
`-32000`,
`"hello"`,
`false`,
`null`,
`{"a":300}`,
`[]`,
} {
a := jsoniter.Get([]byte(s))
assert.NoError(t, a.LastError(), "Any.Get(%+q) should have no error", s)
switch a.ValueType() {
case jsoniter.NumberValue:
_ = a.ToInt()
case jsoniter.StringValue:
_ = a.ToString()
case jsoniter.BoolValue:
_ = a.ToBool()
case jsoniter.NilValue:
case jsoniter.ObjectValue:
var v map[string]interface{}
a.ToVal(&v)
case jsoniter.ArrayValue:
var v []interface{}
a.ToVal(&v)
}
assert.NoError(t, a.LastError(), "Any(%+q) ToXXX should have no error", s)
}
}
Output:
--- FAIL: TestAny (0.00s)
Error Trace: any_test.go:36
Error: Received unexpected error:
EOF
Test: TestAny
Messages: Any("-32000") ToXXX should have no error
FAIL
exit status 1
FAIL tmp/jsoniter 0.024s
jsoniter version: 358cfc3
Metadata
Metadata
Assignees
Labels
No labels