diff --git a/jsoniter_object_test.go b/jsoniter_object_test.go index b69f0bf..9599b6a 100644 --- a/jsoniter_object_test.go +++ b/jsoniter_object_test.go @@ -174,6 +174,106 @@ func Test_decode_five_fields_struct(t *testing.T) { should.Equal("e", obj.Field5) } +func Test_decode_six_fields_struct(t *testing.T) { + should := require.New(t) + type TestObject struct { + Field1 string + Field2 string + Field3 string + Field4 string + Field5 string + Field6 string + } + obj := TestObject{} + should.Nil(UnmarshalFromString(`{}`, &obj)) + should.Equal("", obj.Field1) + should.Nil(UnmarshalFromString(`{"Field1": "a", "Field2": "b", "Field3": "c", "Field4": "d", "Field5": "e", "Field6": "x"}`, &obj)) + should.Equal("a", obj.Field1) + should.Equal("b", obj.Field2) + should.Equal("c", obj.Field3) + should.Equal("d", obj.Field4) + should.Equal("e", obj.Field5) + should.Equal("x", obj.Field6) +} + +func Test_decode_seven_fields_struct(t *testing.T) { + should := require.New(t) + type TestObject struct { + Field1 string + Field2 string + Field3 string + Field4 string + Field5 string + Field6 string + Field7 string + } + obj := TestObject{} + should.Nil(UnmarshalFromString(`{}`, &obj)) + should.Equal("", obj.Field1) + should.Nil(UnmarshalFromString(`{"Field1": "a", "Field2": "b", "Field3": "c", "Field4": "d", "Field5": "e", "Field6": "x", "Field7":"y"}`, &obj)) + should.Equal("a", obj.Field1) + should.Equal("b", obj.Field2) + should.Equal("c", obj.Field3) + should.Equal("d", obj.Field4) + should.Equal("e", obj.Field5) + should.Equal("x", obj.Field6) + should.Equal("y", obj.Field7) +} + +func Test_decode_eight_fields_struct(t *testing.T) { + should := require.New(t) + type TestObject struct { + Field1 string + Field2 string + Field3 string + Field4 string + Field5 string + Field6 string + Field7 string + Field8 string + } + obj := TestObject{} + should.Nil(UnmarshalFromString(`{}`, &obj)) + should.Equal("", obj.Field1) + should.Nil(UnmarshalFromString(`{"Field8":"1", "Field1": "a", "Field2": "b", "Field3": "c", "Field4": "d", "Field5": "e", "Field6": "x", "Field7":"y"}`, &obj)) + should.Equal("a", obj.Field1) + should.Equal("b", obj.Field2) + should.Equal("c", obj.Field3) + should.Equal("d", obj.Field4) + should.Equal("e", obj.Field5) + should.Equal("x", obj.Field6) + should.Equal("y", obj.Field7) + should.Equal("1", obj.Field8) +} + +func Test_decode_nine_fields_struct(t *testing.T) { + should := require.New(t) + type TestObject struct { + Field1 string + Field2 string + Field3 string + Field4 string + Field5 string + Field6 string + Field7 string + Field8 string + Field9 string + } + obj := TestObject{} + should.Nil(UnmarshalFromString(`{}`, &obj)) + should.Equal("", obj.Field1) + should.Nil(UnmarshalFromString(`{"Field8" : "zzzzzzzzzzz", "Field7": "zz", "Field6" : "xx", "Field1": "a", "Field2": "b", "Field3": "c", "Field4": "d", "Field5": "e", "Field9":"f"}`, &obj)) + should.Equal("a", obj.Field1) + should.Equal("b", obj.Field2) + should.Equal("c", obj.Field3) + should.Equal("d", obj.Field4) + should.Equal("e", obj.Field5) + should.Equal("xx", obj.Field6) + should.Equal("zz", obj.Field7) + should.Equal("zzzzzzzzzzz", obj.Field8) + should.Equal("f", obj.Field9) +} + func Test_decode_ten_fields_struct(t *testing.T) { should := require.New(t) type TestObject struct { @@ -191,12 +291,44 @@ func Test_decode_ten_fields_struct(t *testing.T) { obj := TestObject{} should.Nil(UnmarshalFromString(`{}`, &obj)) should.Equal("", obj.Field1) - should.Nil(UnmarshalFromString(`{"Field1": "a", "Field2": "b", "Field3": "c", "Field4": "d", "Field5": "e"}`, &obj)) + should.Nil(UnmarshalFromString(`{"Field10":"x", "Field9": "x", "Field8":"x", "Field7":"x", "Field6":"x", "Field1": "a", "Field2": "b", "Field3": "c", "Field4": "d", "Field5": "e"}`, &obj)) should.Equal("a", obj.Field1) should.Equal("b", obj.Field2) should.Equal("c", obj.Field3) should.Equal("d", obj.Field4) should.Equal("e", obj.Field5) + should.Equal("x", obj.Field6) + should.Equal("x", obj.Field7) + should.Equal("x", obj.Field8) + should.Equal("x", obj.Field9) + should.Equal("x", obj.Field10) +} + +func Test_decode_more_than_ten_fields_struct(t *testing.T) { + should := require.New(t) + type TestObject struct { + Field1 string + Field2 string + Field3 string + Field4 string + Field5 string + Field6 string + Field7 string + Field8 string + Field9 string + Field10 string + Field11 int + } + obj := TestObject{} + should.Nil(UnmarshalFromString(`{}`, &obj)) + should.Equal("", obj.Field1) + should.Nil(UnmarshalFromString(`{"Field11":1, "Field1": "a", "Field2": "b", "Field3": "c", "Field4": "d", "Field5": "e"}`, &obj)) + should.Equal("a", obj.Field1) + should.Equal("b", obj.Field2) + should.Equal("c", obj.Field3) + should.Equal("d", obj.Field4) + should.Equal("e", obj.Field5) + should.Equal(1, obj.Field11) } func Test_decode_struct_field_with_tag(t *testing.T) { diff --git a/jsoniter_skip_test.go b/jsoniter_skip_test.go index c789a98..1212f95 100644 --- a/jsoniter_skip_test.go +++ b/jsoniter_skip_test.go @@ -3,8 +3,9 @@ package jsoniter import ( "bytes" "encoding/json" - "github.com/json-iterator/go/require" "testing" + + "github.com/json-iterator/go/require" ) func Test_skip_number(t *testing.T) { @@ -15,6 +16,7 @@ func Test_skip_number(t *testing.T) { if iter.ReadString() != "b" { t.FailNow() } + } func Test_skip_null(t *testing.T) {