You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Consider the following test case, all 6 cases are valid json values. Only number will cause a not nil
LastError()
Output:
jsoniter version: 358cfc3
The text was updated successfully, but these errors were encountered: