Skip to content

add testcase for readany #437

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions any_tests/jsoniter_any_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,22 @@ func Test_object_wrapper_any_get_all(t *testing.T) {
should.Contains(any.Keys(), "Field2")
should.NotContains(any.Keys(), "Field3")
}

func Test_object_wrapper_readany(t *testing.T) {
type testStruct struct {
Field1 string
Field2 int
Field3 bool
}
var t5 testStruct
testIter := jsoniter.NewIterator(jsoniter.ConfigDefault)
testIter.ResetBytes([]byte(`{}`))
lazyAny := testIter.ReadAny()
lazyAny.ToVal(&t5)
should := require.New(t)
should.Equal(testStruct{"", 0, false}, t5)
testIter.ResetBytes([]byte(`{"Field1": "abc", "Field2": 100, "Field3": true}`))
lazyAny = testIter.ReadAny()
lazyAny.ToVal(&t5)
should.Equal(testStruct{"abc", 100, true}, t5)
}