Skip to content

Any.ToInt() resulting not nil LastError() ? #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
huangjunwen opened this issue Jan 27, 2018 · 0 comments
Closed

Any.ToInt() resulting not nil LastError() ? #228

huangjunwen opened this issue Jan 27, 2018 · 0 comments

Comments

@huangjunwen
Copy link

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

@taowen taowen closed this as completed in ea8c330 Jan 27, 2018
zhenzou pushed a commit to zhenzou/jsoniter that referenced this issue Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant