|
@@ -152,22 +152,221 @@ func Test_unmarshal_into_existing_value(t *testing.T) {
|
|
|
// for issue421
|
|
// for issue421
|
|
|
func Test_unmarshal_anonymous_struct_invalid(t *testing.T) {
|
|
func Test_unmarshal_anonymous_struct_invalid(t *testing.T) {
|
|
|
should := require.New(t)
|
|
should := require.New(t)
|
|
|
- t1 := struct {
|
|
|
|
|
|
|
+ t0 := struct {
|
|
|
Field1 string
|
|
Field1 string
|
|
|
}{}
|
|
}{}
|
|
|
|
|
|
|
|
cfg := jsoniter.ConfigCompatibleWithStandardLibrary
|
|
cfg := jsoniter.ConfigCompatibleWithStandardLibrary
|
|
|
- err := cfg.UnmarshalFromString(`{"Field1":`, &t1)
|
|
|
|
|
|
|
+ err := cfg.UnmarshalFromString(`{"Field1":`, &t0)
|
|
|
should.NotNil(err)
|
|
should.NotNil(err)
|
|
|
- should.NotContains(err.Error(), reflect.TypeOf(t1).String())
|
|
|
|
|
|
|
+ should.NotContains(err.Error(), reflect.TypeOf(t0).String())
|
|
|
|
|
|
|
|
- type TestObject struct {
|
|
|
|
|
|
|
+ cfgCaseSensitive := jsoniter.Config{
|
|
|
|
|
+ CaseSensitive: true,
|
|
|
|
|
+ }.Froze()
|
|
|
|
|
+
|
|
|
|
|
+ type TestObject1 struct {
|
|
|
Field1 struct {
|
|
Field1 struct {
|
|
|
InnerField1 string
|
|
InnerField1 string
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- t2 := TestObject{}
|
|
|
|
|
- err = cfg.UnmarshalFromString(`{"Field1":{"InnerField1"`, &t2)
|
|
|
|
|
|
|
+ t1 := TestObject1{}
|
|
|
|
|
+ err = cfgCaseSensitive.UnmarshalFromString(`{"Field1":{"InnerField1"`, &t1)
|
|
|
|
|
+ should.NotNil(err)
|
|
|
|
|
+ should.NotContains(err.Error(), reflect.TypeOf(t1.Field1).String())
|
|
|
|
|
+ should.Contains(err.Error(), reflect.TypeOf(t1).String())
|
|
|
|
|
+
|
|
|
|
|
+ type TestObject2 struct {
|
|
|
|
|
+ Field1 int
|
|
|
|
|
+ Field2 struct {
|
|
|
|
|
+ InnerField1 string
|
|
|
|
|
+ InnerField2 string
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ t2 := TestObject2{}
|
|
|
|
|
+ err = cfgCaseSensitive.UnmarshalFromString(`{"Field2":{"InnerField2"`, &t2)
|
|
|
|
|
+ should.NotNil(err)
|
|
|
|
|
+ should.NotContains(err.Error(), reflect.TypeOf(t2.Field2).String())
|
|
|
|
|
+ should.Contains(err.Error(), reflect.TypeOf(t2).String())
|
|
|
|
|
+
|
|
|
|
|
+ type TestObject3 struct {
|
|
|
|
|
+ Field1 int
|
|
|
|
|
+ Field2 int
|
|
|
|
|
+ Field3 struct {
|
|
|
|
|
+ InnerField1 string
|
|
|
|
|
+ InnerField2 string
|
|
|
|
|
+ InnerField3 string
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ t3 := TestObject3{}
|
|
|
|
|
+ err = cfgCaseSensitive.UnmarshalFromString(`{"Field3":{"InnerField3"`, &t3)
|
|
|
|
|
+ should.NotNil(err)
|
|
|
|
|
+ should.NotContains(err.Error(), reflect.TypeOf(t3.Field3).String())
|
|
|
|
|
+ should.Contains(err.Error(), reflect.TypeOf(t3).String())
|
|
|
|
|
+
|
|
|
|
|
+ type TestObject4 struct {
|
|
|
|
|
+ Field1 int
|
|
|
|
|
+ Field2 int
|
|
|
|
|
+ Field3 int
|
|
|
|
|
+ Field4 struct {
|
|
|
|
|
+ InnerField1 string
|
|
|
|
|
+ InnerField2 string
|
|
|
|
|
+ InnerField3 string
|
|
|
|
|
+ InnerField4 string
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ t4 := TestObject4{}
|
|
|
|
|
+ err = cfgCaseSensitive.UnmarshalFromString(`{"Field4":{"InnerField4"`, &t4)
|
|
|
|
|
+ should.NotNil(err)
|
|
|
|
|
+ should.NotContains(err.Error(), reflect.TypeOf(t4.Field4).String())
|
|
|
|
|
+ should.Contains(err.Error(), reflect.TypeOf(t4).String())
|
|
|
|
|
+
|
|
|
|
|
+ type TestObject5 struct {
|
|
|
|
|
+ Field1 int
|
|
|
|
|
+ Field2 int
|
|
|
|
|
+ Field3 int
|
|
|
|
|
+ Field4 int
|
|
|
|
|
+ Field5 struct {
|
|
|
|
|
+ InnerField1 string
|
|
|
|
|
+ InnerField2 string
|
|
|
|
|
+ InnerField3 string
|
|
|
|
|
+ InnerField4 string
|
|
|
|
|
+ InnerField5 string
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ t5 := TestObject5{}
|
|
|
|
|
+ err = cfgCaseSensitive.UnmarshalFromString(`{"Field5":{"InnerField5"`, &t5)
|
|
|
|
|
+ should.NotNil(err)
|
|
|
|
|
+ should.NotContains(err.Error(), reflect.TypeOf(t5.Field5).String())
|
|
|
|
|
+ should.Contains(err.Error(), reflect.TypeOf(t5).String())
|
|
|
|
|
+
|
|
|
|
|
+ type TestObject6 struct {
|
|
|
|
|
+ Field1 int
|
|
|
|
|
+ Field2 int
|
|
|
|
|
+ Field3 int
|
|
|
|
|
+ Field4 int
|
|
|
|
|
+ Field5 int
|
|
|
|
|
+ Field6 struct {
|
|
|
|
|
+ InnerField1 string
|
|
|
|
|
+ InnerField2 string
|
|
|
|
|
+ InnerField3 string
|
|
|
|
|
+ InnerField4 string
|
|
|
|
|
+ InnerField5 string
|
|
|
|
|
+ InnerField6 string
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ t6 := TestObject6{}
|
|
|
|
|
+ err = cfgCaseSensitive.UnmarshalFromString(`{"Field6":{"InnerField6"`, &t6)
|
|
|
|
|
+ should.NotNil(err)
|
|
|
|
|
+ should.NotContains(err.Error(), reflect.TypeOf(t6.Field6).String())
|
|
|
|
|
+ should.Contains(err.Error(), reflect.TypeOf(t6).String())
|
|
|
|
|
+
|
|
|
|
|
+ type TestObject7 struct {
|
|
|
|
|
+ Field1 int
|
|
|
|
|
+ Field2 int
|
|
|
|
|
+ Field3 int
|
|
|
|
|
+ Field4 int
|
|
|
|
|
+ Field5 int
|
|
|
|
|
+ Field6 int
|
|
|
|
|
+ Field7 struct {
|
|
|
|
|
+ InnerField1 string
|
|
|
|
|
+ InnerField2 string
|
|
|
|
|
+ InnerField3 string
|
|
|
|
|
+ InnerField4 string
|
|
|
|
|
+ InnerField5 string
|
|
|
|
|
+ InnerField6 string
|
|
|
|
|
+ InnerField7 string
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ t7 := TestObject7{}
|
|
|
|
|
+ err = cfgCaseSensitive.UnmarshalFromString(`{"Field7":{"InnerField7"`, &t7)
|
|
|
|
|
+ should.NotNil(err)
|
|
|
|
|
+ should.NotContains(err.Error(), reflect.TypeOf(t7.Field7).String())
|
|
|
|
|
+ should.Contains(err.Error(), reflect.TypeOf(t7).String())
|
|
|
|
|
+
|
|
|
|
|
+ type TestObject8 struct {
|
|
|
|
|
+ Field1 int
|
|
|
|
|
+ Field2 int
|
|
|
|
|
+ Field3 int
|
|
|
|
|
+ Field4 int
|
|
|
|
|
+ Field5 int
|
|
|
|
|
+ Field6 int
|
|
|
|
|
+ Field7 int
|
|
|
|
|
+ Field8 struct {
|
|
|
|
|
+ InnerField1 string
|
|
|
|
|
+ InnerField2 string
|
|
|
|
|
+ InnerField3 string
|
|
|
|
|
+ InnerField4 string
|
|
|
|
|
+ InnerField5 string
|
|
|
|
|
+ InnerField6 string
|
|
|
|
|
+ InnerField7 string
|
|
|
|
|
+ InnerField8 string
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ t8 := TestObject8{}
|
|
|
|
|
+ err = cfgCaseSensitive.UnmarshalFromString(`{"Field8":{"InnerField8"`, &t8)
|
|
|
|
|
+ should.NotNil(err)
|
|
|
|
|
+ should.NotContains(err.Error(), reflect.TypeOf(t8.Field8).String())
|
|
|
|
|
+ should.Contains(err.Error(), reflect.TypeOf(t8).String())
|
|
|
|
|
+
|
|
|
|
|
+ type TestObject9 struct {
|
|
|
|
|
+ Field1 int
|
|
|
|
|
+ Field2 int
|
|
|
|
|
+ Field3 int
|
|
|
|
|
+ Field4 int
|
|
|
|
|
+ Field5 int
|
|
|
|
|
+ Field6 int
|
|
|
|
|
+ Field7 int
|
|
|
|
|
+ Field8 int
|
|
|
|
|
+ Field9 struct {
|
|
|
|
|
+ InnerField1 string
|
|
|
|
|
+ InnerField2 string
|
|
|
|
|
+ InnerField3 string
|
|
|
|
|
+ InnerField4 string
|
|
|
|
|
+ InnerField5 string
|
|
|
|
|
+ InnerField6 string
|
|
|
|
|
+ InnerField7 string
|
|
|
|
|
+ InnerField8 string
|
|
|
|
|
+ InnerField9 string
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ t9 := TestObject9{}
|
|
|
|
|
+ err = cfgCaseSensitive.UnmarshalFromString(`{"Field9":{"InnerField9"`, &t9)
|
|
|
|
|
+ should.NotNil(err)
|
|
|
|
|
+ should.NotContains(err.Error(), reflect.TypeOf(t9.Field9).String())
|
|
|
|
|
+ should.Contains(err.Error(), reflect.TypeOf(t9).String())
|
|
|
|
|
+
|
|
|
|
|
+ type TestObject10 struct {
|
|
|
|
|
+ Field1 int
|
|
|
|
|
+ Field2 int
|
|
|
|
|
+ Field3 int
|
|
|
|
|
+ Field4 int
|
|
|
|
|
+ Field5 int
|
|
|
|
|
+ Field6 int
|
|
|
|
|
+ Field7 int
|
|
|
|
|
+ Field8 int
|
|
|
|
|
+ Field9 int
|
|
|
|
|
+ Field10 struct {
|
|
|
|
|
+ InnerField1 string
|
|
|
|
|
+ InnerField2 string
|
|
|
|
|
+ InnerField3 string
|
|
|
|
|
+ InnerField4 string
|
|
|
|
|
+ InnerField5 string
|
|
|
|
|
+ InnerField6 string
|
|
|
|
|
+ InnerField7 string
|
|
|
|
|
+ InnerField8 string
|
|
|
|
|
+ InnerField9 string
|
|
|
|
|
+ InnerField10 string
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ t10 := TestObject10{}
|
|
|
|
|
+ err = cfgCaseSensitive.UnmarshalFromString(`{"Field10":{"InnerField10"`, &t10)
|
|
|
|
|
+ should.NotNil(err)
|
|
|
|
|
+ should.NotContains(err.Error(), reflect.TypeOf(t10.Field10).String())
|
|
|
|
|
+ should.Contains(err.Error(), reflect.TypeOf(t10).String())
|
|
|
|
|
+
|
|
|
|
|
+ err = cfg.UnmarshalFromString(`{"Field10":{"InnerField10"`, &t10)
|
|
|
should.NotNil(err)
|
|
should.NotNil(err)
|
|
|
- should.NotContains(err.Error(), reflect.TypeOf(t2.Field1).String())
|
|
|
|
|
|
|
+ should.NotContains(err.Error(), reflect.TypeOf(t10.Field10).String())
|
|
|
|
|
+ should.Contains(err.Error(), reflect.TypeOf(t10).String())
|
|
|
}
|
|
}
|