Merge pull request #216 from goccy/feature/support-omitempty-and-string

Supports using omitempty and string tags at the same time
This commit is contained in:
Masaaki Goshima 2021-05-09 01:12:28 +09:00 committed by GitHub
commit 7d6401a797
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 9496 additions and 2966 deletions

View File

@ -26,6 +26,9 @@ func TestCoverBool(t *testing.T) {
type structBoolString struct {
A bool `json:"a,string"`
}
type structBoolStringOmitEmpty struct {
A bool `json:"a,string,omitempty"`
}
type structBoolPtr struct {
A *bool `json:"a"`
@ -36,6 +39,9 @@ func TestCoverBool(t *testing.T) {
type structBoolPtrString struct {
A *bool `json:"a,string"`
}
type structBoolPtrStringOmitEmpty struct {
A *bool `json:"a,string,omitempty"`
}
type structCustomBoolOmitEmpty struct {
A customBool `json:"a,omitempty"`
@ -99,6 +105,12 @@ func TestCoverBool(t *testing.T) {
A bool `json:"a,string"`
}{},
},
{
name: "HeadBoolZeroStringOmitEmpty",
data: struct {
A bool `json:"a,string,omitempty"`
}{},
},
// HeadBool
{
@ -119,6 +131,12 @@ func TestCoverBool(t *testing.T) {
A bool `json:"a,string"`
}{A: true},
},
{
name: "HeadBoolStringOmitEmpty",
data: struct {
A bool `json:"a,string,omitempty"`
}{A: true},
},
// HeadBoolPtr
{
@ -139,6 +157,12 @@ func TestCoverBool(t *testing.T) {
A *bool `json:"a,string"`
}{A: boolptr(true)},
},
{
name: "HeadBoolPtrStringOmitEmpty",
data: struct {
A *bool `json:"a,string,omitempty"`
}{A: boolptr(true)},
},
// HeadBoolPtrNil
{
@ -159,6 +183,12 @@ func TestCoverBool(t *testing.T) {
A *bool `json:"a,string"`
}{A: nil},
},
{
name: "HeadBoolPtrNilStringOmitEmpty",
data: struct {
A *bool `json:"a,string,omitempty"`
}{A: nil},
},
// PtrHeadBoolZero
{
@ -179,6 +209,12 @@ func TestCoverBool(t *testing.T) {
A bool `json:"a,string"`
}{},
},
{
name: "PtrHeadBoolZeroStringOmitEmpty",
data: &struct {
A bool `json:"a,string,omitempty"`
}{},
},
// PtrHeadBool
{
@ -199,6 +235,12 @@ func TestCoverBool(t *testing.T) {
A bool `json:"a,string"`
}{A: true},
},
{
name: "PtrHeadBoolStringOmitEmpty",
data: &struct {
A bool `json:"a,string,omitempty"`
}{A: true},
},
// PtrHeadBoolPtr
{
@ -219,6 +261,12 @@ func TestCoverBool(t *testing.T) {
A *bool `json:"a,string"`
}{A: boolptr(true)},
},
{
name: "PtrHeadBoolPtrStringOmitEmpty",
data: &struct {
A *bool `json:"a,string,omitempty"`
}{A: boolptr(true)},
},
// PtrHeadBoolPtrNil
{
@ -239,6 +287,12 @@ func TestCoverBool(t *testing.T) {
A *bool `json:"a,string"`
}{A: nil},
},
{
name: "PtrHeadBoolPtrNilStringOmitEmpty",
data: &struct {
A *bool `json:"a,string,omitempty"`
}{A: nil},
},
// PtrHeadBoolNil
{
@ -259,6 +313,12 @@ func TestCoverBool(t *testing.T) {
A *bool `json:"a,string"`
})(nil),
},
{
name: "PtrHeadBoolNilStringOmitEmpty",
data: (*struct {
A *bool `json:"a,string,omitempty"`
})(nil),
},
// HeadBoolZeroMultiFields
{
@ -278,13 +338,21 @@ func TestCoverBool(t *testing.T) {
}{},
},
{
name: "HeadBoolZeroMultiFields",
name: "HeadBoolZeroMultiFieldsString",
data: struct {
A bool `json:"a,string"`
B bool `json:"b,string"`
C bool `json:"c,string"`
}{},
},
{
name: "HeadBoolZeroMultiFieldsStringOmitEmpty",
data: struct {
A bool `json:"a,string,omitempty"`
B bool `json:"b,string,omitempty"`
C bool `json:"c,string,omitempty"`
}{},
},
// HeadBoolMultiFields
{
@ -311,6 +379,14 @@ func TestCoverBool(t *testing.T) {
C bool `json:"c,string"`
}{A: true, B: false, C: true},
},
{
name: "HeadBoolMultiFieldsStringOmitEmpty",
data: struct {
A bool `json:"a,string,omitempty"`
B bool `json:"b,string,omitempty"`
C bool `json:"c,string,omitempty"`
}{A: true, B: false, C: true},
},
// HeadBoolPtrMultiFields
{
@ -337,6 +413,14 @@ func TestCoverBool(t *testing.T) {
C *bool `json:"c,string"`
}{A: boolptr(true), B: boolptr(false), C: boolptr(true)},
},
{
name: "HeadBoolPtrMultiFieldsStringOmitEmpty",
data: struct {
A *bool `json:"a,string,omitempty"`
B *bool `json:"b,string,omitempty"`
C *bool `json:"c,string,omitempty"`
}{A: boolptr(true), B: boolptr(false), C: boolptr(true)},
},
// HeadBoolPtrNilMultiFields
{
@ -363,6 +447,14 @@ func TestCoverBool(t *testing.T) {
C *bool `json:"c,string"`
}{A: nil, B: nil, C: nil},
},
{
name: "HeadBoolPtrNilMultiFieldsStringOmitEmpty",
data: struct {
A *bool `json:"a,string,omitempty"`
B *bool `json:"b,string,omitempty"`
C *bool `json:"c,string,omitempty"`
}{A: nil, B: nil, C: nil},
},
// PtrHeadBoolZeroMultiFields
{
@ -386,6 +478,13 @@ func TestCoverBool(t *testing.T) {
B bool `json:"b,string"`
}{},
},
{
name: "PtrHeadBoolZeroMultiFieldsStringOmitEmpty",
data: &struct {
A bool `json:"a,string,omitempty"`
B bool `json:"b,string,omitempty"`
}{},
},
// PtrHeadBoolMultiFields
{
@ -409,6 +508,13 @@ func TestCoverBool(t *testing.T) {
B bool `json:"b,string"`
}{A: true, B: false},
},
{
name: "PtrHeadBoolMultiFieldsStringOmitEmpty",
data: &struct {
A bool `json:"a,string,omitempty"`
B bool `json:"b,string,omitempty"`
}{A: true, B: false},
},
// PtrHeadBoolPtrMultiFields
{
@ -432,6 +538,13 @@ func TestCoverBool(t *testing.T) {
B *bool `json:"b,string"`
}{A: boolptr(true), B: boolptr(false)},
},
{
name: "PtrHeadBoolPtrMultiFieldsStringOmitEmpty",
data: &struct {
A *bool `json:"a,string,omitempty"`
B *bool `json:"b,string,omitempty"`
}{A: boolptr(true), B: boolptr(false)},
},
// PtrHeadBoolPtrNilMultiFields
{
@ -455,6 +568,13 @@ func TestCoverBool(t *testing.T) {
B *bool `json:"b,string"`
}{A: nil, B: nil},
},
{
name: "PtrHeadBoolPtrNilMultiFieldsStringOmitEmpty",
data: &struct {
A *bool `json:"a,string,omitempty"`
B *bool `json:"b,string,omitempty"`
}{A: nil, B: nil},
},
// PtrHeadBoolNilMultiFields
{
@ -478,6 +598,13 @@ func TestCoverBool(t *testing.T) {
B *bool `json:"b,string"`
})(nil),
},
{
name: "PtrHeadBoolNilMultiFieldsStringOmitEmpty",
data: (*struct {
A *bool `json:"a,string,omitempty"`
B *bool `json:"b,string,omitempty"`
})(nil),
},
// HeadBoolZeroNotRoot
{
@ -504,6 +631,14 @@ func TestCoverBool(t *testing.T) {
}
}{},
},
{
name: "HeadBoolZeroNotRootStringOmitEmpty",
data: struct {
A struct {
A bool `json:"a,string,omitempty"`
}
}{},
},
// HeadBoolNotRoot
{
@ -536,6 +671,16 @@ func TestCoverBool(t *testing.T) {
A bool `json:"a,string"`
}{A: true}},
},
{
name: "HeadBoolNotRootStringOmitEmpty",
data: struct {
A struct {
A bool `json:"a,string,omitempty"`
}
}{A: struct {
A bool `json:"a,string,omitempty"`
}{A: true}},
},
// HeadBoolPtrNotRoot
{
@ -568,6 +713,16 @@ func TestCoverBool(t *testing.T) {
A *bool `json:"a,string"`
}{boolptr(true)}},
},
{
name: "HeadBoolPtrNotRootStringOmitEmpty",
data: struct {
A struct {
A *bool `json:"a,string,omitempty"`
}
}{A: struct {
A *bool `json:"a,string,omitempty"`
}{boolptr(true)}},
},
// HeadBoolPtrNilNotRoot
{
@ -594,6 +749,14 @@ func TestCoverBool(t *testing.T) {
}
}{},
},
{
name: "HeadBoolPtrNilNotRootStringOmitEmpty",
data: struct {
A struct {
A *bool `json:"a,string,omitempty"`
}
}{},
},
// PtrHeadBoolZeroNotRoot
{
@ -626,6 +789,16 @@ func TestCoverBool(t *testing.T) {
A bool `json:"a,string"`
})},
},
{
name: "PtrHeadBoolZeroNotRootStringOmitEmpty",
data: struct {
A *struct {
A bool `json:"a,string,omitempty"`
}
}{A: new(struct {
A bool `json:"a,string,omitempty"`
})},
},
// PtrHeadBoolNotRoot
{
@ -658,6 +831,16 @@ func TestCoverBool(t *testing.T) {
A bool `json:"a,string"`
}{A: true})},
},
{
name: "PtrHeadBoolNotRootStringOmitEmpty",
data: struct {
A *struct {
A bool `json:"a,string,omitempty"`
}
}{A: &(struct {
A bool `json:"a,string,omitempty"`
}{A: true})},
},
// PtrHeadBoolPtrNotRoot
{
@ -690,6 +873,16 @@ func TestCoverBool(t *testing.T) {
A *bool `json:"a,string"`
}{A: boolptr(true)})},
},
{
name: "PtrHeadBoolPtrNotRootStringOmitEmpty",
data: struct {
A *struct {
A *bool `json:"a,string,omitempty"`
}
}{A: &(struct {
A *bool `json:"a,string,omitempty"`
}{A: boolptr(true)})},
},
// PtrHeadBoolPtrNilNotRoot
{
@ -722,6 +915,16 @@ func TestCoverBool(t *testing.T) {
A *bool `json:"a,string"`
}{A: nil})},
},
{
name: "PtrHeadBoolPtrNilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *bool `json:"a,string,omitempty"`
}
}{A: &(struct {
A *bool `json:"a,string,omitempty"`
}{A: nil})},
},
// PtrHeadBoolNilNotRoot
{
@ -748,6 +951,14 @@ func TestCoverBool(t *testing.T) {
} `json:",string"`
}{A: nil},
},
{
name: "PtrHeadBoolNilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *bool `json:"a,string,omitempty"`
} `json:",string,omitempty"`
}{A: nil},
},
// HeadBoolZeroMultiFieldsNotRoot
{
@ -783,6 +994,17 @@ func TestCoverBool(t *testing.T) {
}
}{},
},
{
name: "HeadBoolZeroMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A bool `json:"a,string,omitempty"`
}
B struct {
B bool `json:"b,string,omitempty"`
}
}{},
},
// HeadBoolMultiFieldsNotRoot
{
@ -830,6 +1052,21 @@ func TestCoverBool(t *testing.T) {
B bool `json:"b,string"`
}{B: false}},
},
{
name: "HeadBoolMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A bool `json:"a,string,omitempty"`
}
B struct {
B bool `json:"b,string,omitempty"`
}
}{A: struct {
A bool `json:"a,string,omitempty"`
}{A: true}, B: struct {
B bool `json:"b,string,omitempty"`
}{B: false}},
},
// HeadBoolPtrMultiFieldsNotRoot
{
@ -877,6 +1114,21 @@ func TestCoverBool(t *testing.T) {
B *bool `json:"b,string"`
}{B: boolptr(false)}},
},
{
name: "HeadBoolPtrMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *bool `json:"a,string,omitempty"`
}
B struct {
B *bool `json:"b,string,omitempty"`
}
}{A: struct {
A *bool `json:"a,string,omitempty"`
}{A: boolptr(true)}, B: struct {
B *bool `json:"b,string,omitempty"`
}{B: boolptr(false)}},
},
// HeadBoolPtrNilMultiFieldsNotRoot
{
@ -924,6 +1176,21 @@ func TestCoverBool(t *testing.T) {
B *bool `json:"b,string"`
}{B: nil}},
},
{
name: "HeadBoolPtrNilMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *bool `json:"a,string,omitempty"`
}
B struct {
B *bool `json:"b,string,omitempty"`
}
}{A: struct {
A *bool `json:"a,string,omitempty"`
}{A: nil}, B: struct {
B *bool `json:"b,string,omitempty"`
}{B: nil}},
},
// PtrHeadBoolZeroMultiFieldsNotRoot
{
@ -959,6 +1226,17 @@ func TestCoverBool(t *testing.T) {
}
}{},
},
{
name: "PtrHeadBoolZeroMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A bool `json:"a,string,omitempty"`
}
B struct {
B bool `json:"b,string,omitempty"`
}
}{},
},
// PtrHeadBoolMultiFieldsNotRoot
{
@ -1006,6 +1284,21 @@ func TestCoverBool(t *testing.T) {
B bool `json:"b,string"`
}{B: false}},
},
{
name: "PtrHeadBoolMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A bool `json:"a,string,omitempty"`
}
B struct {
B bool `json:"b,string,omitempty"`
}
}{A: struct {
A bool `json:"a,string,omitempty"`
}{A: true}, B: struct {
B bool `json:"b,string,omitempty"`
}{B: false}},
},
// PtrHeadBoolPtrMultiFieldsNotRoot
{
@ -1053,6 +1346,21 @@ func TestCoverBool(t *testing.T) {
B *bool `json:"b,string"`
}{B: boolptr(false)})},
},
{
name: "PtrHeadBoolPtrMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *bool `json:"a,string,omitempty"`
}
B *struct {
B *bool `json:"b,string,omitempty"`
}
}{A: &(struct {
A *bool `json:"a,string,omitempty"`
}{A: boolptr(true)}), B: &(struct {
B *bool `json:"b,string,omitempty"`
}{B: boolptr(false)})},
},
// PtrHeadBoolPtrNilMultiFieldsNotRoot
{
@ -1088,6 +1396,17 @@ func TestCoverBool(t *testing.T) {
} `json:",string"`
}{A: nil, B: nil},
},
{
name: "PtrHeadBoolPtrNilMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *bool `json:"a,string,omitempty"`
} `json:",string"`
B *struct {
B *bool `json:"b,string,omitempty"`
} `json:",string"`
}{A: nil, B: nil},
},
// PtrHeadBoolNilMultiFieldsNotRoot
{
@ -1123,6 +1442,17 @@ func TestCoverBool(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadBoolNilMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *bool `json:"a,string,omitempty"`
}
B *struct {
B *bool `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadBoolDoubleMultiFieldsNotRoot
{
@ -1182,6 +1512,25 @@ func TestCoverBool(t *testing.T) {
B bool `json:"b,string"`
}{A: true, B: false})},
},
{
name: "PtrHeadBoolDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A bool `json:"a,string,omitempty"`
B bool `json:"b,string,omitempty"`
}
B *struct {
A bool `json:"a,string,omitempty"`
B bool `json:"b,string,omitempty"`
}
}{A: &(struct {
A bool `json:"a,string,omitempty"`
B bool `json:"b,string,omitempty"`
}{A: true, B: false}), B: &(struct {
A bool `json:"a,string,omitempty"`
B bool `json:"b,string,omitempty"`
}{A: true, B: false})},
},
// PtrHeadBoolNilDoubleMultiFieldsNotRoot
{
@ -1223,6 +1572,19 @@ func TestCoverBool(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadBoolNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A bool `json:"a,string,omitempty"`
B bool `json:"b,string,omitempty"`
}
B *struct {
A bool `json:"a,string,omitempty"`
B bool `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadBoolNilDoubleMultiFieldsNotRoot
{
@ -1264,6 +1626,19 @@ func TestCoverBool(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadBoolNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A bool `json:"a,string,omitempty"`
B bool `json:"b,string,omitempty"`
}
B *struct {
A bool `json:"a,string,omitempty"`
B bool `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadBoolPtrDoubleMultiFieldsNotRoot
{
@ -1323,6 +1698,25 @@ func TestCoverBool(t *testing.T) {
B *bool `json:"b,string"`
}{A: boolptr(true), B: boolptr(false)})},
},
{
name: "PtrHeadBoolPtrDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *bool `json:"a,string,omitempty"`
B *bool `json:"b,string,omitempty"`
}
B *struct {
A *bool `json:"a,string,omitempty"`
B *bool `json:"b,string,omitempty"`
}
}{A: &(struct {
A *bool `json:"a,string,omitempty"`
B *bool `json:"b,string,omitempty"`
}{A: boolptr(true), B: boolptr(false)}), B: &(struct {
A *bool `json:"a,string,omitempty"`
B *bool `json:"b,string,omitempty"`
}{A: boolptr(true), B: boolptr(false)})},
},
// PtrHeadBoolPtrNilDoubleMultiFieldsNotRoot
{
@ -1364,6 +1758,19 @@ func TestCoverBool(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadBoolPtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *bool `json:"a,string,omitempty"`
B *bool `json:"b,string,omitempty"`
}
B *struct {
A *bool `json:"a,string,omitempty"`
B *bool `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadBoolPtrNilDoubleMultiFieldsNotRoot
{
@ -1405,6 +1812,19 @@ func TestCoverBool(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadBoolPtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *bool `json:"a,string,omitempty"`
B *bool `json:"b,string,omitempty"`
}
B *struct {
A *bool `json:"a,string,omitempty"`
B *bool `json:"b,string,omitempty"`
}
})(nil),
},
// AnonymousHeadBool
{
@ -1517,6 +1937,16 @@ func TestCoverBool(t *testing.T) {
B: false,
},
},
{
name: "AnonymousHeadBoolStringOmitEmpty",
data: struct {
structBoolStringOmitEmpty
B bool `json:"b,string,omitempty"`
}{
structBoolStringOmitEmpty: structBoolStringOmitEmpty{A: true},
B: false,
},
},
// PtrAnonymousHeadBool
{
@ -1629,6 +2059,16 @@ func TestCoverBool(t *testing.T) {
B: false,
},
},
{
name: "PtrAnonymousHeadBoolStringOmitEmpty",
data: struct {
*structBoolStringOmitEmpty
B bool `json:"b,string,omitempty"`
}{
structBoolStringOmitEmpty: &structBoolStringOmitEmpty{A: true},
B: false,
},
},
// NilPtrAnonymousHeadBool
{
@ -1681,6 +2121,16 @@ func TestCoverBool(t *testing.T) {
B: true,
},
},
{
name: "NilPtrAnonymousHeadBoolStringOmitEmpty",
data: struct {
*structBoolStringOmitEmpty
B bool `json:"b,string,omitempty"`
}{
structBoolStringOmitEmpty: nil,
B: true,
},
},
// AnonymousHeadBoolPtr
{
@ -1713,6 +2163,16 @@ func TestCoverBool(t *testing.T) {
B: boolptr(false),
},
},
{
name: "AnonymousHeadBoolPtrStringOmitEmpty",
data: struct {
structBoolPtrStringOmitEmpty
B *bool `json:"b,string,omitempty"`
}{
structBoolPtrStringOmitEmpty: structBoolPtrStringOmitEmpty{A: boolptr(true)},
B: boolptr(false),
},
},
// AnonymousHeadBoolPtrNil
{
@ -1745,6 +2205,16 @@ func TestCoverBool(t *testing.T) {
B: boolptr(true),
},
},
{
name: "AnonymousHeadBoolPtrNilStringOmitEmpty",
data: struct {
structBoolPtrStringOmitEmpty
B *bool `json:"b,string,omitempty"`
}{
structBoolPtrStringOmitEmpty: structBoolPtrStringOmitEmpty{A: nil},
B: boolptr(true),
},
},
// PtrAnonymousHeadBoolPtr
{
@ -1777,6 +2247,16 @@ func TestCoverBool(t *testing.T) {
B: boolptr(false),
},
},
{
name: "PtrAnonymousHeadBoolPtrStringOmitEmpty",
data: struct {
*structBoolPtrStringOmitEmpty
B *bool `json:"b,string,omitempty"`
}{
structBoolPtrStringOmitEmpty: &structBoolPtrStringOmitEmpty{A: boolptr(true)},
B: boolptr(false),
},
},
// NilPtrAnonymousHeadBoolPtr
{
@ -1809,6 +2289,16 @@ func TestCoverBool(t *testing.T) {
B: boolptr(true),
},
},
{
name: "NilPtrAnonymousHeadBoolPtrStringOmitEmpty",
data: struct {
*structBoolPtrStringOmitEmpty
B *bool `json:"b,string,omitempty"`
}{
structBoolPtrStringOmitEmpty: nil,
B: boolptr(true),
},
},
// AnonymousHeadBoolOnly
{
@ -1883,6 +2373,14 @@ func TestCoverBool(t *testing.T) {
structBoolString: structBoolString{A: true},
},
},
{
name: "AnonymousHeadBoolOnlyStringOmitEmpty",
data: struct {
structBoolStringOmitEmpty
}{
structBoolStringOmitEmpty: structBoolStringOmitEmpty{A: true},
},
},
// PtrAnonymousHeadBoolOnly
{
@ -1957,6 +2455,14 @@ func TestCoverBool(t *testing.T) {
structBoolString: &structBoolString{A: true},
},
},
{
name: "PtrAnonymousHeadBoolOnlyStringOmitEmpty",
data: struct {
*structBoolStringOmitEmpty
}{
structBoolStringOmitEmpty: &structBoolStringOmitEmpty{A: true},
},
},
// NilPtrAnonymousHeadBoolOnly
{
@ -1999,6 +2505,14 @@ func TestCoverBool(t *testing.T) {
structBoolString: nil,
},
},
{
name: "NilPtrAnonymousHeadBoolOnlyStringOmitEmpty",
data: struct {
*structBoolStringOmitEmpty
}{
structBoolStringOmitEmpty: nil,
},
},
// AnonymousHeadBoolPtrOnly
{
@ -2025,6 +2539,14 @@ func TestCoverBool(t *testing.T) {
structBoolPtrString: structBoolPtrString{A: boolptr(true)},
},
},
{
name: "AnonymousHeadBoolPtrOnlyStringOmitEmpty",
data: struct {
structBoolPtrStringOmitEmpty
}{
structBoolPtrStringOmitEmpty: structBoolPtrStringOmitEmpty{A: boolptr(true)},
},
},
// AnonymousHeadBoolPtrNilOnly
{
@ -2051,6 +2573,14 @@ func TestCoverBool(t *testing.T) {
structBoolPtrString: structBoolPtrString{A: nil},
},
},
{
name: "AnonymousHeadBoolPtrNilOnlyStringOmitEmpty",
data: struct {
structBoolPtrStringOmitEmpty
}{
structBoolPtrStringOmitEmpty: structBoolPtrStringOmitEmpty{A: nil},
},
},
// PtrAnonymousHeadBoolPtrOnly
{
@ -2077,6 +2607,14 @@ func TestCoverBool(t *testing.T) {
structBoolPtrString: &structBoolPtrString{A: boolptr(true)},
},
},
{
name: "PtrAnonymousHeadBoolPtrOnlyStringOmitEmpty",
data: struct {
*structBoolPtrStringOmitEmpty
}{
structBoolPtrStringOmitEmpty: &structBoolPtrStringOmitEmpty{A: boolptr(true)},
},
},
// NilPtrAnonymousHeadBoolPtrOnly
{
@ -2103,6 +2641,14 @@ func TestCoverBool(t *testing.T) {
structBoolPtrString: nil,
},
},
{
name: "NilPtrAnonymousHeadBoolPtrOnlyStringOmitEmpty",
data: struct {
*structBoolPtrStringOmitEmpty
}{
structBoolPtrStringOmitEmpty: nil,
},
},
}
for _, test := range tests {
for _, indent := range []bool{true, false} {

View File

@ -17,6 +17,9 @@ func TestCoverFloat32(t *testing.T) {
type structFloat32String struct {
A float32 `json:"a,string"`
}
type structFloat32StringOmitEmpty struct {
A float32 `json:"a,string,omitempty"`
}
type structFloat32Ptr struct {
A *float32 `json:"a"`
@ -27,6 +30,9 @@ func TestCoverFloat32(t *testing.T) {
type structFloat32PtrString struct {
A *float32 `json:"a,string"`
}
type structFloat32PtrStringOmitEmpty struct {
A *float32 `json:"a,string,omitempty"`
}
tests := []struct {
name string
@ -72,6 +78,12 @@ func TestCoverFloat32(t *testing.T) {
A float32 `json:"a,string"`
}{},
},
{
name: "HeadFloat32ZeroStringOmitEmpty",
data: struct {
A float32 `json:"a,string,omitempty"`
}{},
},
// HeadFloat32
{
@ -92,6 +104,12 @@ func TestCoverFloat32(t *testing.T) {
A float32 `json:"a,string"`
}{A: 1},
},
{
name: "HeadFloat32StringOmitEmpty",
data: struct {
A float32 `json:"a,string,omitempty"`
}{A: 1},
},
// HeadFloat32Ptr
{
@ -112,6 +130,12 @@ func TestCoverFloat32(t *testing.T) {
A *float32 `json:"a,string"`
}{A: float32ptr(1)},
},
{
name: "HeadFloat32PtrStringOmitEmpty",
data: struct {
A *float32 `json:"a,string,omitempty"`
}{A: float32ptr(1)},
},
// HeadFloat32PtrNil
{
@ -132,6 +156,12 @@ func TestCoverFloat32(t *testing.T) {
A *float32 `json:"a,string"`
}{A: nil},
},
{
name: "HeadFloat32PtrNilStringOmitEmpty",
data: struct {
A *float32 `json:"a,string,omitempty"`
}{A: nil},
},
// PtrHeadFloat32Zero
{
@ -152,6 +182,12 @@ func TestCoverFloat32(t *testing.T) {
A float32 `json:"a,string"`
}{},
},
{
name: "PtrHeadFloat32ZeroStringOmitEmpty",
data: &struct {
A float32 `json:"a,string,omitempty"`
}{},
},
// PtrHeadFloat32
{
@ -172,6 +208,12 @@ func TestCoverFloat32(t *testing.T) {
A float32 `json:"a,string"`
}{A: 1},
},
{
name: "PtrHeadFloat32StringOmitEmpty",
data: &struct {
A float32 `json:"a,string,omitempty"`
}{A: 1},
},
// PtrHeadFloat32Ptr
{
@ -192,6 +234,12 @@ func TestCoverFloat32(t *testing.T) {
A *float32 `json:"a,string"`
}{A: float32ptr(1)},
},
{
name: "PtrHeadFloat32PtrStringOmitEmpty",
data: &struct {
A *float32 `json:"a,string,omitempty"`
}{A: float32ptr(1)},
},
// PtrHeadFloat32PtrNil
{
@ -212,6 +260,12 @@ func TestCoverFloat32(t *testing.T) {
A *float32 `json:"a,string"`
}{A: nil},
},
{
name: "PtrHeadFloat32PtrNilStringOmitEmpty",
data: &struct {
A *float32 `json:"a,string,omitempty"`
}{A: nil},
},
// PtrHeadFloat32Nil
{
@ -232,6 +286,12 @@ func TestCoverFloat32(t *testing.T) {
A *float32 `json:"a,string"`
})(nil),
},
{
name: "PtrHeadFloat32NilStringOmitEmpty",
data: (*struct {
A *float32 `json:"a,string,omitempty"`
})(nil),
},
// HeadFloat32ZeroMultiFields
{
@ -251,13 +311,21 @@ func TestCoverFloat32(t *testing.T) {
}{},
},
{
name: "HeadFloat32ZeroMultiFields",
name: "HeadFloat32ZeroMultiFieldsString",
data: struct {
A float32 `json:"a,string"`
B float32 `json:"b,string"`
C float32 `json:"c,string"`
}{},
},
{
name: "HeadFloat32ZeroMultiFieldsStringOmitEmpty",
data: struct {
A float32 `json:"a,string,omitempty"`
B float32 `json:"b,string,omitempty"`
C float32 `json:"c,string,omitempty"`
}{},
},
// HeadFloat32MultiFields
{
@ -284,6 +352,14 @@ func TestCoverFloat32(t *testing.T) {
C float32 `json:"c,string"`
}{A: 1, B: 2, C: 3},
},
{
name: "HeadFloat32MultiFieldsStringOmitEmpty",
data: struct {
A float32 `json:"a,string,omitempty"`
B float32 `json:"b,string,omitempty"`
C float32 `json:"c,string,omitempty"`
}{A: 1, B: 2, C: 3},
},
// HeadFloat32PtrMultiFields
{
@ -310,6 +386,14 @@ func TestCoverFloat32(t *testing.T) {
C *float32 `json:"c,string"`
}{A: float32ptr(1), B: float32ptr(2), C: float32ptr(3)},
},
{
name: "HeadFloat32PtrMultiFieldsStringOmitEmpty",
data: struct {
A *float32 `json:"a,string,omitempty"`
B *float32 `json:"b,string,omitempty"`
C *float32 `json:"c,string,omitempty"`
}{A: float32ptr(1), B: float32ptr(2), C: float32ptr(3)},
},
// HeadFloat32PtrNilMultiFields
{
@ -336,6 +420,14 @@ func TestCoverFloat32(t *testing.T) {
C *float32 `json:"c,string"`
}{A: nil, B: nil, C: nil},
},
{
name: "HeadFloat32PtrNilMultiFieldsStringOmitEmpty",
data: struct {
A *float32 `json:"a,string,omitempty"`
B *float32 `json:"b,string,omitempty"`
C *float32 `json:"c,string,omitempty"`
}{A: nil, B: nil, C: nil},
},
// PtrHeadFloat32ZeroMultiFields
{
@ -359,6 +451,13 @@ func TestCoverFloat32(t *testing.T) {
B float32 `json:"b,string"`
}{},
},
{
name: "PtrHeadFloat32ZeroMultiFieldsStringOmitEmpty",
data: &struct {
A float32 `json:"a,string,omitempty"`
B float32 `json:"b,string,omitempty"`
}{},
},
// PtrHeadFloat32MultiFields
{
@ -382,6 +481,13 @@ func TestCoverFloat32(t *testing.T) {
B float32 `json:"b,string"`
}{A: 1, B: 2},
},
{
name: "PtrHeadFloat32MultiFieldsStringOmitEmpty",
data: &struct {
A float32 `json:"a,string,omitempty"`
B float32 `json:"b,string,omitempty"`
}{A: 1, B: 2},
},
// PtrHeadFloat32PtrMultiFields
{
@ -405,6 +511,13 @@ func TestCoverFloat32(t *testing.T) {
B *float32 `json:"b,string"`
}{A: float32ptr(1), B: float32ptr(2)},
},
{
name: "PtrHeadFloat32PtrMultiFieldsStringOmitEmpty",
data: &struct {
A *float32 `json:"a,string,omitempty"`
B *float32 `json:"b,string,omitempty"`
}{A: float32ptr(1), B: float32ptr(2)},
},
// PtrHeadFloat32PtrNilMultiFields
{
@ -428,6 +541,13 @@ func TestCoverFloat32(t *testing.T) {
B *float32 `json:"b,string"`
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat32PtrNilMultiFieldsStringOmitEmpty",
data: &struct {
A *float32 `json:"a,string,omitempty"`
B *float32 `json:"b,string,omitempty"`
}{A: nil, B: nil},
},
// PtrHeadFloat32NilMultiFields
{
@ -451,6 +571,13 @@ func TestCoverFloat32(t *testing.T) {
B *float32 `json:"b,string"`
})(nil),
},
{
name: "PtrHeadFloat32NilMultiFieldsStringOmitEmpty",
data: (*struct {
A *float32 `json:"a,string,omitempty"`
B *float32 `json:"b,string,omitempty"`
})(nil),
},
// HeadFloat32ZeroNotRoot
{
@ -477,6 +604,14 @@ func TestCoverFloat32(t *testing.T) {
}
}{},
},
{
name: "HeadFloat32ZeroNotRootStringOmitEmpty",
data: struct {
A struct {
A float32 `json:"a,string,omitempty"`
}
}{},
},
// HeadFloat32NotRoot
{
@ -509,6 +644,16 @@ func TestCoverFloat32(t *testing.T) {
A float32 `json:"a,string"`
}{A: 1}},
},
{
name: "HeadFloat32NotRootStringOmitEmpty",
data: struct {
A struct {
A float32 `json:"a,string,omitempty"`
}
}{A: struct {
A float32 `json:"a,string,omitempty"`
}{A: 1}},
},
// HeadFloat32PtrNotRoot
{
@ -541,6 +686,16 @@ func TestCoverFloat32(t *testing.T) {
A *float32 `json:"a,string"`
}{float32ptr(1)}},
},
{
name: "HeadFloat32PtrNotRootStringOmitEmpty",
data: struct {
A struct {
A *float32 `json:"a,string,omitempty"`
}
}{A: struct {
A *float32 `json:"a,string,omitempty"`
}{float32ptr(1)}},
},
// HeadFloat32PtrNilNotRoot
{
@ -567,6 +722,14 @@ func TestCoverFloat32(t *testing.T) {
}
}{},
},
{
name: "HeadFloat32PtrNilNotRootStringOmitEmpty",
data: struct {
A struct {
A *float32 `json:"a,string,omitempty"`
}
}{},
},
// PtrHeadFloat32ZeroNotRoot
{
@ -599,6 +762,16 @@ func TestCoverFloat32(t *testing.T) {
A float32 `json:"a,string"`
})},
},
{
name: "PtrHeadFloat32ZeroNotRootStringOmitEmpty",
data: struct {
A *struct {
A float32 `json:"a,string,omitempty"`
}
}{A: new(struct {
A float32 `json:"a,string,omitempty"`
})},
},
// PtrHeadFloat32NotRoot
{
@ -631,6 +804,16 @@ func TestCoverFloat32(t *testing.T) {
A float32 `json:"a,string"`
}{A: 1})},
},
{
name: "PtrHeadFloat32NotRootStringOmitEmpty",
data: struct {
A *struct {
A float32 `json:"a,string,omitempty"`
}
}{A: &(struct {
A float32 `json:"a,string,omitempty"`
}{A: 1})},
},
// PtrHeadFloat32PtrNotRoot
{
@ -663,6 +846,16 @@ func TestCoverFloat32(t *testing.T) {
A *float32 `json:"a,string"`
}{A: float32ptr(1)})},
},
{
name: "PtrHeadFloat32PtrNotRootStringOmitEmpty",
data: struct {
A *struct {
A *float32 `json:"a,string,omitempty"`
}
}{A: &(struct {
A *float32 `json:"a,string,omitempty"`
}{A: float32ptr(1)})},
},
// PtrHeadFloat32PtrNilNotRoot
{
@ -695,6 +888,16 @@ func TestCoverFloat32(t *testing.T) {
A *float32 `json:"a,string"`
}{A: nil})},
},
{
name: "PtrHeadFloat32PtrNilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *float32 `json:"a,string,omitempty"`
}
}{A: &(struct {
A *float32 `json:"a,string,omitempty"`
}{A: nil})},
},
// PtrHeadFloat32NilNotRoot
{
@ -721,6 +924,14 @@ func TestCoverFloat32(t *testing.T) {
} `json:",string"`
}{A: nil},
},
{
name: "PtrHeadFloat32NilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *float32 `json:"a,string,omitempty"`
} `json:",string,omitempty"`
}{A: nil},
},
// HeadFloat32ZeroMultiFieldsNotRoot
{
@ -756,6 +967,17 @@ func TestCoverFloat32(t *testing.T) {
}
}{},
},
{
name: "HeadFloat32ZeroMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A float32 `json:"a,string,omitempty"`
}
B struct {
B float32 `json:"b,string,omitempty"`
}
}{},
},
// HeadFloat32MultiFieldsNotRoot
{
@ -803,6 +1025,21 @@ func TestCoverFloat32(t *testing.T) {
B float32 `json:"b,string"`
}{B: 2}},
},
{
name: "HeadFloat32MultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A float32 `json:"a,string,omitempty"`
}
B struct {
B float32 `json:"b,string,omitempty"`
}
}{A: struct {
A float32 `json:"a,string,omitempty"`
}{A: 1}, B: struct {
B float32 `json:"b,string,omitempty"`
}{B: 2}},
},
// HeadFloat32PtrMultiFieldsNotRoot
{
@ -850,6 +1087,21 @@ func TestCoverFloat32(t *testing.T) {
B *float32 `json:"b,string"`
}{B: float32ptr(2)}},
},
{
name: "HeadFloat32PtrMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *float32 `json:"a,string,omitempty"`
}
B struct {
B *float32 `json:"b,string,omitempty"`
}
}{A: struct {
A *float32 `json:"a,string,omitempty"`
}{A: float32ptr(1)}, B: struct {
B *float32 `json:"b,string,omitempty"`
}{B: float32ptr(2)}},
},
// HeadFloat32PtrNilMultiFieldsNotRoot
{
@ -897,6 +1149,21 @@ func TestCoverFloat32(t *testing.T) {
B *float32 `json:"b,string"`
}{B: nil}},
},
{
name: "HeadFloat32PtrNilMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *float32 `json:"a,string,omitempty"`
}
B struct {
B *float32 `json:"b,string,omitempty"`
}
}{A: struct {
A *float32 `json:"a,string,omitempty"`
}{A: nil}, B: struct {
B *float32 `json:"b,string,omitempty"`
}{B: nil}},
},
// PtrHeadFloat32ZeroMultiFieldsNotRoot
{
@ -932,6 +1199,17 @@ func TestCoverFloat32(t *testing.T) {
}
}{},
},
{
name: "PtrHeadFloat32ZeroMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A float32 `json:"a,string,omitempty"`
}
B struct {
B float32 `json:"b,string,omitempty"`
}
}{},
},
// PtrHeadFloat32MultiFieldsNotRoot
{
@ -979,6 +1257,21 @@ func TestCoverFloat32(t *testing.T) {
B float32 `json:"b,string"`
}{B: 2}},
},
{
name: "PtrHeadFloat32MultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A float32 `json:"a,string,omitempty"`
}
B struct {
B float32 `json:"b,string,omitempty"`
}
}{A: struct {
A float32 `json:"a,string,omitempty"`
}{A: 1}, B: struct {
B float32 `json:"b,string,omitempty"`
}{B: 2}},
},
// PtrHeadFloat32PtrMultiFieldsNotRoot
{
@ -1026,6 +1319,21 @@ func TestCoverFloat32(t *testing.T) {
B *float32 `json:"b,string"`
}{B: float32ptr(2)})},
},
{
name: "PtrHeadFloat32PtrMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *float32 `json:"a,string,omitempty"`
}
B *struct {
B *float32 `json:"b,string,omitempty"`
}
}{A: &(struct {
A *float32 `json:"a,string,omitempty"`
}{A: float32ptr(1)}), B: &(struct {
B *float32 `json:"b,string,omitempty"`
}{B: float32ptr(2)})},
},
// PtrHeadFloat32PtrNilMultiFieldsNotRoot
{
@ -1061,6 +1369,17 @@ func TestCoverFloat32(t *testing.T) {
} `json:",string"`
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat32PtrNilMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *float32 `json:"a,string,omitempty"`
} `json:",string,omitempty"`
B *struct {
B *float32 `json:"b,string,omitempty"`
} `json:",string,omitempty"`
}{A: nil, B: nil},
},
// PtrHeadFloat32NilMultiFieldsNotRoot
{
@ -1096,6 +1415,17 @@ func TestCoverFloat32(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadFloat32NilMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *float32 `json:"a,string,omitempty"`
}
B *struct {
B *float32 `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadFloat32DoubleMultiFieldsNotRoot
{
@ -1155,6 +1485,25 @@ func TestCoverFloat32(t *testing.T) {
B float32 `json:"b,string"`
}{A: 3, B: 4})},
},
{
name: "PtrHeadFloat32DoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A float32 `json:"a,string,omitempty"`
B float32 `json:"b,string,omitempty"`
}
B *struct {
A float32 `json:"a,string,omitempty"`
B float32 `json:"b,string,omitempty"`
}
}{A: &(struct {
A float32 `json:"a,string,omitempty"`
B float32 `json:"b,string,omitempty"`
}{A: 1, B: 2}), B: &(struct {
A float32 `json:"a,string,omitempty"`
B float32 `json:"b,string,omitempty"`
}{A: 3, B: 4})},
},
// PtrHeadFloat32NilDoubleMultiFieldsNotRoot
{
@ -1196,6 +1545,19 @@ func TestCoverFloat32(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat32NilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A float32 `json:"a,string,omitempty"`
B float32 `json:"b,string,omitempty"`
}
B *struct {
A float32 `json:"a,string,omitempty"`
B float32 `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadFloat32NilDoubleMultiFieldsNotRoot
{
@ -1237,6 +1599,19 @@ func TestCoverFloat32(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadFloat32NilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A float32 `json:"a,string,omitempty"`
B float32 `json:"b,string,omitempty"`
}
B *struct {
A float32 `json:"a,string,omitempty"`
B float32 `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadFloat32PtrDoubleMultiFieldsNotRoot
{
@ -1296,6 +1671,25 @@ func TestCoverFloat32(t *testing.T) {
B *float32 `json:"b,string"`
}{A: float32ptr(3), B: float32ptr(4)})},
},
{
name: "PtrHeadFloat32PtrDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *float32 `json:"a,string,omitempty"`
B *float32 `json:"b,string,omitempty"`
}
B *struct {
A *float32 `json:"a,string,omitempty"`
B *float32 `json:"b,string,omitempty"`
}
}{A: &(struct {
A *float32 `json:"a,string,omitempty"`
B *float32 `json:"b,string,omitempty"`
}{A: float32ptr(1), B: float32ptr(2)}), B: &(struct {
A *float32 `json:"a,string,omitempty"`
B *float32 `json:"b,string,omitempty"`
}{A: float32ptr(3), B: float32ptr(4)})},
},
// PtrHeadFloat32PtrNilDoubleMultiFieldsNotRoot
{
@ -1337,6 +1731,19 @@ func TestCoverFloat32(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat32PtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *float32 `json:"a,string,omitempty"`
B *float32 `json:"b,string,omitempty"`
}
B *struct {
A *float32 `json:"a,string,omitempty"`
B *float32 `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadFloat32PtrNilDoubleMultiFieldsNotRoot
{
@ -1378,6 +1785,19 @@ func TestCoverFloat32(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadFloat32PtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *float32 `json:"a,string,omitempty"`
B *float32 `json:"b,string,omitempty"`
}
B *struct {
A *float32 `json:"a,string,omitempty"`
B *float32 `json:"b,string,omitempty"`
}
})(nil),
},
// AnonymousHeadFloat32
{
@ -1410,6 +1830,16 @@ func TestCoverFloat32(t *testing.T) {
B: 2,
},
},
{
name: "AnonymousHeadFloat32StringOmitEmpty",
data: struct {
structFloat32StringOmitEmpty
B float32 `json:"b,string,omitempty"`
}{
structFloat32StringOmitEmpty: structFloat32StringOmitEmpty{A: 1},
B: 2,
},
},
// PtrAnonymousHeadFloat32
{
@ -1442,6 +1872,16 @@ func TestCoverFloat32(t *testing.T) {
B: 2,
},
},
{
name: "PtrAnonymousHeadFloat32StringOmitEmpty",
data: struct {
*structFloat32StringOmitEmpty
B float32 `json:"b,string,omitempty"`
}{
structFloat32StringOmitEmpty: &structFloat32StringOmitEmpty{A: 1},
B: 2,
},
},
// NilPtrAnonymousHeadFloat32
{
@ -1474,6 +1914,16 @@ func TestCoverFloat32(t *testing.T) {
B: 2,
},
},
{
name: "NilPtrAnonymousHeadFloat32StringOmitEmpty",
data: struct {
*structFloat32StringOmitEmpty
B float32 `json:"b,string,omitempty"`
}{
structFloat32StringOmitEmpty: nil,
B: 2,
},
},
// AnonymousHeadFloat32Ptr
{
@ -1506,6 +1956,16 @@ func TestCoverFloat32(t *testing.T) {
B: float32ptr(2),
},
},
{
name: "AnonymousHeadFloat32PtrStringOmitEmpty",
data: struct {
structFloat32PtrStringOmitEmpty
B *float32 `json:"b,string,omitempty"`
}{
structFloat32PtrStringOmitEmpty: structFloat32PtrStringOmitEmpty{A: float32ptr(1)},
B: float32ptr(2),
},
},
// AnonymousHeadFloat32PtrNil
{
@ -1538,6 +1998,16 @@ func TestCoverFloat32(t *testing.T) {
B: float32ptr(2),
},
},
{
name: "AnonymousHeadFloat32PtrNilStringOmitEmpty",
data: struct {
structFloat32PtrStringOmitEmpty
B *float32 `json:"b,string,omitempty"`
}{
structFloat32PtrStringOmitEmpty: structFloat32PtrStringOmitEmpty{A: nil},
B: float32ptr(2),
},
},
// PtrAnonymousHeadFloat32Ptr
{
@ -1570,6 +2040,16 @@ func TestCoverFloat32(t *testing.T) {
B: float32ptr(2),
},
},
{
name: "PtrAnonymousHeadFloat32PtrStringOmitEmpty",
data: struct {
*structFloat32PtrStringOmitEmpty
B *float32 `json:"b,string,omitempty"`
}{
structFloat32PtrStringOmitEmpty: &structFloat32PtrStringOmitEmpty{A: float32ptr(1)},
B: float32ptr(2),
},
},
// NilPtrAnonymousHeadFloat32Ptr
{
@ -1602,6 +2082,16 @@ func TestCoverFloat32(t *testing.T) {
B: float32ptr(2),
},
},
{
name: "NilPtrAnonymousHeadFloat32PtrStringOmitEmpty",
data: struct {
*structFloat32PtrStringOmitEmpty
B *float32 `json:"b,string,omitempty"`
}{
structFloat32PtrStringOmitEmpty: nil,
B: float32ptr(2),
},
},
// AnonymousHeadFloat32Only
{
@ -1628,6 +2118,14 @@ func TestCoverFloat32(t *testing.T) {
structFloat32String: structFloat32String{A: 1},
},
},
{
name: "AnonymousHeadFloat32OnlyStringOmitEmpty",
data: struct {
structFloat32StringOmitEmpty
}{
structFloat32StringOmitEmpty: structFloat32StringOmitEmpty{A: 1},
},
},
// PtrAnonymousHeadFloat32Only
{
@ -1654,6 +2152,14 @@ func TestCoverFloat32(t *testing.T) {
structFloat32String: &structFloat32String{A: 1},
},
},
{
name: "PtrAnonymousHeadFloat32OnlyStringOmitEmpty",
data: struct {
*structFloat32StringOmitEmpty
}{
structFloat32StringOmitEmpty: &structFloat32StringOmitEmpty{A: 1},
},
},
// NilPtrAnonymousHeadFloat32Only
{
@ -1680,6 +2186,14 @@ func TestCoverFloat32(t *testing.T) {
structFloat32String: nil,
},
},
{
name: "NilPtrAnonymousHeadFloat32OnlyStringOmitEmpty",
data: struct {
*structFloat32StringOmitEmpty
}{
structFloat32StringOmitEmpty: nil,
},
},
// AnonymousHeadFloat32PtrOnly
{
@ -1706,6 +2220,14 @@ func TestCoverFloat32(t *testing.T) {
structFloat32PtrString: structFloat32PtrString{A: float32ptr(1)},
},
},
{
name: "AnonymousHeadFloat32PtrOnlyStringOmitEmpty",
data: struct {
structFloat32PtrStringOmitEmpty
}{
structFloat32PtrStringOmitEmpty: structFloat32PtrStringOmitEmpty{A: float32ptr(1)},
},
},
// AnonymousHeadFloat32PtrNilOnly
{
@ -1732,6 +2254,14 @@ func TestCoverFloat32(t *testing.T) {
structFloat32PtrString: structFloat32PtrString{A: nil},
},
},
{
name: "AnonymousHeadFloat32PtrNilOnlyStringOmitEmpty",
data: struct {
structFloat32PtrStringOmitEmpty
}{
structFloat32PtrStringOmitEmpty: structFloat32PtrStringOmitEmpty{A: nil},
},
},
// PtrAnonymousHeadFloat32PtrOnly
{
@ -1758,6 +2288,14 @@ func TestCoverFloat32(t *testing.T) {
structFloat32PtrString: &structFloat32PtrString{A: float32ptr(1)},
},
},
{
name: "PtrAnonymousHeadFloat32PtrOnlyStringOmitEmpty",
data: struct {
*structFloat32PtrStringOmitEmpty
}{
structFloat32PtrStringOmitEmpty: &structFloat32PtrStringOmitEmpty{A: float32ptr(1)},
},
},
// NilPtrAnonymousHeadFloat32PtrOnly
{
@ -1784,6 +2322,14 @@ func TestCoverFloat32(t *testing.T) {
structFloat32PtrString: nil,
},
},
{
name: "NilPtrAnonymousHeadFloat32PtrOnlyStringOmitEmpty",
data: struct {
*structFloat32PtrStringOmitEmpty
}{
structFloat32PtrStringOmitEmpty: nil,
},
},
}
for _, test := range tests {
for _, indent := range []bool{true, false} {

View File

@ -17,6 +17,9 @@ func TestCoverFloat64(t *testing.T) {
type structFloat64String struct {
A float64 `json:"a,string"`
}
type structFloat64StringOmitEmpty struct {
A float64 `json:"a,string,omitempty"`
}
type structFloat64Ptr struct {
A *float64 `json:"a"`
@ -27,6 +30,9 @@ func TestCoverFloat64(t *testing.T) {
type structFloat64PtrString struct {
A *float64 `json:"a,string"`
}
type structFloat64PtrStringOmitEmpty struct {
A *float64 `json:"a,string,omitempty"`
}
tests := []struct {
name string
@ -72,6 +78,12 @@ func TestCoverFloat64(t *testing.T) {
A float64 `json:"a,string"`
}{},
},
{
name: "HeadFloat64ZeroStringOmitEmpty",
data: struct {
A float64 `json:"a,string,omitempty"`
}{},
},
// HeadFloat64
{
@ -92,6 +104,12 @@ func TestCoverFloat64(t *testing.T) {
A float64 `json:"a,string"`
}{A: 1},
},
{
name: "HeadFloat64StringOmitEmpty",
data: struct {
A float64 `json:"a,string,omitempty"`
}{A: 1},
},
// HeadFloat64Ptr
{
@ -112,6 +130,12 @@ func TestCoverFloat64(t *testing.T) {
A *float64 `json:"a,string"`
}{A: float64ptr(1)},
},
{
name: "HeadFloat64PtrStringOmitEmpty",
data: struct {
A *float64 `json:"a,string,omitempty"`
}{A: float64ptr(1)},
},
// HeadFloat64PtrNil
{
@ -132,6 +156,12 @@ func TestCoverFloat64(t *testing.T) {
A *float64 `json:"a,string"`
}{A: nil},
},
{
name: "HeadFloat64PtrNilStringOmitEmpty",
data: struct {
A *float64 `json:"a,string,omitempty"`
}{A: nil},
},
// PtrHeadFloat64Zero
{
@ -152,6 +182,12 @@ func TestCoverFloat64(t *testing.T) {
A float64 `json:"a,string"`
}{},
},
{
name: "PtrHeadFloat64ZeroStringOmitEmpty",
data: &struct {
A float64 `json:"a,string,omitempty"`
}{},
},
// PtrHeadFloat64
{
@ -172,6 +208,12 @@ func TestCoverFloat64(t *testing.T) {
A float64 `json:"a,string"`
}{A: 1},
},
{
name: "PtrHeadFloat64StringOmitEmpty",
data: &struct {
A float64 `json:"a,string,omitempty"`
}{A: 1},
},
// PtrHeadFloat64Ptr
{
@ -192,6 +234,12 @@ func TestCoverFloat64(t *testing.T) {
A *float64 `json:"a,string"`
}{A: float64ptr(1)},
},
{
name: "PtrHeadFloat64PtrStringOmitEmpty",
data: &struct {
A *float64 `json:"a,string,omitempty"`
}{A: float64ptr(1)},
},
// PtrHeadFloat64PtrNil
{
@ -212,6 +260,12 @@ func TestCoverFloat64(t *testing.T) {
A *float64 `json:"a,string"`
}{A: nil},
},
{
name: "PtrHeadFloat64PtrNilStringOmitEmpty",
data: &struct {
A *float64 `json:"a,string,omitempty"`
}{A: nil},
},
// PtrHeadFloat64Nil
{
@ -232,6 +286,12 @@ func TestCoverFloat64(t *testing.T) {
A *float64 `json:"a,string"`
})(nil),
},
{
name: "PtrHeadFloat64NilStringOmitEmpty",
data: (*struct {
A *float64 `json:"a,string,omitempty"`
})(nil),
},
// HeadFloat64ZeroMultiFields
{
@ -251,13 +311,21 @@ func TestCoverFloat64(t *testing.T) {
}{},
},
{
name: "HeadFloat64ZeroMultiFields",
name: "HeadFloat64ZeroMultiFieldsString",
data: struct {
A float64 `json:"a,string"`
B float64 `json:"b,string"`
C float64 `json:"c,string"`
}{},
},
{
name: "HeadFloat64ZeroMultiFieldsStringOmitEmpty",
data: struct {
A float64 `json:"a,string,omitempty"`
B float64 `json:"b,string,omitempty"`
C float64 `json:"c,string,omitempty"`
}{},
},
// HeadFloat64MultiFields
{
@ -284,6 +352,14 @@ func TestCoverFloat64(t *testing.T) {
C float64 `json:"c,string"`
}{A: 1, B: 2, C: 3},
},
{
name: "HeadFloat64MultiFieldsStringOmitEmpty",
data: struct {
A float64 `json:"a,string,omitempty"`
B float64 `json:"b,string,omitempty"`
C float64 `json:"c,string,omitempty"`
}{A: 1, B: 2, C: 3},
},
// HeadFloat64PtrMultiFields
{
@ -310,6 +386,14 @@ func TestCoverFloat64(t *testing.T) {
C *float64 `json:"c,string"`
}{A: float64ptr(1), B: float64ptr(2), C: float64ptr(3)},
},
{
name: "HeadFloat64PtrMultiFieldsStringOmitEmpty",
data: struct {
A *float64 `json:"a,string,omitempty"`
B *float64 `json:"b,string,omitempty"`
C *float64 `json:"c,string,omitempty"`
}{A: float64ptr(1), B: float64ptr(2), C: float64ptr(3)},
},
// HeadFloat64PtrNilMultiFields
{
@ -336,6 +420,14 @@ func TestCoverFloat64(t *testing.T) {
C *float64 `json:"c,string"`
}{A: nil, B: nil, C: nil},
},
{
name: "HeadFloat64PtrNilMultiFieldsStringOmitEmpty",
data: struct {
A *float64 `json:"a,string,omitempty"`
B *float64 `json:"b,string,omitempty"`
C *float64 `json:"c,string,omitempty"`
}{A: nil, B: nil, C: nil},
},
// PtrHeadFloat64ZeroMultiFields
{
@ -359,6 +451,13 @@ func TestCoverFloat64(t *testing.T) {
B float64 `json:"b,string"`
}{},
},
{
name: "PtrHeadFloat64ZeroMultiFieldsStringOmitEmpty",
data: &struct {
A float64 `json:"a,string,omitempty"`
B float64 `json:"b,string,omitempty"`
}{},
},
// PtrHeadFloat64MultiFields
{
@ -382,6 +481,13 @@ func TestCoverFloat64(t *testing.T) {
B float64 `json:"b,string"`
}{A: 1, B: 2},
},
{
name: "PtrHeadFloat64MultiFieldsStringOmitEmpty",
data: &struct {
A float64 `json:"a,string,omitempty"`
B float64 `json:"b,string,omitempty"`
}{A: 1, B: 2},
},
// PtrHeadFloat64PtrMultiFields
{
@ -405,6 +511,13 @@ func TestCoverFloat64(t *testing.T) {
B *float64 `json:"b,string"`
}{A: float64ptr(1), B: float64ptr(2)},
},
{
name: "PtrHeadFloat64PtrMultiFieldsStringOmitEmpty",
data: &struct {
A *float64 `json:"a,string,omitempty"`
B *float64 `json:"b,string,omitempty"`
}{A: float64ptr(1), B: float64ptr(2)},
},
// PtrHeadFloat64PtrNilMultiFields
{
@ -428,6 +541,13 @@ func TestCoverFloat64(t *testing.T) {
B *float64 `json:"b,string"`
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat64PtrNilMultiFieldsStringOmitEmpty",
data: &struct {
A *float64 `json:"a,string,omitempty"`
B *float64 `json:"b,string,omitempty"`
}{A: nil, B: nil},
},
// PtrHeadFloat64NilMultiFields
{
@ -451,6 +571,13 @@ func TestCoverFloat64(t *testing.T) {
B *float64 `json:"b,string"`
})(nil),
},
{
name: "PtrHeadFloat64NilMultiFieldsStringOmitEmpty",
data: (*struct {
A *float64 `json:"a,string,omitempty"`
B *float64 `json:"b,string,omitempty"`
})(nil),
},
// HeadFloat64ZeroNotRoot
{
@ -477,6 +604,14 @@ func TestCoverFloat64(t *testing.T) {
}
}{},
},
{
name: "HeadFloat64ZeroNotRootStringOmitEmpty",
data: struct {
A struct {
A float64 `json:"a,string,omitempty"`
}
}{},
},
// HeadFloat64NotRoot
{
@ -509,6 +644,16 @@ func TestCoverFloat64(t *testing.T) {
A float64 `json:"a,string"`
}{A: 1}},
},
{
name: "HeadFloat64NotRootStringOmitEmpty",
data: struct {
A struct {
A float64 `json:"a,string,omitempty"`
}
}{A: struct {
A float64 `json:"a,string,omitempty"`
}{A: 1}},
},
// HeadFloat64PtrNotRoot
{
@ -541,6 +686,16 @@ func TestCoverFloat64(t *testing.T) {
A *float64 `json:"a,string"`
}{float64ptr(1)}},
},
{
name: "HeadFloat64PtrNotRootStringOmitEmpty",
data: struct {
A struct {
A *float64 `json:"a,string,omitempty"`
}
}{A: struct {
A *float64 `json:"a,string,omitempty"`
}{float64ptr(1)}},
},
// HeadFloat64PtrNilNotRoot
{
@ -567,6 +722,14 @@ func TestCoverFloat64(t *testing.T) {
}
}{},
},
{
name: "HeadFloat64PtrNilNotRootStringOmitEmpty",
data: struct {
A struct {
A *float64 `json:"a,string,omitempty"`
}
}{},
},
// PtrHeadFloat64ZeroNotRoot
{
@ -599,6 +762,16 @@ func TestCoverFloat64(t *testing.T) {
A float64 `json:"a,string"`
})},
},
{
name: "PtrHeadFloat64ZeroNotRootStringOmitEmpty",
data: struct {
A *struct {
A float64 `json:"a,string,omitempty"`
}
}{A: new(struct {
A float64 `json:"a,string,omitempty"`
})},
},
// PtrHeadFloat64NotRoot
{
@ -631,6 +804,16 @@ func TestCoverFloat64(t *testing.T) {
A float64 `json:"a,string"`
}{A: 1})},
},
{
name: "PtrHeadFloat64NotRootStringOmitEmpty",
data: struct {
A *struct {
A float64 `json:"a,string,omitempty"`
}
}{A: &(struct {
A float64 `json:"a,string,omitempty"`
}{A: 1})},
},
// PtrHeadFloat64PtrNotRoot
{
@ -663,6 +846,16 @@ func TestCoverFloat64(t *testing.T) {
A *float64 `json:"a,string"`
}{A: float64ptr(1)})},
},
{
name: "PtrHeadFloat64PtrNotRootStringOmitEmpty",
data: struct {
A *struct {
A *float64 `json:"a,string,omitempty"`
}
}{A: &(struct {
A *float64 `json:"a,string,omitempty"`
}{A: float64ptr(1)})},
},
// PtrHeadFloat64PtrNilNotRoot
{
@ -695,6 +888,16 @@ func TestCoverFloat64(t *testing.T) {
A *float64 `json:"a,string"`
}{A: nil})},
},
{
name: "PtrHeadFloat64PtrNilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *float64 `json:"a,string,omitempty"`
}
}{A: &(struct {
A *float64 `json:"a,string,omitempty"`
}{A: nil})},
},
// PtrHeadFloat64NilNotRoot
{
@ -721,6 +924,14 @@ func TestCoverFloat64(t *testing.T) {
} `json:",string"`
}{A: nil},
},
{
name: "PtrHeadFloat64NilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *float64 `json:"a,string,omitempty"`
} `json:",string,omitempty"`
}{A: nil},
},
// HeadFloat64ZeroMultiFieldsNotRoot
{
@ -756,6 +967,17 @@ func TestCoverFloat64(t *testing.T) {
}
}{},
},
{
name: "HeadFloat64ZeroMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A float64 `json:"a,string,omitempty"`
}
B struct {
B float64 `json:"b,string,omitempty"`
}
}{},
},
// HeadFloat64MultiFieldsNotRoot
{
@ -803,6 +1025,21 @@ func TestCoverFloat64(t *testing.T) {
B float64 `json:"b,string"`
}{B: 2}},
},
{
name: "HeadFloat64MultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A float64 `json:"a,string,omitempty"`
}
B struct {
B float64 `json:"b,string,omitempty"`
}
}{A: struct {
A float64 `json:"a,string,omitempty"`
}{A: 1}, B: struct {
B float64 `json:"b,string,omitempty"`
}{B: 2}},
},
// HeadFloat64PtrMultiFieldsNotRoot
{
@ -850,6 +1087,21 @@ func TestCoverFloat64(t *testing.T) {
B *float64 `json:"b,string"`
}{B: float64ptr(2)}},
},
{
name: "HeadFloat64PtrMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *float64 `json:"a,string,omitempty"`
}
B struct {
B *float64 `json:"b,string,omitempty"`
}
}{A: struct {
A *float64 `json:"a,string,omitempty"`
}{A: float64ptr(1)}, B: struct {
B *float64 `json:"b,string,omitempty"`
}{B: float64ptr(2)}},
},
// HeadFloat64PtrNilMultiFieldsNotRoot
{
@ -897,6 +1149,21 @@ func TestCoverFloat64(t *testing.T) {
B *float64 `json:"b,string"`
}{B: nil}},
},
{
name: "HeadFloat64PtrNilMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *float64 `json:"a,string,omitempty"`
}
B struct {
B *float64 `json:"b,string,omitempty"`
}
}{A: struct {
A *float64 `json:"a,string,omitempty"`
}{A: nil}, B: struct {
B *float64 `json:"b,string,omitempty"`
}{B: nil}},
},
// PtrHeadFloat64ZeroMultiFieldsNotRoot
{
@ -932,6 +1199,17 @@ func TestCoverFloat64(t *testing.T) {
}
}{},
},
{
name: "PtrHeadFloat64ZeroMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A float64 `json:"a,string,omitempty"`
}
B struct {
B float64 `json:"b,string,omitempty"`
}
}{},
},
// PtrHeadFloat64MultiFieldsNotRoot
{
@ -979,6 +1257,21 @@ func TestCoverFloat64(t *testing.T) {
B float64 `json:"b,string"`
}{B: 2}},
},
{
name: "PtrHeadFloat64MultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A float64 `json:"a,string,omitempty"`
}
B struct {
B float64 `json:"b,string,omitempty"`
}
}{A: struct {
A float64 `json:"a,string,omitempty"`
}{A: 1}, B: struct {
B float64 `json:"b,string,omitempty"`
}{B: 2}},
},
// PtrHeadFloat64PtrMultiFieldsNotRoot
{
@ -1026,6 +1319,21 @@ func TestCoverFloat64(t *testing.T) {
B *float64 `json:"b,string"`
}{B: float64ptr(2)})},
},
{
name: "PtrHeadFloat64PtrMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *float64 `json:"a,string,omitempty"`
}
B *struct {
B *float64 `json:"b,string,omitempty"`
}
}{A: &(struct {
A *float64 `json:"a,string,omitempty"`
}{A: float64ptr(1)}), B: &(struct {
B *float64 `json:"b,string,omitempty"`
}{B: float64ptr(2)})},
},
// PtrHeadFloat64PtrNilMultiFieldsNotRoot
{
@ -1061,6 +1369,17 @@ func TestCoverFloat64(t *testing.T) {
} `json:",string"`
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat64PtrNilMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *float64 `json:"a,string,omitempty"`
} `json:",string,omitempty"`
B *struct {
B *float64 `json:"b,string,omitempty"`
} `json:",string,omitempty"`
}{A: nil, B: nil},
},
// PtrHeadFloat64NilMultiFieldsNotRoot
{
@ -1096,6 +1415,17 @@ func TestCoverFloat64(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadFloat64NilMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *float64 `json:"a,string,omitempty"`
}
B *struct {
B *float64 `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadFloat64DoubleMultiFieldsNotRoot
{
@ -1155,6 +1485,25 @@ func TestCoverFloat64(t *testing.T) {
B float64 `json:"b,string"`
}{A: 3, B: 4})},
},
{
name: "PtrHeadFloat64DoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A float64 `json:"a,string,omitempty"`
B float64 `json:"b,string,omitempty"`
}
B *struct {
A float64 `json:"a,string,omitempty"`
B float64 `json:"b,string,omitempty"`
}
}{A: &(struct {
A float64 `json:"a,string,omitempty"`
B float64 `json:"b,string,omitempty"`
}{A: 1, B: 2}), B: &(struct {
A float64 `json:"a,string,omitempty"`
B float64 `json:"b,string,omitempty"`
}{A: 3, B: 4})},
},
// PtrHeadFloat64NilDoubleMultiFieldsNotRoot
{
@ -1196,6 +1545,19 @@ func TestCoverFloat64(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat64NilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A float64 `json:"a,string,omitempty"`
B float64 `json:"b,string,omitempty"`
}
B *struct {
A float64 `json:"a,string,omitempty"`
B float64 `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadFloat64NilDoubleMultiFieldsNotRoot
{
@ -1237,6 +1599,19 @@ func TestCoverFloat64(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadFloat64NilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A float64 `json:"a,string,omitempty"`
B float64 `json:"b,string,omitempty"`
}
B *struct {
A float64 `json:"a,string,omitempty"`
B float64 `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadFloat64PtrDoubleMultiFieldsNotRoot
{
@ -1296,6 +1671,25 @@ func TestCoverFloat64(t *testing.T) {
B *float64 `json:"b,string"`
}{A: float64ptr(3), B: float64ptr(4)})},
},
{
name: "PtrHeadFloat64PtrDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *float64 `json:"a,string,omitempty"`
B *float64 `json:"b,string,omitempty"`
}
B *struct {
A *float64 `json:"a,string,omitempty"`
B *float64 `json:"b,string,omitempty"`
}
}{A: &(struct {
A *float64 `json:"a,string,omitempty"`
B *float64 `json:"b,string,omitempty"`
}{A: float64ptr(1), B: float64ptr(2)}), B: &(struct {
A *float64 `json:"a,string,omitempty"`
B *float64 `json:"b,string,omitempty"`
}{A: float64ptr(3), B: float64ptr(4)})},
},
// PtrHeadFloat64PtrNilDoubleMultiFieldsNotRoot
{
@ -1337,6 +1731,19 @@ func TestCoverFloat64(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *float64 `json:"a,string,omitempty"`
B *float64 `json:"b,string,omitempty"`
}
B *struct {
A *float64 `json:"a,string,omitempty"`
B *float64 `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadFloat64PtrNilDoubleMultiFieldsNotRoot
{
@ -1378,6 +1785,19 @@ func TestCoverFloat64(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *float64 `json:"a,string,omitempty"`
B *float64 `json:"b,string,omitempty"`
}
B *struct {
A *float64 `json:"a,string,omitempty"`
B *float64 `json:"b,string,omitempty"`
}
})(nil),
},
// AnonymousHeadFloat64
{
@ -1410,6 +1830,16 @@ func TestCoverFloat64(t *testing.T) {
B: 2,
},
},
{
name: "AnonymousHeadFloat64StringOmitEmpty",
data: struct {
structFloat64StringOmitEmpty
B float64 `json:"b,string,omitempty"`
}{
structFloat64StringOmitEmpty: structFloat64StringOmitEmpty{A: 1},
B: 2,
},
},
// PtrAnonymousHeadFloat64
{
@ -1442,6 +1872,16 @@ func TestCoverFloat64(t *testing.T) {
B: 2,
},
},
{
name: "PtrAnonymousHeadFloat64StringOmitEmpty",
data: struct {
*structFloat64StringOmitEmpty
B float64 `json:"b,string,omitempty"`
}{
structFloat64StringOmitEmpty: &structFloat64StringOmitEmpty{A: 1},
B: 2,
},
},
// NilPtrAnonymousHeadFloat64
{
@ -1474,6 +1914,16 @@ func TestCoverFloat64(t *testing.T) {
B: 2,
},
},
{
name: "NilPtrAnonymousHeadFloat64StringOmitEmpty",
data: struct {
*structFloat64StringOmitEmpty
B float64 `json:"b,string,omitempty"`
}{
structFloat64StringOmitEmpty: nil,
B: 2,
},
},
// AnonymousHeadFloat64Ptr
{
@ -1506,6 +1956,16 @@ func TestCoverFloat64(t *testing.T) {
B: float64ptr(2),
},
},
{
name: "AnonymousHeadFloat64PtrStringOmitEmpty",
data: struct {
structFloat64PtrStringOmitEmpty
B *float64 `json:"b,string,omitempty"`
}{
structFloat64PtrStringOmitEmpty: structFloat64PtrStringOmitEmpty{A: float64ptr(1)},
B: float64ptr(2),
},
},
// AnonymousHeadFloat64PtrNil
{
@ -1538,6 +1998,16 @@ func TestCoverFloat64(t *testing.T) {
B: float64ptr(2),
},
},
{
name: "AnonymousHeadFloat64PtrNilStringOmitEmpty",
data: struct {
structFloat64PtrStringOmitEmpty
B *float64 `json:"b,string,omitempty"`
}{
structFloat64PtrStringOmitEmpty: structFloat64PtrStringOmitEmpty{A: nil},
B: float64ptr(2),
},
},
// PtrAnonymousHeadFloat64Ptr
{
@ -1570,6 +2040,16 @@ func TestCoverFloat64(t *testing.T) {
B: float64ptr(2),
},
},
{
name: "PtrAnonymousHeadFloat64PtrStringOmitEmpty",
data: struct {
*structFloat64PtrStringOmitEmpty
B *float64 `json:"b,string,omitempty"`
}{
structFloat64PtrStringOmitEmpty: &structFloat64PtrStringOmitEmpty{A: float64ptr(1)},
B: float64ptr(2),
},
},
// NilPtrAnonymousHeadFloat64Ptr
{
@ -1602,6 +2082,16 @@ func TestCoverFloat64(t *testing.T) {
B: float64ptr(2),
},
},
{
name: "NilPtrAnonymousHeadFloat64PtrStringOmitEmpty",
data: struct {
*structFloat64PtrStringOmitEmpty
B *float64 `json:"b,string,omitempty"`
}{
structFloat64PtrStringOmitEmpty: nil,
B: float64ptr(2),
},
},
// AnonymousHeadFloat64Only
{
@ -1628,6 +2118,14 @@ func TestCoverFloat64(t *testing.T) {
structFloat64String: structFloat64String{A: 1},
},
},
{
name: "AnonymousHeadFloat64OnlyStringOmitEmpty",
data: struct {
structFloat64StringOmitEmpty
}{
structFloat64StringOmitEmpty: structFloat64StringOmitEmpty{A: 1},
},
},
// PtrAnonymousHeadFloat64Only
{
@ -1654,6 +2152,14 @@ func TestCoverFloat64(t *testing.T) {
structFloat64String: &structFloat64String{A: 1},
},
},
{
name: "PtrAnonymousHeadFloat64OnlyStringOmitEmpty",
data: struct {
*structFloat64StringOmitEmpty
}{
structFloat64StringOmitEmpty: &structFloat64StringOmitEmpty{A: 1},
},
},
// NilPtrAnonymousHeadFloat64Only
{
@ -1680,6 +2186,14 @@ func TestCoverFloat64(t *testing.T) {
structFloat64String: nil,
},
},
{
name: "NilPtrAnonymousHeadFloat64OnlyStringOmitEmpty",
data: struct {
*structFloat64StringOmitEmpty
}{
structFloat64StringOmitEmpty: nil,
},
},
// AnonymousHeadFloat64PtrOnly
{
@ -1706,6 +2220,14 @@ func TestCoverFloat64(t *testing.T) {
structFloat64PtrString: structFloat64PtrString{A: float64ptr(1)},
},
},
{
name: "AnonymousHeadFloat64PtrOnlyStringOmitEmpty",
data: struct {
structFloat64PtrStringOmitEmpty
}{
structFloat64PtrStringOmitEmpty: structFloat64PtrStringOmitEmpty{A: float64ptr(1)},
},
},
// AnonymousHeadFloat64PtrNilOnly
{
@ -1732,6 +2254,14 @@ func TestCoverFloat64(t *testing.T) {
structFloat64PtrString: structFloat64PtrString{A: nil},
},
},
{
name: "AnonymousHeadFloat64PtrNilOnlyStringOmitEmpty",
data: struct {
structFloat64PtrStringOmitEmpty
}{
structFloat64PtrStringOmitEmpty: structFloat64PtrStringOmitEmpty{A: nil},
},
},
// PtrAnonymousHeadFloat64PtrOnly
{
@ -1758,6 +2288,14 @@ func TestCoverFloat64(t *testing.T) {
structFloat64PtrString: &structFloat64PtrString{A: float64ptr(1)},
},
},
{
name: "PtrAnonymousHeadFloat64PtrOnlyStringOmitEmpty",
data: struct {
*structFloat64PtrStringOmitEmpty
}{
structFloat64PtrStringOmitEmpty: &structFloat64PtrStringOmitEmpty{A: float64ptr(1)},
},
},
// NilPtrAnonymousHeadFloat64PtrOnly
{
@ -1784,6 +2322,14 @@ func TestCoverFloat64(t *testing.T) {
structFloat64PtrString: nil,
},
},
{
name: "NilPtrAnonymousHeadFloat64PtrOnlyStringOmitEmpty",
data: struct {
*structFloat64PtrStringOmitEmpty
}{
structFloat64PtrStringOmitEmpty: nil,
},
},
}
for _, test := range tests {
for _, indent := range []bool{true, false} {

View File

@ -17,6 +17,9 @@ func TestCoverInt(t *testing.T) {
type structIntString struct {
A int `json:"a,string"`
}
type structIntStringOmitEmpty struct {
A int `json:"a,omitempty,string"`
}
type structIntPtr struct {
A *int `json:"a"`
@ -27,6 +30,9 @@ func TestCoverInt(t *testing.T) {
type structIntPtrString struct {
A *int `json:"a,string"`
}
type structIntPtrStringOmitEmpty struct {
A *int `json:"a,omitempty,string"`
}
tests := []struct {
name string
@ -152,6 +158,12 @@ func TestCoverInt(t *testing.T) {
A int `json:"a,string"`
}{},
},
{
name: "PtrHeadIntZeroStringOmitEmpty",
data: &struct {
A int `json:"a,string,omitempty"`
}{},
},
// PtrHeadInt
{
@ -172,6 +184,12 @@ func TestCoverInt(t *testing.T) {
A int `json:"a,string"`
}{A: -1},
},
{
name: "PtrHeadIntStringOmitEmpty",
data: &struct {
A int `json:"a,string,omitempty"`
}{A: -1},
},
// PtrHeadIntPtr
{
@ -192,6 +210,12 @@ func TestCoverInt(t *testing.T) {
A *int `json:"a,string"`
}{A: intptr(-1)},
},
{
name: "PtrHeadIntPtrStringOmitEmpty",
data: &struct {
A *int `json:"a,string,omitempty"`
}{A: intptr(-1)},
},
// PtrHeadIntPtrNil
{
@ -212,6 +236,12 @@ func TestCoverInt(t *testing.T) {
A *int `json:"a,string"`
}{A: nil},
},
{
name: "PtrHeadIntPtrNilStringOmitEmpty",
data: &struct {
A *int `json:"a,string,omitempty"`
}{A: nil},
},
// PtrHeadIntNil
{
@ -232,6 +262,12 @@ func TestCoverInt(t *testing.T) {
A *int `json:"a,string"`
})(nil),
},
{
name: "PtrHeadIntNilStringOmitEmpty",
data: (*struct {
A *int `json:"a,string,omitempty"`
})(nil),
},
// HeadIntZeroMultiFields
{
@ -251,13 +287,21 @@ func TestCoverInt(t *testing.T) {
}{},
},
{
name: "HeadIntZeroMultiFields",
name: "HeadIntZeroMultiFieldsString",
data: struct {
A int `json:"a,string"`
B int `json:"b,string"`
C int `json:"c,string"`
}{},
},
{
name: "HeadIntZeroMultiFieldsStringOmitEmpty",
data: struct {
A int `json:"a,string,omitempty"`
B int `json:"b,string,omitempty"`
C int `json:"c,string,omitempty"`
}{},
},
// HeadIntMultiFields
{
@ -284,6 +328,14 @@ func TestCoverInt(t *testing.T) {
C int `json:"c,string"`
}{A: -1, B: 2, C: 3},
},
{
name: "HeadIntMultiFieldsStringOmitEmpty",
data: struct {
A int `json:"a,string,omitempty"`
B int `json:"b,string,omitempty"`
C int `json:"c,string,omitempty"`
}{A: -1, B: 2, C: 3},
},
// HeadIntPtrMultiFields
{
@ -310,6 +362,14 @@ func TestCoverInt(t *testing.T) {
C *int `json:"c,string"`
}{A: intptr(-1), B: intptr(2), C: intptr(3)},
},
{
name: "HeadIntPtrMultiFieldsStringOmitEmpty",
data: struct {
A *int `json:"a,string,omitempty"`
B *int `json:"b,string,omitempty"`
C *int `json:"c,string,omitempty"`
}{A: intptr(-1), B: intptr(2), C: intptr(3)},
},
// HeadIntPtrNilMultiFields
{
@ -336,6 +396,14 @@ func TestCoverInt(t *testing.T) {
C *int `json:"c,string"`
}{A: nil, B: nil, C: nil},
},
{
name: "HeadIntPtrNilMultiFieldsStringOmitEmpty",
data: struct {
A *int `json:"a,string,omitempty"`
B *int `json:"b,string,omitempty"`
C *int `json:"c,string,omitempty"`
}{A: nil, B: nil, C: nil},
},
// PtrHeadIntZeroMultiFields
{
@ -359,6 +427,13 @@ func TestCoverInt(t *testing.T) {
B int `json:"b,string"`
}{},
},
{
name: "PtrHeadIntZeroMultiFieldsStringOmitEmpty",
data: &struct {
A int `json:"a,string,omitempty"`
B int `json:"b,string,omitempty"`
}{},
},
// PtrHeadIntMultiFields
{
@ -382,6 +457,13 @@ func TestCoverInt(t *testing.T) {
B int `json:"b,string"`
}{A: -1, B: 2},
},
{
name: "PtrHeadIntMultiFieldsStringOmitEmpty",
data: &struct {
A int `json:"a,string,omitempty"`
B int `json:"b,string,omitempty"`
}{A: -1, B: 2},
},
// PtrHeadIntPtrMultiFields
{
@ -405,6 +487,13 @@ func TestCoverInt(t *testing.T) {
B *int `json:"b,string"`
}{A: intptr(-1), B: intptr(2)},
},
{
name: "PtrHeadIntPtrMultiFieldsStringOmitEmpty",
data: &struct {
A *int `json:"a,string,omitempty"`
B *int `json:"b,string,omitempty"`
}{A: intptr(-1), B: intptr(2)},
},
// PtrHeadIntPtrNilMultiFields
{
@ -428,6 +517,13 @@ func TestCoverInt(t *testing.T) {
B *int `json:"b,string"`
}{A: nil, B: nil},
},
{
name: "PtrHeadIntPtrNilMultiFieldsStringOmitEmpty",
data: &struct {
A *int `json:"a,string,omitempty"`
B *int `json:"b,string,omitempty"`
}{A: nil, B: nil},
},
// PtrHeadIntNilMultiFields
{
@ -451,6 +547,13 @@ func TestCoverInt(t *testing.T) {
B *int `json:"b,string"`
})(nil),
},
{
name: "PtrHeadIntNilMultiFieldsStringOmitEmpty",
data: (*struct {
A *int `json:"a,string,omitempty"`
B *int `json:"b,string,omitempty"`
})(nil),
},
// HeadIntZeroNotRoot
{
@ -477,6 +580,14 @@ func TestCoverInt(t *testing.T) {
}
}{},
},
{
name: "HeadIntZeroNotRootStringOmitEmpty",
data: struct {
A struct {
A int `json:"a,string,omitempty"`
}
}{},
},
// HeadIntNotRoot
{
@ -509,6 +620,16 @@ func TestCoverInt(t *testing.T) {
A int `json:"a,string"`
}{A: -1}},
},
{
name: "HeadIntNotRootStringOmitEmpty",
data: struct {
A struct {
A int `json:"a,string,omitempty"`
}
}{A: struct {
A int `json:"a,string,omitempty"`
}{A: -1}},
},
// HeadIntPtrNotRoot
{
@ -541,6 +662,16 @@ func TestCoverInt(t *testing.T) {
A *int `json:"a,string"`
}{intptr(-1)}},
},
{
name: "HeadIntPtrNotRootStringOmitEmpty",
data: struct {
A struct {
A *int `json:"a,string,omitempty"`
}
}{A: struct {
A *int `json:"a,string,omitempty"`
}{intptr(-1)}},
},
// HeadIntPtrNilNotRoot
{
@ -567,6 +698,14 @@ func TestCoverInt(t *testing.T) {
}
}{},
},
{
name: "HeadIntPtrNilNotRootStringOmitEmpty",
data: struct {
A struct {
A *int `json:"a,string,omitempty"`
}
}{},
},
// PtrHeadIntZeroNotRoot
{
@ -599,6 +738,16 @@ func TestCoverInt(t *testing.T) {
A int `json:"a,string"`
})},
},
{
name: "PtrHeadIntZeroNotRootStringOmitEmpty",
data: struct {
A *struct {
A int `json:"a,string,omitempty"`
}
}{A: new(struct {
A int `json:"a,string,omitempty"`
})},
},
// PtrHeadIntNotRoot
{
@ -631,6 +780,16 @@ func TestCoverInt(t *testing.T) {
A int `json:"a,string"`
}{A: -1})},
},
{
name: "PtrHeadIntNotRootStringOmitEmpty",
data: struct {
A *struct {
A int `json:"a,string,omitempty"`
}
}{A: &(struct {
A int `json:"a,string,omitempty"`
}{A: -1})},
},
// PtrHeadIntPtrNotRoot
{
@ -663,6 +822,16 @@ func TestCoverInt(t *testing.T) {
A *int `json:"a,string"`
}{A: intptr(-1)})},
},
{
name: "PtrHeadIntPtrNotRootStringOmitEmpty",
data: struct {
A *struct {
A *int `json:"a,string,omitempty"`
}
}{A: &(struct {
A *int `json:"a,string,omitempty"`
}{A: intptr(-1)})},
},
// PtrHeadIntPtrNilNotRoot
{
@ -695,6 +864,16 @@ func TestCoverInt(t *testing.T) {
A *int `json:"a,string"`
}{A: nil})},
},
{
name: "PtrHeadIntPtrNilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *int `json:"a,string,omitempty"`
}
}{A: &(struct {
A *int `json:"a,string,omitempty"`
}{A: nil})},
},
// PtrHeadIntNilNotRoot
{
@ -721,6 +900,14 @@ func TestCoverInt(t *testing.T) {
} `json:",string"`
}{A: nil},
},
{
name: "PtrHeadIntNilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *int `json:"a,string,omitempty"`
} `json:",string,omitempty"`
}{A: nil},
},
// HeadIntZeroMultiFieldsNotRoot
{
@ -756,6 +943,17 @@ func TestCoverInt(t *testing.T) {
}
}{},
},
{
name: "HeadIntZeroMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A int `json:"a,string,omitempty"`
}
B struct {
B int `json:"b,string,omitempty"`
}
}{},
},
// HeadIntMultiFieldsNotRoot
{
@ -803,6 +1001,21 @@ func TestCoverInt(t *testing.T) {
B int `json:"b,string"`
}{B: 2}},
},
{
name: "HeadIntMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A int `json:"a,string,omitempty"`
}
B struct {
B int `json:"b,string,omitempty"`
}
}{A: struct {
A int `json:"a,string,omitempty"`
}{A: -1}, B: struct {
B int `json:"b,string,omitempty"`
}{B: 2}},
},
// HeadIntPtrMultiFieldsNotRoot
{
@ -850,6 +1063,21 @@ func TestCoverInt(t *testing.T) {
B *int `json:"b,string"`
}{B: intptr(2)}},
},
{
name: "HeadIntPtrMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *int `json:"a,string,omitempty"`
}
B struct {
B *int `json:"b,string,omitempty"`
}
}{A: struct {
A *int `json:"a,string,omitempty"`
}{A: intptr(-1)}, B: struct {
B *int `json:"b,string,omitempty"`
}{B: intptr(2)}},
},
// HeadIntPtrNilMultiFieldsNotRoot
{
@ -897,6 +1125,21 @@ func TestCoverInt(t *testing.T) {
B *int `json:"b,string"`
}{B: nil}},
},
{
name: "HeadIntPtrNilMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *int `json:"a,string,omitempty"`
}
B struct {
B *int `json:"b,string,omitempty"`
}
}{A: struct {
A *int `json:"a,string,omitempty"`
}{A: nil}, B: struct {
B *int `json:"b,string,omitempty"`
}{B: nil}},
},
// PtrHeadIntZeroMultiFieldsNotRoot
{
@ -932,6 +1175,17 @@ func TestCoverInt(t *testing.T) {
}
}{},
},
{
name: "PtrHeadIntZeroMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A int `json:"a,string,omitempty"`
}
B struct {
B int `json:"b,string,omitempty"`
}
}{},
},
// PtrHeadIntMultiFieldsNotRoot
{
@ -979,6 +1233,21 @@ func TestCoverInt(t *testing.T) {
B int `json:"b,string"`
}{B: 2}},
},
{
name: "PtrHeadIntMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A int `json:"a,string,omitempty"`
}
B struct {
B int `json:"b,string,omitempty"`
}
}{A: struct {
A int `json:"a,string,omitempty"`
}{A: -1}, B: struct {
B int `json:"b,string,omitempty"`
}{B: 2}},
},
// PtrHeadIntPtrMultiFieldsNotRoot
{
@ -1026,6 +1295,21 @@ func TestCoverInt(t *testing.T) {
B *int `json:"b,string"`
}{B: intptr(2)})},
},
{
name: "PtrHeadIntPtrMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *int `json:"a,string,omitempty"`
}
B *struct {
B *int `json:"b,string,omitempty"`
}
}{A: &(struct {
A *int `json:"a,string,omitempty"`
}{A: intptr(-1)}), B: &(struct {
B *int `json:"b,string,omitempty"`
}{B: intptr(2)})},
},
// PtrHeadIntPtrNilMultiFieldsNotRoot
{
@ -1061,6 +1345,17 @@ func TestCoverInt(t *testing.T) {
} `json:",string"`
}{A: nil, B: nil},
},
{
name: "PtrHeadIntPtrNilMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *int `json:"a,string,omitempty"`
} `json:",string,omitempty"`
B *struct {
B *int `json:"b,string,omitempty"`
} `json:",string,omitempty"`
}{A: nil, B: nil},
},
// PtrHeadIntNilMultiFieldsNotRoot
{
@ -1096,6 +1391,17 @@ func TestCoverInt(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadIntNilMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *int `json:"a,string,omitempty"`
}
B *struct {
B *int `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadIntDoubleMultiFieldsNotRoot
{
@ -1155,6 +1461,25 @@ func TestCoverInt(t *testing.T) {
B int `json:"b,string"`
}{A: 3, B: 4})},
},
{
name: "PtrHeadIntDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A int `json:"a,string,omitempty"`
B int `json:"b,string,omitempty"`
}
B *struct {
A int `json:"a,string,omitempty"`
B int `json:"b,string,omitempty"`
}
}{A: &(struct {
A int `json:"a,string,omitempty"`
B int `json:"b,string,omitempty"`
}{A: -1, B: 2}), B: &(struct {
A int `json:"a,string,omitempty"`
B int `json:"b,string,omitempty"`
}{A: 3, B: 4})},
},
// PtrHeadIntNilDoubleMultiFieldsNotRoot
{
@ -1196,6 +1521,19 @@ func TestCoverInt(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadIntNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A int `json:"a,string,omitempty"`
B int `json:"b,string,omitempty"`
}
B *struct {
A int `json:"a,string,omitempty"`
B int `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadIntNilDoubleMultiFieldsNotRoot
{
@ -1237,6 +1575,19 @@ func TestCoverInt(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadIntNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A int `json:"a,string,omitempty"`
B int `json:"b,string,omitempty"`
}
B *struct {
A int `json:"a,string,omitempty"`
B int `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadIntPtrDoubleMultiFieldsNotRoot
{
@ -1296,6 +1647,25 @@ func TestCoverInt(t *testing.T) {
B *int `json:"b,string"`
}{A: intptr(3), B: intptr(4)})},
},
{
name: "PtrHeadIntPtrDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *int `json:"a,string,omitempty"`
B *int `json:"b,string,omitempty"`
}
B *struct {
A *int `json:"a,string,omitempty"`
B *int `json:"b,string,omitempty"`
}
}{A: &(struct {
A *int `json:"a,string,omitempty"`
B *int `json:"b,string,omitempty"`
}{A: intptr(-1), B: intptr(2)}), B: &(struct {
A *int `json:"a,string,omitempty"`
B *int `json:"b,string,omitempty"`
}{A: intptr(3), B: intptr(4)})},
},
// PtrHeadIntPtrNilDoubleMultiFieldsNotRoot
{
@ -1337,6 +1707,19 @@ func TestCoverInt(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadIntPtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *int `json:"a,string,omitempty"`
B *int `json:"b,string,omitempty"`
}
B *struct {
A *int `json:"a,string,omitempty"`
B *int `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadIntPtrNilDoubleMultiFieldsNotRoot
{
@ -1378,6 +1761,19 @@ func TestCoverInt(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadIntPtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *int `json:"a,string,omitempty"`
B *int `json:"b,string,omitempty"`
}
B *struct {
A *int `json:"a,string,omitempty"`
B *int `json:"b,string,omitempty"`
}
})(nil),
},
// AnonymousHeadInt
{
@ -1410,6 +1806,16 @@ func TestCoverInt(t *testing.T) {
B: 2,
},
},
{
name: "AnonymousHeadIntStringOmitEmpty",
data: struct {
structIntStringOmitEmpty
B int `json:"b,string,omitempty"`
}{
structIntStringOmitEmpty: structIntStringOmitEmpty{A: -1},
B: 2,
},
},
// PtrAnonymousHeadInt
{
@ -1442,6 +1848,16 @@ func TestCoverInt(t *testing.T) {
B: 2,
},
},
{
name: "PtrAnonymousHeadIntStringOmitEmpty",
data: struct {
*structIntStringOmitEmpty
B int `json:"b,string,omitempty"`
}{
structIntStringOmitEmpty: &structIntStringOmitEmpty{A: -1},
B: 2,
},
},
// NilPtrAnonymousHeadInt
{
@ -1474,6 +1890,16 @@ func TestCoverInt(t *testing.T) {
B: 2,
},
},
{
name: "NilPtrAnonymousHeadIntStringOmitEmpty",
data: struct {
*structIntStringOmitEmpty
B int `json:"b,string,omitempty"`
}{
structIntStringOmitEmpty: nil,
B: 2,
},
},
// AnonymousHeadIntPtr
{
@ -1506,6 +1932,16 @@ func TestCoverInt(t *testing.T) {
B: intptr(2),
},
},
{
name: "AnonymousHeadIntPtrStringOmitEmpty",
data: struct {
structIntPtrStringOmitEmpty
B *int `json:"b,string,omitempty"`
}{
structIntPtrStringOmitEmpty: structIntPtrStringOmitEmpty{A: intptr(-1)},
B: intptr(2),
},
},
// AnonymousHeadIntPtrNil
{
@ -1538,6 +1974,16 @@ func TestCoverInt(t *testing.T) {
B: intptr(2),
},
},
{
name: "AnonymousHeadIntPtrNilStringOmitEmpty",
data: struct {
structIntPtrStringOmitEmpty
B *int `json:"b,string,omitempty"`
}{
structIntPtrStringOmitEmpty: structIntPtrStringOmitEmpty{A: nil},
B: intptr(2),
},
},
// PtrAnonymousHeadIntPtr
{
@ -1570,6 +2016,16 @@ func TestCoverInt(t *testing.T) {
B: intptr(2),
},
},
{
name: "PtrAnonymousHeadIntPtrStringOmitEmpty",
data: struct {
*structIntPtrStringOmitEmpty
B *int `json:"b,string,omitempty"`
}{
structIntPtrStringOmitEmpty: &structIntPtrStringOmitEmpty{A: intptr(-1)},
B: intptr(2),
},
},
// NilPtrAnonymousHeadIntPtr
{
@ -1602,6 +2058,16 @@ func TestCoverInt(t *testing.T) {
B: intptr(2),
},
},
{
name: "NilPtrAnonymousHeadIntPtrStringOmitEmpty",
data: struct {
*structIntPtrStringOmitEmpty
B *int `json:"b,string,omitempty"`
}{
structIntPtrStringOmitEmpty: nil,
B: intptr(2),
},
},
// AnonymousHeadIntOnly
{
@ -1628,6 +2094,14 @@ func TestCoverInt(t *testing.T) {
structIntString: structIntString{A: -1},
},
},
{
name: "AnonymousHeadIntOnlyStringOmitEmpty",
data: struct {
structIntStringOmitEmpty
}{
structIntStringOmitEmpty: structIntStringOmitEmpty{A: -1},
},
},
// PtrAnonymousHeadIntOnly
{
@ -1654,6 +2128,14 @@ func TestCoverInt(t *testing.T) {
structIntString: &structIntString{A: -1},
},
},
{
name: "PtrAnonymousHeadIntOnlyStringOmitEmpty",
data: struct {
*structIntStringOmitEmpty
}{
structIntStringOmitEmpty: &structIntStringOmitEmpty{A: -1},
},
},
// NilPtrAnonymousHeadIntOnly
{
@ -1680,6 +2162,14 @@ func TestCoverInt(t *testing.T) {
structIntString: nil,
},
},
{
name: "NilPtrAnonymousHeadIntOnlyStringOmitEmpty",
data: struct {
*structIntStringOmitEmpty
}{
structIntStringOmitEmpty: nil,
},
},
// AnonymousHeadIntPtrOnly
{
@ -1706,6 +2196,14 @@ func TestCoverInt(t *testing.T) {
structIntPtrString: structIntPtrString{A: intptr(-1)},
},
},
{
name: "AnonymousHeadIntPtrOnlyStringOmitEmpty",
data: struct {
structIntPtrStringOmitEmpty
}{
structIntPtrStringOmitEmpty: structIntPtrStringOmitEmpty{A: intptr(-1)},
},
},
// AnonymousHeadIntPtrNilOnly
{
@ -1732,6 +2230,14 @@ func TestCoverInt(t *testing.T) {
structIntPtrString: structIntPtrString{A: nil},
},
},
{
name: "AnonymousHeadIntPtrNilOnlyStringOmitEmpty",
data: struct {
structIntPtrStringOmitEmpty
}{
structIntPtrStringOmitEmpty: structIntPtrStringOmitEmpty{A: nil},
},
},
// PtrAnonymousHeadIntPtrOnly
{
@ -1758,6 +2264,14 @@ func TestCoverInt(t *testing.T) {
structIntPtrString: &structIntPtrString{A: intptr(-1)},
},
},
{
name: "PtrAnonymousHeadIntPtrOnlyStringOmitEmpty",
data: struct {
*structIntPtrStringOmitEmpty
}{
structIntPtrStringOmitEmpty: &structIntPtrStringOmitEmpty{A: intptr(-1)},
},
},
// NilPtrAnonymousHeadIntPtrOnly
{
@ -1784,6 +2298,14 @@ func TestCoverInt(t *testing.T) {
structIntPtrString: nil,
},
},
{
name: "NilPtrAnonymousHeadIntPtrOnlyStringOmitEmpty",
data: struct {
*structIntPtrStringOmitEmpty
}{
structIntPtrStringOmitEmpty: nil,
},
},
}
for _, test := range tests {
for _, indent := range []bool{true, false} {

View File

@ -17,6 +17,9 @@ func TestCoverNumber(t *testing.T) {
type structNumberString struct {
A json.Number `json:"a,string"`
}
type structNumberStringOmitEmpty struct {
A json.Number `json:"a,string,omitempty"`
}
type structNumberPtr struct {
A *json.Number `json:"a"`
@ -27,6 +30,9 @@ func TestCoverNumber(t *testing.T) {
type structNumberPtrString struct {
A *json.Number `json:"a,string"`
}
type structNumberPtrStringOmitEmpty struct {
A *json.Number `json:"a,string,omitempty"`
}
tests := []struct {
name string
@ -72,6 +78,12 @@ func TestCoverNumber(t *testing.T) {
A json.Number `json:"a,string"`
}{},
},
{
name: "HeadNumberZeroStringOmitEmpty",
data: struct {
A json.Number `json:"a,string,omitempty"`
}{},
},
// HeadNumber
{
@ -92,6 +104,12 @@ func TestCoverNumber(t *testing.T) {
A json.Number `json:"a,string"`
}{A: "1"},
},
{
name: "HeadNumberStringOmitEmpty",
data: struct {
A json.Number `json:"a,string,omitempty"`
}{A: "1"},
},
// HeadNumberPtr
{
@ -112,6 +130,12 @@ func TestCoverNumber(t *testing.T) {
A *json.Number `json:"a,string"`
}{A: numberptr("1")},
},
{
name: "HeadNumberPtrStringOmitEmpty",
data: struct {
A *json.Number `json:"a,string,omitempty"`
}{A: numberptr("1")},
},
// HeadNumberPtrNil
{
@ -132,6 +156,12 @@ func TestCoverNumber(t *testing.T) {
A *json.Number `json:"a,string"`
}{A: nil},
},
{
name: "HeadNumberPtrNilStringOmitEmpty",
data: struct {
A *json.Number `json:"a,string,omitempty"`
}{A: nil},
},
// PtrHeadNumberZero
{
@ -152,6 +182,12 @@ func TestCoverNumber(t *testing.T) {
A json.Number `json:"a,string"`
}{},
},
{
name: "PtrHeadNumberZeroStringOmitEmpty",
data: &struct {
A json.Number `json:"a,string,omitempty"`
}{},
},
// PtrHeadNumber
{
@ -172,6 +208,12 @@ func TestCoverNumber(t *testing.T) {
A json.Number `json:"a,string"`
}{A: "1"},
},
{
name: "PtrHeadNumberStringOmitEmpty",
data: &struct {
A json.Number `json:"a,string,omitempty"`
}{A: "1"},
},
// PtrHeadNumberPtr
{
@ -192,6 +234,12 @@ func TestCoverNumber(t *testing.T) {
A *json.Number `json:"a,string"`
}{A: numberptr("1")},
},
{
name: "PtrHeadNumberPtrStringOmitEmpty",
data: &struct {
A *json.Number `json:"a,string,omitempty"`
}{A: numberptr("1")},
},
// PtrHeadNumberPtrNil
{
@ -212,6 +260,12 @@ func TestCoverNumber(t *testing.T) {
A *json.Number `json:"a,string"`
}{A: nil},
},
{
name: "PtrHeadNumberPtrNilStringOmitEmpty",
data: &struct {
A *json.Number `json:"a,string,omitempty"`
}{A: nil},
},
// PtrHeadNumberNil
{
@ -232,6 +286,12 @@ func TestCoverNumber(t *testing.T) {
A *json.Number `json:"a,string"`
})(nil),
},
{
name: "PtrHeadNumberNilStringOmitEmpty",
data: (*struct {
A *json.Number `json:"a,string,omitempty"`
})(nil),
},
// HeadNumberZeroMultiFields
{
@ -251,13 +311,21 @@ func TestCoverNumber(t *testing.T) {
}{},
},
{
name: "HeadNumberZeroMultiFields",
name: "HeadNumberZeroMultiFieldsString",
data: struct {
A json.Number `json:"a,string"`
B json.Number `json:"b,string"`
C json.Number `json:"c,string"`
}{},
},
{
name: "HeadNumberZeroMultiFieldsStringOmitEmpty",
data: struct {
A json.Number `json:"a,string,omitempty"`
B json.Number `json:"b,string,omitempty"`
C json.Number `json:"c,string,omitempty"`
}{},
},
// HeadNumberMultiFields
{
@ -284,6 +352,14 @@ func TestCoverNumber(t *testing.T) {
C json.Number `json:"c,string"`
}{A: "1", B: "2", C: "3"},
},
{
name: "HeadNumberMultiFieldsStringOmitEmpty",
data: struct {
A json.Number `json:"a,string,omitempty"`
B json.Number `json:"b,string,omitempty"`
C json.Number `json:"c,string,omitempty"`
}{A: "1", B: "2", C: "3"},
},
// HeadNumberPtrMultiFields
{
@ -310,6 +386,14 @@ func TestCoverNumber(t *testing.T) {
C *json.Number `json:"c,string"`
}{A: numberptr("1"), B: numberptr("2"), C: numberptr("3")},
},
{
name: "HeadNumberPtrMultiFieldsStringOmitEmpty",
data: struct {
A *json.Number `json:"a,string,omitempty"`
B *json.Number `json:"b,string,omitempty"`
C *json.Number `json:"c,string,omitempty"`
}{A: numberptr("1"), B: numberptr("2"), C: numberptr("3")},
},
// HeadNumberPtrNilMultiFields
{
@ -336,6 +420,14 @@ func TestCoverNumber(t *testing.T) {
C *json.Number `json:"c,string"`
}{A: nil, B: nil, C: nil},
},
{
name: "HeadNumberPtrNilMultiFieldsStringOmitEmpty",
data: struct {
A *json.Number `json:"a,string,omitempty"`
B *json.Number `json:"b,string,omitempty"`
C *json.Number `json:"c,string,omitempty"`
}{A: nil, B: nil, C: nil},
},
// PtrHeadNumberZeroMultiFields
{
@ -359,6 +451,13 @@ func TestCoverNumber(t *testing.T) {
B json.Number `json:"b,string"`
}{},
},
{
name: "PtrHeadNumberZeroMultiFieldsStringOmitEmpty",
data: &struct {
A json.Number `json:"a,string,omitempty"`
B json.Number `json:"b,string,omitempty"`
}{},
},
// PtrHeadNumberMultiFields
{
@ -382,6 +481,13 @@ func TestCoverNumber(t *testing.T) {
B json.Number `json:"b,string"`
}{A: "1", B: "2"},
},
{
name: "PtrHeadNumberMultiFieldsStringOmitEmpty",
data: &struct {
A json.Number `json:"a,string,omitempty"`
B json.Number `json:"b,string,omitempty"`
}{A: "1", B: "2"},
},
// PtrHeadNumberPtrMultiFields
{
@ -405,6 +511,13 @@ func TestCoverNumber(t *testing.T) {
B *json.Number `json:"b,string"`
}{A: numberptr("1"), B: numberptr("2")},
},
{
name: "PtrHeadNumberPtrMultiFieldsStringOmitEmpty",
data: &struct {
A *json.Number `json:"a,string,omitempty"`
B *json.Number `json:"b,string,omitempty"`
}{A: numberptr("1"), B: numberptr("2")},
},
// PtrHeadNumberPtrNilMultiFields
{
@ -428,6 +541,13 @@ func TestCoverNumber(t *testing.T) {
B *json.Number `json:"b,string"`
}{A: nil, B: nil},
},
{
name: "PtrHeadNumberPtrNilMultiFieldsStringOmitEmpty",
data: &struct {
A *json.Number `json:"a,string,omitempty"`
B *json.Number `json:"b,string,omitempty"`
}{A: nil, B: nil},
},
// PtrHeadNumberNilMultiFields
{
@ -451,6 +571,13 @@ func TestCoverNumber(t *testing.T) {
B *json.Number `json:"b,string"`
})(nil),
},
{
name: "PtrHeadNumberNilMultiFieldsStringOmitEmpty",
data: (*struct {
A *json.Number `json:"a,string,omitempty"`
B *json.Number `json:"b,string,omitempty"`
})(nil),
},
// HeadNumberZeroNotRoot
{
@ -477,6 +604,14 @@ func TestCoverNumber(t *testing.T) {
}
}{},
},
{
name: "HeadNumberZeroNotRootStringOmitEmpty",
data: struct {
A struct {
A json.Number `json:"a,string,omitempty"`
}
}{},
},
// HeadNumberNotRoot
{
@ -509,6 +644,16 @@ func TestCoverNumber(t *testing.T) {
A json.Number `json:"a,string"`
}{A: "1"}},
},
{
name: "HeadNumberNotRootStringOmitEmpty",
data: struct {
A struct {
A json.Number `json:"a,string,omitempty"`
}
}{A: struct {
A json.Number `json:"a,string,omitempty"`
}{A: "1"}},
},
// HeadNumberPtrNotRoot
{
@ -541,6 +686,16 @@ func TestCoverNumber(t *testing.T) {
A *json.Number `json:"a,string"`
}{numberptr("1")}},
},
{
name: "HeadNumberPtrNotRootStringOmitEmpty",
data: struct {
A struct {
A *json.Number `json:"a,string,omitempty"`
}
}{A: struct {
A *json.Number `json:"a,string,omitempty"`
}{numberptr("1")}},
},
// HeadNumberPtrNilNotRoot
{
@ -567,6 +722,14 @@ func TestCoverNumber(t *testing.T) {
}
}{},
},
{
name: "HeadNumberPtrNilNotRootStringOmitEmpty",
data: struct {
A struct {
A *json.Number `json:"a,string,omitempty"`
}
}{},
},
// PtrHeadNumberZeroNotRoot
{
@ -599,6 +762,16 @@ func TestCoverNumber(t *testing.T) {
A json.Number `json:"a,string"`
})},
},
{
name: "PtrHeadNumberZeroNotRootStringOmitEmpty",
data: struct {
A *struct {
A json.Number `json:"a,string,omitempty"`
}
}{A: new(struct {
A json.Number `json:"a,string,omitempty"`
})},
},
// PtrHeadNumberNotRoot
{
@ -631,6 +804,16 @@ func TestCoverNumber(t *testing.T) {
A json.Number `json:"a,string"`
}{A: "1"})},
},
{
name: "PtrHeadNumberNotRootStringOmitEmpty",
data: struct {
A *struct {
A json.Number `json:"a,string,omitempty"`
}
}{A: &(struct {
A json.Number `json:"a,string,omitempty"`
}{A: "1"})},
},
// PtrHeadNumberPtrNotRoot
{
@ -663,6 +846,16 @@ func TestCoverNumber(t *testing.T) {
A *json.Number `json:"a,string"`
}{A: numberptr("1")})},
},
{
name: "PtrHeadNumberPtrNotRootStringOmitEmpty",
data: struct {
A *struct {
A *json.Number `json:"a,string,omitempty"`
}
}{A: &(struct {
A *json.Number `json:"a,string,omitempty"`
}{A: numberptr("1")})},
},
// PtrHeadNumberPtrNilNotRoot
{
@ -695,6 +888,16 @@ func TestCoverNumber(t *testing.T) {
A *json.Number `json:"a,string"`
}{A: nil})},
},
{
name: "PtrHeadNumberPtrNilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *json.Number `json:"a,string,omitempty"`
}
}{A: &(struct {
A *json.Number `json:"a,string,omitempty"`
}{A: nil})},
},
// PtrHeadNumberNilNotRoot
{
@ -721,6 +924,14 @@ func TestCoverNumber(t *testing.T) {
} `json:",string"`
}{A: nil},
},
{
name: "PtrHeadNumberNilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *json.Number `json:"a,string,omitempty"`
} `json:",string,omitempty"`
}{A: nil},
},
// HeadNumberZeroMultiFieldsNotRoot
{
@ -756,6 +967,17 @@ func TestCoverNumber(t *testing.T) {
}
}{},
},
{
name: "HeadNumberZeroMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A json.Number `json:"a,string,omitempty"`
}
B struct {
B json.Number `json:"b,string,omitempty"`
}
}{},
},
// HeadNumberMultiFieldsNotRoot
{
@ -803,6 +1025,21 @@ func TestCoverNumber(t *testing.T) {
B json.Number `json:"b,string"`
}{B: "2"}},
},
{
name: "HeadNumberMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A json.Number `json:"a,string,omitempty"`
}
B struct {
B json.Number `json:"b,string,omitempty"`
}
}{A: struct {
A json.Number `json:"a,string,omitempty"`
}{A: "1"}, B: struct {
B json.Number `json:"b,string,omitempty"`
}{B: "2"}},
},
// HeadNumberPtrMultiFieldsNotRoot
{
@ -850,6 +1087,21 @@ func TestCoverNumber(t *testing.T) {
B *json.Number `json:"b,string"`
}{B: numberptr("2")}},
},
{
name: "HeadNumberPtrMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *json.Number `json:"a,string,omitempty"`
}
B struct {
B *json.Number `json:"b,string,omitempty"`
}
}{A: struct {
A *json.Number `json:"a,string,omitempty"`
}{A: numberptr("1")}, B: struct {
B *json.Number `json:"b,string,omitempty"`
}{B: numberptr("2")}},
},
// HeadNumberPtrNilMultiFieldsNotRoot
{
@ -897,6 +1149,21 @@ func TestCoverNumber(t *testing.T) {
B *json.Number `json:"b,string"`
}{B: nil}},
},
{
name: "HeadNumberPtrNilMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *json.Number `json:"a,string,omitempty"`
}
B struct {
B *json.Number `json:"b,string,omitempty"`
}
}{A: struct {
A *json.Number `json:"a,string,omitempty"`
}{A: nil}, B: struct {
B *json.Number `json:"b,string,omitempty"`
}{B: nil}},
},
// PtrHeadNumberZeroMultiFieldsNotRoot
{
@ -932,6 +1199,17 @@ func TestCoverNumber(t *testing.T) {
}
}{},
},
{
name: "PtrHeadNumberZeroMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A json.Number `json:"a,string,omitempty"`
}
B struct {
B json.Number `json:"b,string,omitempty"`
}
}{},
},
// PtrHeadNumberMultiFieldsNotRoot
{
@ -979,6 +1257,21 @@ func TestCoverNumber(t *testing.T) {
B json.Number `json:"b,string"`
}{B: "2"}},
},
{
name: "PtrHeadNumberMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A json.Number `json:"a,string,omitempty"`
}
B struct {
B json.Number `json:"b,string,omitempty"`
}
}{A: struct {
A json.Number `json:"a,string,omitempty"`
}{A: "1"}, B: struct {
B json.Number `json:"b,string,omitempty"`
}{B: "2"}},
},
// PtrHeadNumberPtrMultiFieldsNotRoot
{
@ -1026,6 +1319,21 @@ func TestCoverNumber(t *testing.T) {
B *json.Number `json:"b,string"`
}{B: numberptr("2")})},
},
{
name: "PtrHeadNumberPtrMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *json.Number `json:"a,string,omitempty"`
}
B *struct {
B *json.Number `json:"b,string,omitempty"`
}
}{A: &(struct {
A *json.Number `json:"a,string,omitempty"`
}{A: numberptr("1")}), B: &(struct {
B *json.Number `json:"b,string,omitempty"`
}{B: numberptr("2")})},
},
// PtrHeadNumberPtrNilMultiFieldsNotRoot
{
@ -1061,6 +1369,17 @@ func TestCoverNumber(t *testing.T) {
} `json:",string"`
}{A: nil, B: nil},
},
{
name: "PtrHeadNumberPtrNilMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *json.Number `json:"a,string,omitempty"`
} `json:",string,omitempty"`
B *struct {
B *json.Number `json:"b,string,omitempty"`
} `json:",string,omitempty"`
}{A: nil, B: nil},
},
// PtrHeadNumberNilMultiFieldsNotRoot
{
@ -1096,6 +1415,17 @@ func TestCoverNumber(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadNumberNilMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *json.Number `json:"a,string,omitempty"`
}
B *struct {
B *json.Number `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadNumberDoubleMultiFieldsNotRoot
{
@ -1155,6 +1485,25 @@ func TestCoverNumber(t *testing.T) {
B json.Number `json:"b,string"`
}{A: "3", B: "4"})},
},
{
name: "PtrHeadNumberDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A json.Number `json:"a,string,omitempty"`
B json.Number `json:"b,string,omitempty"`
}
B *struct {
A json.Number `json:"a,string,omitempty"`
B json.Number `json:"b,string,omitempty"`
}
}{A: &(struct {
A json.Number `json:"a,string,omitempty"`
B json.Number `json:"b,string,omitempty"`
}{A: "1", B: "2"}), B: &(struct {
A json.Number `json:"a,string,omitempty"`
B json.Number `json:"b,string,omitempty"`
}{A: "3", B: "4"})},
},
// PtrHeadNumberNilDoubleMultiFieldsNotRoot
{
@ -1196,6 +1545,19 @@ func TestCoverNumber(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadNumberNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A json.Number `json:"a,string,omitempty"`
B json.Number `json:"b,string,omitempty"`
}
B *struct {
A json.Number `json:"a,string,omitempty"`
B json.Number `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadNumberNilDoubleMultiFieldsNotRoot
{
@ -1237,6 +1599,19 @@ func TestCoverNumber(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadNumberNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A json.Number `json:"a,string,omitempty"`
B json.Number `json:"b,string,omitempty"`
}
B *struct {
A json.Number `json:"a,string,omitempty"`
B json.Number `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadNumberPtrDoubleMultiFieldsNotRoot
{
@ -1296,6 +1671,25 @@ func TestCoverNumber(t *testing.T) {
B *json.Number `json:"b,string"`
}{A: numberptr("3"), B: numberptr("4")})},
},
{
name: "PtrHeadNumberPtrDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *json.Number `json:"a,string,omitempty"`
B *json.Number `json:"b,string,omitempty"`
}
B *struct {
A *json.Number `json:"a,string,omitempty"`
B *json.Number `json:"b,string,omitempty"`
}
}{A: &(struct {
A *json.Number `json:"a,string,omitempty"`
B *json.Number `json:"b,string,omitempty"`
}{A: numberptr("1"), B: numberptr("2")}), B: &(struct {
A *json.Number `json:"a,string,omitempty"`
B *json.Number `json:"b,string,omitempty"`
}{A: numberptr("3"), B: numberptr("4")})},
},
// PtrHeadNumberPtrNilDoubleMultiFieldsNotRoot
{
@ -1337,6 +1731,19 @@ func TestCoverNumber(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadNumberPtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *json.Number `json:"a,string,omitempty"`
B *json.Number `json:"b,string,omitempty"`
}
B *struct {
A *json.Number `json:"a,string,omitempty"`
B *json.Number `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadNumberPtrNilDoubleMultiFieldsNotRoot
{
@ -1378,6 +1785,19 @@ func TestCoverNumber(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadNumberPtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *json.Number `json:"a,string,omitempty"`
B *json.Number `json:"b,string,omitempty"`
}
B *struct {
A *json.Number `json:"a,string,omitempty"`
B *json.Number `json:"b,string,omitempty"`
}
})(nil),
},
// AnonymousHeadNumber
{
@ -1410,6 +1830,16 @@ func TestCoverNumber(t *testing.T) {
B: "2",
},
},
{
name: "AnonymousHeadNumberStringOmitEmpty",
data: struct {
structNumberStringOmitEmpty
B json.Number `json:"b,string,omitempty"`
}{
structNumberStringOmitEmpty: structNumberStringOmitEmpty{A: "1"},
B: "2",
},
},
// PtrAnonymousHeadNumber
{
@ -1442,6 +1872,16 @@ func TestCoverNumber(t *testing.T) {
B: "2",
},
},
{
name: "PtrAnonymousHeadNumberStringOmitEmpty",
data: struct {
*structNumberStringOmitEmpty
B json.Number `json:"b,string,omitempty"`
}{
structNumberStringOmitEmpty: &structNumberStringOmitEmpty{A: "1"},
B: "2",
},
},
// NilPtrAnonymousHeadNumber
{
@ -1474,6 +1914,16 @@ func TestCoverNumber(t *testing.T) {
B: "2",
},
},
{
name: "NilPtrAnonymousHeadNumberStringOmitEmpty",
data: struct {
*structNumberStringOmitEmpty
B json.Number `json:"b,string,omitempty"`
}{
structNumberStringOmitEmpty: nil,
B: "2",
},
},
// AnonymousHeadNumberPtr
{
@ -1506,6 +1956,16 @@ func TestCoverNumber(t *testing.T) {
B: numberptr("2"),
},
},
{
name: "AnonymousHeadNumberPtrStringOmitEmpty",
data: struct {
structNumberPtrStringOmitEmpty
B *json.Number `json:"b,string,omitempty"`
}{
structNumberPtrStringOmitEmpty: structNumberPtrStringOmitEmpty{A: numberptr("1")},
B: numberptr("2"),
},
},
// AnonymousHeadNumberPtrNil
{
@ -1538,6 +1998,16 @@ func TestCoverNumber(t *testing.T) {
B: numberptr("2"),
},
},
{
name: "AnonymousHeadNumberPtrNilStringOmitEmpty",
data: struct {
structNumberPtrStringOmitEmpty
B *json.Number `json:"b,string,omitempty"`
}{
structNumberPtrStringOmitEmpty: structNumberPtrStringOmitEmpty{A: nil},
B: numberptr("2"),
},
},
// PtrAnonymousHeadNumberPtr
{
@ -1570,6 +2040,16 @@ func TestCoverNumber(t *testing.T) {
B: numberptr("2"),
},
},
{
name: "PtrAnonymousHeadNumberPtrStringOmitEmpty",
data: struct {
*structNumberPtrStringOmitEmpty
B *json.Number `json:"b,string,omitempty"`
}{
structNumberPtrStringOmitEmpty: &structNumberPtrStringOmitEmpty{A: numberptr("1")},
B: numberptr("2"),
},
},
// NilPtrAnonymousHeadNumberPtr
{
@ -1602,6 +2082,16 @@ func TestCoverNumber(t *testing.T) {
B: numberptr("2"),
},
},
{
name: "NilPtrAnonymousHeadNumberPtrStringOmitEmpty",
data: struct {
*structNumberPtrStringOmitEmpty
B *json.Number `json:"b,string,omitempty"`
}{
structNumberPtrStringOmitEmpty: nil,
B: numberptr("2"),
},
},
// AnonymousHeadNumberOnly
{
@ -1628,6 +2118,14 @@ func TestCoverNumber(t *testing.T) {
structNumberString: structNumberString{A: "1"},
},
},
{
name: "AnonymousHeadNumberOnlyStringOmitEmpty",
data: struct {
structNumberStringOmitEmpty
}{
structNumberStringOmitEmpty: structNumberStringOmitEmpty{A: "1"},
},
},
// PtrAnonymousHeadNumberOnly
{
@ -1654,6 +2152,14 @@ func TestCoverNumber(t *testing.T) {
structNumberString: &structNumberString{A: "1"},
},
},
{
name: "PtrAnonymousHeadNumberOnlyStringOmitEmpty",
data: struct {
*structNumberStringOmitEmpty
}{
structNumberStringOmitEmpty: &structNumberStringOmitEmpty{A: "1"},
},
},
// NilPtrAnonymousHeadNumberOnly
{
@ -1680,6 +2186,14 @@ func TestCoverNumber(t *testing.T) {
structNumberString: nil,
},
},
{
name: "NilPtrAnonymousHeadNumberOnlyStringOmitEmpty",
data: struct {
*structNumberStringOmitEmpty
}{
structNumberStringOmitEmpty: nil,
},
},
// AnonymousHeadNumberPtrOnly
{
@ -1706,6 +2220,14 @@ func TestCoverNumber(t *testing.T) {
structNumberPtrString: structNumberPtrString{A: numberptr("1")},
},
},
{
name: "AnonymousHeadNumberPtrOnlyStringOmitEmpty",
data: struct {
structNumberPtrStringOmitEmpty
}{
structNumberPtrStringOmitEmpty: structNumberPtrStringOmitEmpty{A: numberptr("1")},
},
},
// AnonymousHeadNumberPtrNilOnly
{
@ -1732,6 +2254,14 @@ func TestCoverNumber(t *testing.T) {
structNumberPtrString: structNumberPtrString{A: nil},
},
},
{
name: "AnonymousHeadNumberPtrNilOnlyStringOmitEmpty",
data: struct {
structNumberPtrStringOmitEmpty
}{
structNumberPtrStringOmitEmpty: structNumberPtrStringOmitEmpty{A: nil},
},
},
// PtrAnonymousHeadNumberPtrOnly
{
@ -1758,6 +2288,14 @@ func TestCoverNumber(t *testing.T) {
structNumberPtrString: &structNumberPtrString{A: numberptr("1")},
},
},
{
name: "PtrAnonymousHeadNumberPtrOnlyStringOmitEmpty",
data: struct {
*structNumberPtrStringOmitEmpty
}{
structNumberPtrStringOmitEmpty: &structNumberPtrStringOmitEmpty{A: numberptr("1")},
},
},
// NilPtrAnonymousHeadNumberPtrOnly
{
@ -1784,6 +2322,14 @@ func TestCoverNumber(t *testing.T) {
structNumberPtrString: nil,
},
},
{
name: "NilPtrAnonymousHeadNumberPtrOnlyStringOmitEmpty",
data: struct {
*structNumberPtrStringOmitEmpty
}{
structNumberPtrStringOmitEmpty: nil,
},
},
}
for _, test := range tests {
for _, indent := range []bool{true, false} {

View File

@ -17,6 +17,9 @@ func TestCoverString(t *testing.T) {
type structStringString struct {
A string `json:"a,string"`
}
type structStringStringOmitEmpty struct {
A string `json:"a,string,omitempty"`
}
type structStringPtr struct {
A *string `json:"a"`
@ -27,6 +30,9 @@ func TestCoverString(t *testing.T) {
type structStringPtrString struct {
A *string `json:"a,string"`
}
type structStringPtrStringOmitEmpty struct {
A *string `json:"a,string,omitempty"`
}
tests := []struct {
name string
@ -84,6 +90,12 @@ func TestCoverString(t *testing.T) {
A string `json:"a,string"`
}{},
},
{
name: "HeadStringZeroStringOmitEmpty",
data: struct {
A string `json:"a,string,omitempty"`
}{},
},
// HeadString
{
@ -104,6 +116,12 @@ func TestCoverString(t *testing.T) {
A string `json:"a,string"`
}{A: "foo"},
},
{
name: "HeadStringStringOmitEmpty",
data: struct {
A string `json:"a,string,omitempty"`
}{A: "foo"},
},
// HeadStringPtr
{
@ -124,6 +142,12 @@ func TestCoverString(t *testing.T) {
A *string `json:"a,string"`
}{A: stringptr("foo")},
},
{
name: "HeadStringPtrStringOmitEmpty",
data: struct {
A *string `json:"a,string,omitempty"`
}{A: stringptr("foo")},
},
// HeadStringPtrNil
{
@ -144,6 +168,12 @@ func TestCoverString(t *testing.T) {
A *string `json:"a,string"`
}{A: nil},
},
{
name: "HeadStringPtrNilStringOmitEmpty",
data: struct {
A *string `json:"a,string,omitempty"`
}{A: nil},
},
// PtrHeadStringZero
{
@ -164,6 +194,12 @@ func TestCoverString(t *testing.T) {
A string `json:"a,string"`
}{},
},
{
name: "PtrHeadStringZeroStringOmitEmpty",
data: &struct {
A string `json:"a,string,omitempty"`
}{},
},
// PtrHeadString
{
@ -184,6 +220,12 @@ func TestCoverString(t *testing.T) {
A string `json:"a,string"`
}{A: "foo"},
},
{
name: "PtrHeadStringStringOmitEmpty",
data: &struct {
A string `json:"a,string,omitempty"`
}{A: "foo"},
},
// PtrHeadStringPtr
{
@ -204,6 +246,12 @@ func TestCoverString(t *testing.T) {
A *string `json:"a,string"`
}{A: stringptr("foo")},
},
{
name: "PtrHeadStringPtrStringOmitEmpty",
data: &struct {
A *string `json:"a,string,omitempty"`
}{A: stringptr("foo")},
},
// PtrHeadStringPtrNil
{
@ -224,6 +272,12 @@ func TestCoverString(t *testing.T) {
A *string `json:"a,string"`
}{A: nil},
},
{
name: "PtrHeadStringPtrNilStringOmitEmpty",
data: &struct {
A *string `json:"a,string,omitempty"`
}{A: nil},
},
// PtrHeadStringNil
{
@ -244,6 +298,12 @@ func TestCoverString(t *testing.T) {
A *string `json:"a,string"`
})(nil),
},
{
name: "PtrHeadStringNilStringOmitEmpty",
data: (*struct {
A *string `json:"a,string,omitempty"`
})(nil),
},
// HeadStringZeroMultiFields
{
@ -270,6 +330,14 @@ func TestCoverString(t *testing.T) {
C string `json:"c,string"`
}{},
},
{
name: "HeadStringZeroMultiFieldsStringOmitEmpty",
data: struct {
A string `json:"a,string,omitempty"`
B string `json:"b,string,omitempty"`
C string `json:"c,string,omitempty"`
}{},
},
// HeadStringMultiFields
{
@ -296,6 +364,14 @@ func TestCoverString(t *testing.T) {
C string `json:"c,string"`
}{A: "foo", B: "bar", C: "baz"},
},
{
name: "HeadStringMultiFieldsStringOmitEmpty",
data: struct {
A string `json:"a,string,omitempty"`
B string `json:"b,string,omitempty"`
C string `json:"c,string,omitempty"`
}{A: "foo", B: "bar", C: "baz"},
},
// HeadStringPtrMultiFields
{
@ -322,6 +398,14 @@ func TestCoverString(t *testing.T) {
C *string `json:"c,string"`
}{A: stringptr("foo"), B: stringptr("bar"), C: stringptr("baz")},
},
{
name: "HeadStringPtrMultiFieldsStringOmitEmpty",
data: struct {
A *string `json:"a,string,omitempty"`
B *string `json:"b,string,omitempty"`
C *string `json:"c,string,omitempty"`
}{A: stringptr("foo"), B: stringptr("bar"), C: stringptr("baz")},
},
// HeadStringPtrNilMultiFields
{
@ -348,6 +432,14 @@ func TestCoverString(t *testing.T) {
C *string `json:"c,string"`
}{A: nil, B: nil, C: nil},
},
{
name: "HeadStringPtrNilMultiFieldsStringOmitEmpty",
data: struct {
A *string `json:"a,string,omitempty"`
B *string `json:"b,string,omitempty"`
C *string `json:"c,string,omitempty"`
}{A: nil, B: nil, C: nil},
},
// PtrHeadStringZeroMultiFields
{
@ -374,6 +466,14 @@ func TestCoverString(t *testing.T) {
C string `json:"c,string"`
}{},
},
{
name: "PtrHeadStringZeroMultiFieldsStringOmitEmpty",
data: &struct {
A string `json:"a,string,omitempty"`
B string `json:"b,string,omitempty"`
C string `json:"c,string,omitempty"`
}{},
},
// PtrHeadStringMultiFields
{
@ -400,6 +500,14 @@ func TestCoverString(t *testing.T) {
C string `json:"c,string"`
}{A: "foo", B: "bar", C: "baz"},
},
{
name: "PtrHeadStringMultiFieldsStringOmitEmpty",
data: &struct {
A string `json:"a,string,omitempty"`
B string `json:"b,string,omitempty"`
C string `json:"c,string,omitempty"`
}{A: "foo", B: "bar", C: "baz"},
},
// PtrHeadStringPtrMultiFields
{
@ -426,6 +534,14 @@ func TestCoverString(t *testing.T) {
C *string `json:"c,string"`
}{A: stringptr("foo"), B: stringptr("bar"), C: stringptr("baz")},
},
{
name: "PtrHeadStringPtrMultiFieldsStringOmitEmpty",
data: &struct {
A *string `json:"a,string,omitempty"`
B *string `json:"b,string,omitempty"`
C *string `json:"c,string,omitempty"`
}{A: stringptr("foo"), B: stringptr("bar"), C: stringptr("baz")},
},
// PtrHeadStringPtrNilMultiFields
{
@ -452,6 +568,14 @@ func TestCoverString(t *testing.T) {
C *string `json:"c,string"`
}{A: nil, B: nil, C: nil},
},
{
name: "PtrHeadStringPtrNilMultiFieldsStringOmitEmpty",
data: &struct {
A *string `json:"a,string,omitempty"`
B *string `json:"b,string,omitempty"`
C *string `json:"c,string,omitempty"`
}{A: nil, B: nil, C: nil},
},
// PtrHeadStringNilMultiFields
{
@ -478,6 +602,14 @@ func TestCoverString(t *testing.T) {
C *string `json:"c,string"`
})(nil),
},
{
name: "PtrHeadStringNilMultiFieldsStringOmitEmpty",
data: (*struct {
A *string `json:"a,string,omitempty"`
B *string `json:"b,string,omitempty"`
C *string `json:"c,string,omitempty"`
})(nil),
},
// HeadStringZeroNotRoot
{
@ -504,6 +636,14 @@ func TestCoverString(t *testing.T) {
}
}{},
},
{
name: "HeadStringZeroNotRootStringOmitEmpty",
data: struct {
A struct {
A string `json:"a,string,omitempty"`
}
}{},
},
// HeadStringNotRoot
{
@ -536,6 +676,16 @@ func TestCoverString(t *testing.T) {
A string `json:"a,string"`
}{A: "foo"}},
},
{
name: "HeadStringNotRootStringOmitEmpty",
data: struct {
A struct {
A string `json:"a,string,omitempty"`
}
}{A: struct {
A string `json:"a,string,omitempty"`
}{A: "foo"}},
},
// HeadStringPtrNotRoot
{
@ -568,6 +718,16 @@ func TestCoverString(t *testing.T) {
A *string `json:"a,string"`
}{stringptr("foo")}},
},
{
name: "HeadStringPtrNotRootStringOmitEmpty",
data: struct {
A struct {
A *string `json:"a,string,omitempty"`
}
}{A: struct {
A *string `json:"a,string,omitempty"`
}{stringptr("foo")}},
},
// HeadStringPtrNilNotRoot
{
@ -594,6 +754,14 @@ func TestCoverString(t *testing.T) {
}
}{},
},
{
name: "HeadStringPtrNilNotRootStringOmitEmpty",
data: struct {
A struct {
A *string `json:"a,string,omitempty"`
}
}{},
},
// PtrHeadStringZeroNotRoot
{
@ -626,6 +794,16 @@ func TestCoverString(t *testing.T) {
A string `json:"a,string"`
})},
},
{
name: "PtrHeadStringZeroNotRootStringOmitEmpty",
data: struct {
A *struct {
A string `json:"a,string,omitempty"`
}
}{A: new(struct {
A string `json:"a,string,omitempty"`
})},
},
// PtrHeadStringNotRoot
{
@ -658,6 +836,16 @@ func TestCoverString(t *testing.T) {
A string `json:"a,string"`
}{A: "foo"})},
},
{
name: "PtrHeadStringNotRootStringOmitEmpty",
data: struct {
A *struct {
A string `json:"a,string,omitempty"`
}
}{A: &(struct {
A string `json:"a,string,omitempty"`
}{A: "foo"})},
},
// PtrHeadStringPtrNotRoot
{
@ -690,6 +878,16 @@ func TestCoverString(t *testing.T) {
A *string `json:"a,string"`
}{A: stringptr("foo")})},
},
{
name: "PtrHeadStringPtrNotRootStringOmitEmpty",
data: struct {
A *struct {
A *string `json:"a,string,omitempty"`
}
}{A: &(struct {
A *string `json:"a,string,omitempty"`
}{A: stringptr("foo")})},
},
// PtrHeadStringPtrNilNotRoot
{
@ -722,6 +920,16 @@ func TestCoverString(t *testing.T) {
A *string `json:"a,string"`
}{A: nil})},
},
{
name: "PtrHeadStringPtrNilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *string `json:"a,string,omitempty"`
}
}{A: &(struct {
A *string `json:"a,string,omitempty"`
}{A: nil})},
},
// PtrHeadStringNilNotRoot
{
@ -748,6 +956,14 @@ func TestCoverString(t *testing.T) {
} `json:",string"`
}{A: nil},
},
{
name: "PtrHeadStringNilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *string `json:"a,string,omitempty"`
} `json:",string,omitempty"`
}{A: nil},
},
// HeadStringZeroMultiFieldsNotRoot
{
@ -783,6 +999,17 @@ func TestCoverString(t *testing.T) {
}
}{},
},
{
name: "HeadStringZeroMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A string `json:"a,string,omitempty"`
}
B struct {
B string `json:"b,string,omitempty"`
}
}{},
},
// HeadStringMultiFieldsNotRoot
{
@ -830,6 +1057,21 @@ func TestCoverString(t *testing.T) {
B string `json:"b,string"`
}{B: "bar"}},
},
{
name: "HeadStringMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A string `json:"a,string,omitempty"`
}
B struct {
B string `json:"b,string,omitempty"`
}
}{A: struct {
A string `json:"a,string,omitempty"`
}{A: "foo"}, B: struct {
B string `json:"b,string,omitempty"`
}{B: "bar"}},
},
// HeadStringPtrMultiFieldsNotRoot
{
@ -877,6 +1119,21 @@ func TestCoverString(t *testing.T) {
B *string `json:"b,string"`
}{B: stringptr("bar")}},
},
{
name: "HeadStringPtrMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *string `json:"a,string,omitempty"`
}
B struct {
B *string `json:"b,string,omitempty"`
}
}{A: struct {
A *string `json:"a,string,omitempty"`
}{A: stringptr("foo")}, B: struct {
B *string `json:"b,string,omitempty"`
}{B: stringptr("bar")}},
},
// HeadStringPtrNilMultiFieldsNotRoot
{
@ -924,6 +1181,21 @@ func TestCoverString(t *testing.T) {
B *string `json:"b,string"`
}{B: nil}},
},
{
name: "HeadStringPtrNilMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *string `json:"a,string,omitempty"`
}
B struct {
B *string `json:"b,string,omitempty"`
}
}{A: struct {
A *string `json:"a,string,omitempty"`
}{A: nil}, B: struct {
B *string `json:"b,string,omitempty"`
}{B: nil}},
},
// PtrHeadStringZeroMultiFieldsNotRoot
{
@ -959,6 +1231,17 @@ func TestCoverString(t *testing.T) {
}
}{},
},
{
name: "PtrHeadStringZeroMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A string `json:"a,string,omitempty"`
}
B struct {
B string `json:"b,string,omitempty"`
}
}{},
},
// PtrHeadStringMultiFieldsNotRoot
{
@ -1006,6 +1289,21 @@ func TestCoverString(t *testing.T) {
B string `json:"b,string"`
}{B: "bar"}},
},
{
name: "PtrHeadStringMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A string `json:"a,string,omitempty"`
}
B struct {
B string `json:"b,string,omitempty"`
}
}{A: struct {
A string `json:"a,string,omitempty"`
}{A: "foo"}, B: struct {
B string `json:"b,string,omitempty"`
}{B: "bar"}},
},
// PtrHeadStringPtrMultiFieldsNotRoot
{
@ -1053,6 +1351,21 @@ func TestCoverString(t *testing.T) {
B *string `json:"b,string"`
}{B: stringptr("bar")})},
},
{
name: "PtrHeadStringPtrMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *string `json:"a,string,omitempty"`
}
B *struct {
B *string `json:"b,string,omitempty"`
}
}{A: &(struct {
A *string `json:"a,string,omitempty"`
}{A: stringptr("foo")}), B: &(struct {
B *string `json:"b,string,omitempty"`
}{B: stringptr("bar")})},
},
// PtrHeadStringPtrNilMultiFieldsNotRoot
{
@ -1088,6 +1401,17 @@ func TestCoverString(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadStringPtrNilMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *string `json:"a,string,omitempty"`
}
B *struct {
B *string `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadStringNilMultiFieldsNotRoot
{
@ -1123,6 +1447,17 @@ func TestCoverString(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadStringNilMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *string `json:"a,string,omitempty"`
}
B *struct {
B *string `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadStringDoubleMultiFieldsNotRoot
{
@ -1186,6 +1521,25 @@ func TestCoverString(t *testing.T) {
B string `json:"b,string"`
}{A: "foo", B: "bar"})},
},
{
name: "PtrHeadStringDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A string `json:"a,string,omitempty"`
B string `json:"b,string,omitempty"`
}
B *struct {
A string `json:"a,string,omitempty"`
B string `json:"b,string,omitempty"`
}
}{A: &(struct {
A string `json:"a,string,omitempty"`
B string `json:"b,string,omitempty"`
}{A: "foo", B: "bar"}), B: &(struct {
A string `json:"a,string,omitempty"`
B string `json:"b,string,omitempty"`
}{A: "foo", B: "bar"})},
},
// PtrHeadStringNilDoubleMultiFieldsNotRoot
{
@ -1227,6 +1581,19 @@ func TestCoverString(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadStringNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A string `json:"a,string,omitempty"`
B string `json:"b,string,omitempty"`
}
B *struct {
A string `json:"a,string,omitempty"`
B string `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadStringNilDoubleMultiFieldsNotRoot
{
@ -1268,6 +1635,19 @@ func TestCoverString(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadStringNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A string `json:"a,string,omitempty"`
B string `json:"b,string,omitempty"`
}
B *struct {
A string `json:"a,string,omitempty"`
B string `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadStringPtrDoubleMultiFieldsNotRoot
{
@ -1327,6 +1707,25 @@ func TestCoverString(t *testing.T) {
B *string `json:"b,string"`
}{A: stringptr("foo"), B: stringptr("bar")})},
},
{
name: "PtrHeadStringPtrDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *string `json:"a,string,omitempty"`
B *string `json:"b,string,omitempty"`
}
B *struct {
A *string `json:"a,string,omitempty"`
B *string `json:"b,string,omitempty"`
}
}{A: &(struct {
A *string `json:"a,string,omitempty"`
B *string `json:"b,string,omitempty"`
}{A: stringptr("foo"), B: stringptr("bar")}), B: &(struct {
A *string `json:"a,string,omitempty"`
B *string `json:"b,string,omitempty"`
}{A: stringptr("foo"), B: stringptr("bar")})},
},
// PtrHeadStringPtrNilDoubleMultiFieldsNotRoot
{
@ -1368,6 +1767,19 @@ func TestCoverString(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadStringPtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *string `json:"a,string,omitempty"`
B *string `json:"b,string,omitempty"`
}
B *struct {
A *string `json:"a,string,omitempty"`
B *string `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadStringPtrNilDoubleMultiFieldsNotRoot
{
@ -1409,6 +1821,19 @@ func TestCoverString(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadStringPtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *string `json:"a,string,omitempty"`
B *string `json:"b,string,omitempty"`
}
B *struct {
A *string `json:"a,string,omitempty"`
B *string `json:"b,string,omitempty"`
}
})(nil),
},
// AnonymousHeadString
{
@ -1441,6 +1866,16 @@ func TestCoverString(t *testing.T) {
B: "bar",
},
},
{
name: "AnonymousHeadStringStringOmitEmpty",
data: struct {
structStringStringOmitEmpty
B string `json:"b,string,omitempty"`
}{
structStringStringOmitEmpty: structStringStringOmitEmpty{A: "foo"},
B: "bar",
},
},
// PtrAnonymousHeadString
{
@ -1473,6 +1908,16 @@ func TestCoverString(t *testing.T) {
B: "bar",
},
},
{
name: "PtrAnonymousHeadStringStringOmitEmpty",
data: struct {
*structStringStringOmitEmpty
B string `json:"b,string,omitempty"`
}{
structStringStringOmitEmpty: &structStringStringOmitEmpty{A: "foo"},
B: "bar",
},
},
// NilPtrAnonymousHeadString
{
@ -1505,6 +1950,16 @@ func TestCoverString(t *testing.T) {
B: "baz",
},
},
{
name: "NilPtrAnonymousHeadStringStringOmitEmpty",
data: struct {
*structStringStringOmitEmpty
B string `json:"b,string,omitempty"`
}{
structStringStringOmitEmpty: nil,
B: "baz",
},
},
// AnonymousHeadStringPtr
{
@ -1537,6 +1992,16 @@ func TestCoverString(t *testing.T) {
B: stringptr("bar"),
},
},
{
name: "AnonymousHeadStringPtrStringOmitEmpty",
data: struct {
structStringPtrStringOmitEmpty
B *string `json:"b,string,omitempty"`
}{
structStringPtrStringOmitEmpty: structStringPtrStringOmitEmpty{A: stringptr("foo")},
B: stringptr("bar"),
},
},
// AnonymousHeadStringPtrNil
{
@ -1569,6 +2034,16 @@ func TestCoverString(t *testing.T) {
B: stringptr("foo"),
},
},
{
name: "AnonymousHeadStringPtrNilStringOmitEmpty",
data: struct {
structStringPtrStringOmitEmpty
B *string `json:"b,string,omitempty"`
}{
structStringPtrStringOmitEmpty: structStringPtrStringOmitEmpty{A: nil},
B: stringptr("foo"),
},
},
// PtrAnonymousHeadStringPtr
{
@ -1601,6 +2076,16 @@ func TestCoverString(t *testing.T) {
B: stringptr("bar"),
},
},
{
name: "PtrAnonymousHeadStringPtrStringOmitEmpty",
data: struct {
*structStringPtrStringOmitEmpty
B *string `json:"b,string,omitempty"`
}{
structStringPtrStringOmitEmpty: &structStringPtrStringOmitEmpty{A: stringptr("foo")},
B: stringptr("bar"),
},
},
// NilPtrAnonymousHeadStringPtr
{
@ -1633,6 +2118,16 @@ func TestCoverString(t *testing.T) {
B: stringptr("foo"),
},
},
{
name: "NilPtrAnonymousHeadStringPtrStringOmitEmpty",
data: struct {
*structStringPtrStringOmitEmpty
B *string `json:"b,string,omitempty"`
}{
structStringPtrStringOmitEmpty: nil,
B: stringptr("foo"),
},
},
// AnonymousHeadStringOnly
{
@ -1659,6 +2154,14 @@ func TestCoverString(t *testing.T) {
structStringString: structStringString{A: "foo"},
},
},
{
name: "AnonymousHeadStringOnlyStringOmitEmpty",
data: struct {
structStringStringOmitEmpty
}{
structStringStringOmitEmpty: structStringStringOmitEmpty{A: "foo"},
},
},
// PtrAnonymousHeadStringOnly
{
@ -1685,6 +2188,14 @@ func TestCoverString(t *testing.T) {
structStringString: &structStringString{A: "foo"},
},
},
{
name: "PtrAnonymousHeadStringOnlyStringOmitEmpty",
data: struct {
*structStringStringOmitEmpty
}{
structStringStringOmitEmpty: &structStringStringOmitEmpty{A: "foo"},
},
},
// NilPtrAnonymousHeadStringOnly
{
@ -1711,6 +2222,14 @@ func TestCoverString(t *testing.T) {
structStringString: nil,
},
},
{
name: "NilPtrAnonymousHeadStringOnlyStringOmitEmpty",
data: struct {
*structStringStringOmitEmpty
}{
structStringStringOmitEmpty: nil,
},
},
// AnonymousHeadStringPtrOnly
{
@ -1737,6 +2256,14 @@ func TestCoverString(t *testing.T) {
structStringPtrString: structStringPtrString{A: stringptr("foo")},
},
},
{
name: "AnonymousHeadStringPtrOnlyStringOmitEmpty",
data: struct {
structStringPtrStringOmitEmpty
}{
structStringPtrStringOmitEmpty: structStringPtrStringOmitEmpty{A: stringptr("foo")},
},
},
// AnonymousHeadStringPtrNilOnly
{
@ -1763,6 +2290,14 @@ func TestCoverString(t *testing.T) {
structStringPtrString: structStringPtrString{A: nil},
},
},
{
name: "AnonymousHeadStringPtrNilOnlyStringOmitEmpty",
data: struct {
structStringPtrStringOmitEmpty
}{
structStringPtrStringOmitEmpty: structStringPtrStringOmitEmpty{A: nil},
},
},
// PtrAnonymousHeadStringPtrOnly
{
@ -1789,6 +2324,14 @@ func TestCoverString(t *testing.T) {
structStringPtrString: &structStringPtrString{A: stringptr("foo")},
},
},
{
name: "PtrAnonymousHeadStringPtrOnlyStringOmitEmpty",
data: struct {
*structStringPtrStringOmitEmpty
}{
structStringPtrStringOmitEmpty: &structStringPtrStringOmitEmpty{A: stringptr("foo")},
},
},
// NilPtrAnonymousHeadStringPtrOnly
{
@ -1815,6 +2358,14 @@ func TestCoverString(t *testing.T) {
structStringPtrString: nil,
},
},
{
name: "NilPtrAnonymousHeadStringPtrOnlyStringOmitEmpty",
data: struct {
*structStringPtrStringOmitEmpty
}{
structStringPtrStringOmitEmpty: nil,
},
},
}
for _, test := range tests {
for _, indent := range []bool{true, false} {

View File

@ -17,6 +17,9 @@ func TestCoverUint(t *testing.T) {
type structUintString struct {
A uint `json:"a,string"`
}
type structUintStringOmitEmpty struct {
A uint `json:"a,string,omitempty"`
}
type structUintPtr struct {
A *uint `json:"a"`
@ -27,6 +30,9 @@ func TestCoverUint(t *testing.T) {
type structUintPtrString struct {
A *uint `json:"a,string"`
}
type structUintPtrStringOmitEmpty struct {
A *uint `json:"a,string,omitempty"`
}
tests := []struct {
name string
@ -72,6 +78,12 @@ func TestCoverUint(t *testing.T) {
A uint `json:"a,string"`
}{},
},
{
name: "HeadUintZeroStringOmitEmpty",
data: struct {
A uint `json:"a,string,omitempty"`
}{},
},
// HeadUint
{
@ -92,6 +104,12 @@ func TestCoverUint(t *testing.T) {
A uint `json:"a,string"`
}{A: 1},
},
{
name: "HeadUintStringOmitEmpty",
data: struct {
A uint `json:"a,string,omitempty"`
}{A: 1},
},
// HeadUintPtr
{
@ -112,6 +130,12 @@ func TestCoverUint(t *testing.T) {
A *uint `json:"a,string"`
}{A: uptr(1)},
},
{
name: "HeadUintPtrStringOmitEmpty",
data: struct {
A *uint `json:"a,string,omitempty"`
}{A: uptr(1)},
},
// HeadUintPtrNil
{
@ -132,6 +156,12 @@ func TestCoverUint(t *testing.T) {
A *uint `json:"a,string"`
}{A: nil},
},
{
name: "HeadUintPtrNilStringOmitEmpty",
data: struct {
A *uint `json:"a,string,omitempty"`
}{A: nil},
},
// PtrHeadUintZero
{
@ -152,6 +182,12 @@ func TestCoverUint(t *testing.T) {
A uint `json:"a,string"`
}{},
},
{
name: "PtrHeadUintZeroStringOmitEmpty",
data: &struct {
A uint `json:"a,string,omitempty"`
}{},
},
// PtrHeadUint
{
@ -172,6 +208,12 @@ func TestCoverUint(t *testing.T) {
A uint `json:"a,string"`
}{A: 1},
},
{
name: "PtrHeadUintStringOmitEmpty",
data: &struct {
A uint `json:"a,string,omitempty"`
}{A: 1},
},
// PtrHeadUintPtr
{
@ -192,6 +234,12 @@ func TestCoverUint(t *testing.T) {
A *uint `json:"a,string"`
}{A: uptr(1)},
},
{
name: "PtrHeadUintPtrStringOmitEmpty",
data: &struct {
A *uint `json:"a,string,omitempty"`
}{A: uptr(1)},
},
// PtrHeadUintPtrNil
{
@ -212,6 +260,12 @@ func TestCoverUint(t *testing.T) {
A *uint `json:"a,string"`
}{A: nil},
},
{
name: "PtrHeadUintPtrNilStringOmitEmpty",
data: &struct {
A *uint `json:"a,string,omitempty"`
}{A: nil},
},
// PtrHeadUintNil
{
@ -232,6 +286,12 @@ func TestCoverUint(t *testing.T) {
A *uint `json:"a,string"`
})(nil),
},
{
name: "PtrHeadUintNilStringOmitEmpty",
data: (*struct {
A *uint `json:"a,string,omitempty"`
})(nil),
},
// HeadUintZeroMultiFields
{
@ -251,13 +311,21 @@ func TestCoverUint(t *testing.T) {
}{},
},
{
name: "HeadUintZeroMultiFields",
name: "HeadUintZeroMultiFieldsString",
data: struct {
A uint `json:"a,string"`
B uint `json:"b,string"`
C uint `json:"c,string"`
}{},
},
{
name: "HeadUintZeroMultiFieldsStringOmitEmpty",
data: struct {
A uint `json:"a,string,omitempty"`
B uint `json:"b,string,omitempty"`
C uint `json:"c,string,omitempty"`
}{},
},
// HeadUintMultiFields
{
@ -284,6 +352,14 @@ func TestCoverUint(t *testing.T) {
C uint `json:"c,string"`
}{A: 1, B: 2, C: 3},
},
{
name: "HeadUintMultiFieldsStringOmitEmpty",
data: struct {
A uint `json:"a,string,omitempty"`
B uint `json:"b,string,omitempty"`
C uint `json:"c,string,omitempty"`
}{A: 1, B: 2, C: 3},
},
// HeadUintPtrMultiFields
{
@ -310,6 +386,14 @@ func TestCoverUint(t *testing.T) {
C *uint `json:"c,string"`
}{A: uptr(1), B: uptr(2), C: uptr(3)},
},
{
name: "HeadUintPtrMultiFieldsStringOmitEmpty",
data: struct {
A *uint `json:"a,string,omitempty"`
B *uint `json:"b,string,omitempty"`
C *uint `json:"c,string,omitempty"`
}{A: uptr(1), B: uptr(2), C: uptr(3)},
},
// HeadUintPtrNilMultiFields
{
@ -336,6 +420,14 @@ func TestCoverUint(t *testing.T) {
C *uint `json:"c,string"`
}{A: nil, B: nil, C: nil},
},
{
name: "HeadUintPtrNilMultiFieldsStringOmitEmpty",
data: struct {
A *uint `json:"a,string,omitempty"`
B *uint `json:"b,string,omitempty"`
C *uint `json:"c,string,omitempty"`
}{A: nil, B: nil, C: nil},
},
// PtrHeadUintZeroMultiFields
{
@ -359,6 +451,13 @@ func TestCoverUint(t *testing.T) {
B uint `json:"b,string"`
}{},
},
{
name: "PtrHeadUintZeroMultiFieldsStringOmitEmpty",
data: &struct {
A uint `json:"a,string,omitempty"`
B uint `json:"b,string,omitempty"`
}{},
},
// PtrHeadUintMultiFields
{
@ -382,6 +481,13 @@ func TestCoverUint(t *testing.T) {
B uint `json:"b,string"`
}{A: 1, B: 2},
},
{
name: "PtrHeadUintMultiFieldsStringOmitEmpty",
data: &struct {
A uint `json:"a,string,omitempty"`
B uint `json:"b,string,omitempty"`
}{A: 1, B: 2},
},
// PtrHeadUintPtrMultiFields
{
@ -405,6 +511,13 @@ func TestCoverUint(t *testing.T) {
B *uint `json:"b,string"`
}{A: uptr(1), B: uptr(2)},
},
{
name: "PtrHeadUintPtrMultiFieldsStringOmitEmpty",
data: &struct {
A *uint `json:"a,string,omitempty"`
B *uint `json:"b,string,omitempty"`
}{A: uptr(1), B: uptr(2)},
},
// PtrHeadUintPtrNilMultiFields
{
@ -428,6 +541,13 @@ func TestCoverUint(t *testing.T) {
B *uint `json:"b,string"`
}{A: nil, B: nil},
},
{
name: "PtrHeadUintPtrNilMultiFieldsStringOmitEmpty",
data: &struct {
A *uint `json:"a,string,omitempty"`
B *uint `json:"b,string,omitempty"`
}{A: nil, B: nil},
},
// PtrHeadUintNilMultiFields
{
@ -451,6 +571,13 @@ func TestCoverUint(t *testing.T) {
B *uint `json:"b,string"`
})(nil),
},
{
name: "PtrHeadUintNilMultiFieldsStringOmitEmpty",
data: (*struct {
A *uint `json:"a,string,omitempty"`
B *uint `json:"b,string,omitempty"`
})(nil),
},
// HeadUintZeroNotRoot
{
@ -477,6 +604,14 @@ func TestCoverUint(t *testing.T) {
}
}{},
},
{
name: "HeadUintZeroNotRootStringOmitEmpty",
data: struct {
A struct {
A uint `json:"a,string,omitempty"`
}
}{},
},
// HeadUintNotRoot
{
@ -509,6 +644,16 @@ func TestCoverUint(t *testing.T) {
A uint `json:"a,string"`
}{A: 1}},
},
{
name: "HeadUintNotRootStringOmitEmpty",
data: struct {
A struct {
A uint `json:"a,string,omitempty"`
}
}{A: struct {
A uint `json:"a,string,omitempty"`
}{A: 1}},
},
// HeadUintPtrNotRoot
{
@ -541,6 +686,16 @@ func TestCoverUint(t *testing.T) {
A *uint `json:"a,string"`
}{uptr(1)}},
},
{
name: "HeadUintPtrNotRootStringOmitEmpty",
data: struct {
A struct {
A *uint `json:"a,string,omitempty"`
}
}{A: struct {
A *uint `json:"a,string,omitempty"`
}{uptr(1)}},
},
// HeadUintPtrNilNotRoot
{
@ -567,6 +722,14 @@ func TestCoverUint(t *testing.T) {
}
}{},
},
{
name: "HeadUintPtrNilNotRootStringOmitEmpty",
data: struct {
A struct {
A *uint `json:"a,string,omitempty"`
}
}{},
},
// PtrHeadUintZeroNotRoot
{
@ -599,6 +762,16 @@ func TestCoverUint(t *testing.T) {
A uint `json:"a,string"`
})},
},
{
name: "PtrHeadUintZeroNotRootStringOmitEmpty",
data: struct {
A *struct {
A uint `json:"a,string,omitempty"`
}
}{A: new(struct {
A uint `json:"a,string,omitempty"`
})},
},
// PtrHeadUintNotRoot
{
@ -631,6 +804,16 @@ func TestCoverUint(t *testing.T) {
A uint `json:"a,string"`
}{A: 1})},
},
{
name: "PtrHeadUintNotRootStringOmitEmpty",
data: struct {
A *struct {
A uint `json:"a,string,omitempty"`
}
}{A: &(struct {
A uint `json:"a,string,omitempty"`
}{A: 1})},
},
// PtrHeadUintPtrNotRoot
{
@ -663,6 +846,16 @@ func TestCoverUint(t *testing.T) {
A *uint `json:"a,string"`
}{A: uptr(1)})},
},
{
name: "PtrHeadUintPtrNotRootStringOmitEmpty",
data: struct {
A *struct {
A *uint `json:"a,string,omitempty"`
}
}{A: &(struct {
A *uint `json:"a,string,omitempty"`
}{A: uptr(1)})},
},
// PtrHeadUintPtrNilNotRoot
{
@ -695,6 +888,16 @@ func TestCoverUint(t *testing.T) {
A *uint `json:"a,string"`
}{A: nil})},
},
{
name: "PtrHeadUintPtrNilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *uint `json:"a,string,omitempty"`
}
}{A: &(struct {
A *uint `json:"a,string,omitempty"`
}{A: nil})},
},
// PtrHeadUintNilNotRoot
{
@ -721,6 +924,14 @@ func TestCoverUint(t *testing.T) {
} `json:",string"`
}{A: nil},
},
{
name: "PtrHeadUintNilNotRootStringOmitEmpty",
data: struct {
A *struct {
A *uint `json:"a,string,omitempty"`
} `json:",string,omitempty"`
}{A: nil},
},
// HeadUintZeroMultiFieldsNotRoot
{
@ -756,6 +967,17 @@ func TestCoverUint(t *testing.T) {
}
}{},
},
{
name: "HeadUintZeroMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A uint `json:"a,string,omitempty"`
}
B struct {
B uint `json:"b,string,omitempty"`
}
}{},
},
// HeadUintMultiFieldsNotRoot
{
@ -803,6 +1025,21 @@ func TestCoverUint(t *testing.T) {
B uint `json:"b,string"`
}{B: 2}},
},
{
name: "HeadUintMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A uint `json:"a,string,omitempty"`
}
B struct {
B uint `json:"b,string,omitempty"`
}
}{A: struct {
A uint `json:"a,string,omitempty"`
}{A: 1}, B: struct {
B uint `json:"b,string,omitempty"`
}{B: 2}},
},
// HeadUintPtrMultiFieldsNotRoot
{
@ -850,6 +1087,21 @@ func TestCoverUint(t *testing.T) {
B *uint `json:"b,string"`
}{B: uptr(2)}},
},
{
name: "HeadUintPtrMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *uint `json:"a,string,omitempty"`
}
B struct {
B *uint `json:"b,string,omitempty"`
}
}{A: struct {
A *uint `json:"a,string,omitempty"`
}{A: uptr(1)}, B: struct {
B *uint `json:"b,string,omitempty"`
}{B: uptr(2)}},
},
// HeadUintPtrNilMultiFieldsNotRoot
{
@ -897,6 +1149,21 @@ func TestCoverUint(t *testing.T) {
B *uint `json:"b,string"`
}{B: nil}},
},
{
name: "HeadUintPtrNilMultiFieldsNotRootStringOmitEmpty",
data: struct {
A struct {
A *uint `json:"a,string,omitempty"`
}
B struct {
B *uint `json:"b,string,omitempty"`
}
}{A: struct {
A *uint `json:"a,string,omitempty"`
}{A: nil}, B: struct {
B *uint `json:"b,string,omitempty"`
}{B: nil}},
},
// PtrHeadUintZeroMultiFieldsNotRoot
{
@ -932,6 +1199,17 @@ func TestCoverUint(t *testing.T) {
}
}{},
},
{
name: "PtrHeadUintZeroMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A uint `json:"a,string,omitempty"`
}
B struct {
B uint `json:"b,string,omitempty"`
}
}{},
},
// PtrHeadUintMultiFieldsNotRoot
{
@ -979,6 +1257,21 @@ func TestCoverUint(t *testing.T) {
B uint `json:"b,string"`
}{B: 2}},
},
{
name: "PtrHeadUintMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A struct {
A uint `json:"a,string,omitempty"`
}
B struct {
B uint `json:"b,string,omitempty"`
}
}{A: struct {
A uint `json:"a,string,omitempty"`
}{A: 1}, B: struct {
B uint `json:"b,string,omitempty"`
}{B: 2}},
},
// PtrHeadUintPtrMultiFieldsNotRoot
{
@ -1026,6 +1319,21 @@ func TestCoverUint(t *testing.T) {
B *uint `json:"b,string"`
}{B: uptr(2)})},
},
{
name: "PtrHeadUintPtrMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *uint `json:"a,string,omitempty"`
}
B *struct {
B *uint `json:"b,string,omitempty"`
}
}{A: &(struct {
A *uint `json:"a,string,omitempty"`
}{A: uptr(1)}), B: &(struct {
B *uint `json:"b,string,omitempty"`
}{B: uptr(2)})},
},
// PtrHeadUintPtrNilMultiFieldsNotRoot
{
@ -1061,6 +1369,17 @@ func TestCoverUint(t *testing.T) {
} `json:",string"`
}{A: nil, B: nil},
},
{
name: "PtrHeadUintPtrNilMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *uint `json:"a,string,omitempty"`
} `json:",string,omitempty"`
B *struct {
B *uint `json:"b,string,omitempty"`
} `json:",string,omitempty"`
}{A: nil, B: nil},
},
// PtrHeadUintNilMultiFieldsNotRoot
{
@ -1096,6 +1415,17 @@ func TestCoverUint(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadUintNilMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *uint `json:"a,string,omitempty"`
}
B *struct {
B *uint `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadUintDoubleMultiFieldsNotRoot
{
@ -1155,6 +1485,25 @@ func TestCoverUint(t *testing.T) {
B uint `json:"b,string"`
}{A: 3, B: 4})},
},
{
name: "PtrHeadUintDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A uint `json:"a,string,omitempty"`
B uint `json:"b,string,omitempty"`
}
B *struct {
A uint `json:"a,string,omitempty"`
B uint `json:"b,string,omitempty"`
}
}{A: &(struct {
A uint `json:"a,string,omitempty"`
B uint `json:"b,string,omitempty"`
}{A: 1, B: 2}), B: &(struct {
A uint `json:"a,string,omitempty"`
B uint `json:"b,string,omitempty"`
}{A: 3, B: 4})},
},
// PtrHeadUintNilDoubleMultiFieldsNotRoot
{
@ -1196,6 +1545,19 @@ func TestCoverUint(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadUintNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A uint `json:"a,string,omitempty"`
B uint `json:"b,string,omitempty"`
}
B *struct {
A uint `json:"a,string,omitempty"`
B uint `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadUintNilDoubleMultiFieldsNotRoot
{
@ -1237,6 +1599,19 @@ func TestCoverUint(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadUintNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A uint `json:"a,string,omitempty"`
B uint `json:"b,string,omitempty"`
}
B *struct {
A uint `json:"a,string,omitempty"`
B uint `json:"b,string,omitempty"`
}
})(nil),
},
// PtrHeadUintPtrDoubleMultiFieldsNotRoot
{
@ -1296,6 +1671,25 @@ func TestCoverUint(t *testing.T) {
B *uint `json:"b,string"`
}{A: uptr(3), B: uptr(4)})},
},
{
name: "PtrHeadUintPtrDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *uint `json:"a,string,omitempty"`
B *uint `json:"b,string,omitempty"`
}
B *struct {
A *uint `json:"a,string,omitempty"`
B *uint `json:"b,string,omitempty"`
}
}{A: &(struct {
A *uint `json:"a,string,omitempty"`
B *uint `json:"b,string,omitempty"`
}{A: uptr(1), B: uptr(2)}), B: &(struct {
A *uint `json:"a,string,omitempty"`
B *uint `json:"b,string,omitempty"`
}{A: uptr(3), B: uptr(4)})},
},
// PtrHeadUintPtrNilDoubleMultiFieldsNotRoot
{
@ -1337,6 +1731,19 @@ func TestCoverUint(t *testing.T) {
}
}{A: nil, B: nil},
},
{
name: "PtrHeadUintPtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: &struct {
A *struct {
A *uint `json:"a,string,omitempty"`
B *uint `json:"b,string,omitempty"`
}
B *struct {
A *uint `json:"a,string,omitempty"`
B *uint `json:"b,string,omitempty"`
}
}{A: nil, B: nil},
},
// PtrHeadUintPtrNilDoubleMultiFieldsNotRoot
{
@ -1378,6 +1785,19 @@ func TestCoverUint(t *testing.T) {
}
})(nil),
},
{
name: "PtrHeadUintPtrNilDoubleMultiFieldsNotRootStringOmitEmpty",
data: (*struct {
A *struct {
A *uint `json:"a,string,omitempty"`
B *uint `json:"b,string,omitempty"`
}
B *struct {
A *uint `json:"a,string,omitempty"`
B *uint `json:"b,string,omitempty"`
}
})(nil),
},
// AnonymousHeadUint
{
@ -1410,6 +1830,16 @@ func TestCoverUint(t *testing.T) {
B: 2,
},
},
{
name: "AnonymousHeadUintStringOmitEmpty",
data: struct {
structUintStringOmitEmpty
B uint `json:"b,string,omitempty"`
}{
structUintStringOmitEmpty: structUintStringOmitEmpty{A: 1},
B: 2,
},
},
// PtrAnonymousHeadUint
{
@ -1442,6 +1872,16 @@ func TestCoverUint(t *testing.T) {
B: 2,
},
},
{
name: "PtrAnonymousHeadUintStringOmitEmpty",
data: struct {
*structUintStringOmitEmpty
B uint `json:"b,string,omitempty"`
}{
structUintStringOmitEmpty: &structUintStringOmitEmpty{A: 1},
B: 2,
},
},
// NilPtrAnonymousHeadUint
{
@ -1474,6 +1914,16 @@ func TestCoverUint(t *testing.T) {
B: 2,
},
},
{
name: "NilPtrAnonymousHeadUintStringOmitEmpty",
data: struct {
*structUintStringOmitEmpty
B uint `json:"b,string,omitempty"`
}{
structUintStringOmitEmpty: nil,
B: 2,
},
},
// AnonymousHeadUintPtr
{
@ -1506,6 +1956,16 @@ func TestCoverUint(t *testing.T) {
B: uptr(2),
},
},
{
name: "AnonymousHeadUintPtrStringOmitEmpty",
data: struct {
structUintPtrStringOmitEmpty
B *uint `json:"b,string,omitempty"`
}{
structUintPtrStringOmitEmpty: structUintPtrStringOmitEmpty{A: uptr(1)},
B: uptr(2),
},
},
// AnonymousHeadUintPtrNil
{
@ -1538,6 +1998,16 @@ func TestCoverUint(t *testing.T) {
B: uptr(2),
},
},
{
name: "AnonymousHeadUintPtrNilStringOmitEmpty",
data: struct {
structUintPtrStringOmitEmpty
B *uint `json:"b,string,omitempty"`
}{
structUintPtrStringOmitEmpty: structUintPtrStringOmitEmpty{A: nil},
B: uptr(2),
},
},
// PtrAnonymousHeadUintPtr
{
@ -1570,6 +2040,16 @@ func TestCoverUint(t *testing.T) {
B: uptr(2),
},
},
{
name: "PtrAnonymousHeadUintPtrStringOmitEmpty",
data: struct {
*structUintPtrStringOmitEmpty
B *uint `json:"b,string,omitempty"`
}{
structUintPtrStringOmitEmpty: &structUintPtrStringOmitEmpty{A: uptr(1)},
B: uptr(2),
},
},
// NilPtrAnonymousHeadUintPtr
{
@ -1602,6 +2082,16 @@ func TestCoverUint(t *testing.T) {
B: uptr(2),
},
},
{
name: "NilPtrAnonymousHeadUintPtrStringOmitEmpty",
data: struct {
*structUintPtrStringOmitEmpty
B *uint `json:"b,string,omitempty"`
}{
structUintPtrStringOmitEmpty: nil,
B: uptr(2),
},
},
// AnonymousHeadUintOnly
{
@ -1628,6 +2118,14 @@ func TestCoverUint(t *testing.T) {
structUintString: structUintString{A: 1},
},
},
{
name: "AnonymousHeadUintOnlyStringOmitEmpty",
data: struct {
structUintStringOmitEmpty
}{
structUintStringOmitEmpty: structUintStringOmitEmpty{A: 1},
},
},
// PtrAnonymousHeadUintOnly
{
@ -1654,6 +2152,14 @@ func TestCoverUint(t *testing.T) {
structUintString: &structUintString{A: 1},
},
},
{
name: "PtrAnonymousHeadUintOnlyStringOmitEmpty",
data: struct {
*structUintStringOmitEmpty
}{
structUintStringOmitEmpty: &structUintStringOmitEmpty{A: 1},
},
},
// NilPtrAnonymousHeadUintOnly
{
@ -1680,6 +2186,14 @@ func TestCoverUint(t *testing.T) {
structUintString: nil,
},
},
{
name: "NilPtrAnonymousHeadUintOnlyStringOmitEmpty",
data: struct {
*structUintStringOmitEmpty
}{
structUintStringOmitEmpty: nil,
},
},
// AnonymousHeadUintPtrOnly
{
@ -1706,6 +2220,14 @@ func TestCoverUint(t *testing.T) {
structUintPtrString: structUintPtrString{A: uptr(1)},
},
},
{
name: "AnonymousHeadUintPtrOnlyStringOmitEmpty",
data: struct {
structUintPtrStringOmitEmpty
}{
structUintPtrStringOmitEmpty: structUintPtrStringOmitEmpty{A: uptr(1)},
},
},
// AnonymousHeadUintPtrNilOnly
{
@ -1732,6 +2254,14 @@ func TestCoverUint(t *testing.T) {
structUintPtrString: structUintPtrString{A: nil},
},
},
{
name: "AnonymousHeadUintPtrNilOnlyStringOmitEmpty",
data: struct {
structUintPtrStringOmitEmpty
}{
structUintPtrStringOmitEmpty: structUintPtrStringOmitEmpty{A: nil},
},
},
// PtrAnonymousHeadUintPtrOnly
{
@ -1758,6 +2288,14 @@ func TestCoverUint(t *testing.T) {
structUintPtrString: &structUintPtrString{A: uptr(1)},
},
},
{
name: "PtrAnonymousHeadUintPtrOnlyStringOmitEmpty",
data: struct {
*structUintPtrStringOmitEmpty
}{
structUintPtrStringOmitEmpty: &structUintPtrStringOmitEmpty{A: uptr(1)},
},
},
// NilPtrAnonymousHeadUintPtrOnly
{
@ -1784,6 +2322,14 @@ func TestCoverUint(t *testing.T) {
structUintPtrString: nil,
},
},
{
name: "NilPtrAnonymousHeadUintPtrOnlyStringOmitEmpty",
data: struct {
*structUintPtrStringOmitEmpty
}{
structUintPtrStringOmitEmpty: nil,
},
},
}
for _, test := range tests {
for _, indent := range []bool{true, false} {

View File

@ -7,7 +7,7 @@ services:
deploy:
resources:
limits:
memory: 600M
memory: 700M
working_dir: /go/src/go-json
command: |
sh -c "go test -c . && ls go-json.test"

View File

@ -100,7 +100,7 @@ func (t OpType) HeadToPtrHead() OpType {
}
suffix := "PtrHead"+t.String()[idx+len("Head"):]
const toPtrOffset = 3
const toPtrOffset = 2
if strings.Contains(OpType(int(t) + toPtrOffset).String(), suffix) {
return OpType(int(t) + toPtrOffset)
}
@ -116,14 +116,6 @@ func (t OpType) HeadToOmitEmptyHead() OpType {
return t
}
func (t OpType) HeadToStringTagHead() OpType {
const toStringTagOffset = 2
if strings.Contains(OpType(int(t) + toStringTagOffset).String(), "StringTag") {
return OpType(int(t) + toStringTagOffset)
}
return t
}
func (t OpType) PtrHeadToHead() OpType {
idx := strings.Index(t.String(), "Ptr")
if idx == -1 {
@ -131,7 +123,7 @@ func (t OpType) PtrHeadToHead() OpType {
}
suffix := t.String()[idx+len("Ptr"):]
const toPtrOffset = 3
const toPtrOffset = 2
if strings.Contains(OpType(int(t) - toPtrOffset).String(), suffix) {
return OpType(int(t) - toPtrOffset)
}
@ -144,10 +136,10 @@ func (t OpType) FieldToEnd() OpType {
return t
}
suffix := t.String()[idx+len("Field"):]
if suffix == "" || suffix == "OmitEmpty" || suffix == "StringTag" {
if suffix == "" || suffix == "OmitEmpty" {
return t
}
const toEndOffset = 3
const toEndOffset = 2
if strings.Contains(OpType(int(t) + toEndOffset).String(), "End"+suffix) {
return OpType(int(t) + toEndOffset)
}
@ -161,15 +153,6 @@ func (t OpType) FieldToOmitEmptyField() OpType {
}
return t
}
func (t OpType) FieldToStringTagField() OpType {
const toStringTagOffset = 2
if strings.Contains(OpType(int(t) + toStringTagOffset).String(), "StringTag") {
return OpType(int(t) + toStringTagOffset)
}
return t
}
`)
if err != nil {
return err
@ -191,9 +174,10 @@ func (t OpType) FieldToStringTagField() OpType {
primitiveTypes := []string{
"int", "uint", "float32", "float64", "bool", "string", "bytes", "number",
"array", "map", "slice", "struct", "MarshalJSON", "MarshalText",
"intString", "uintString",
"intString", "uintString", "float32String", "float64String", "boolString", "stringString", "numberString",
"intPtr", "uintPtr", "float32Ptr", "float64Ptr", "boolPtr", "stringPtr", "bytesPtr", "numberPtr",
"arrayPtr", "mapPtr", "slicePtr", "marshalJSONPtr", "marshalTextPtr", "interfacePtr",
"intPtrString", "uintPtrString", "float32PtrString", "float64PtrString", "boolPtrString", "stringPtrString", "numberPtrString",
}
primitiveTypesUpper := []string{}
for _, typ := range primitiveTypes {
@ -221,7 +205,7 @@ func (t OpType) FieldToStringTagField() OpType {
}
for _, typ := range append(primitiveTypesUpper, "") {
for _, ptrOrNot := range []string{"", "Ptr"} {
for _, opt := range []string{"", "OmitEmpty", "StringTag"} {
for _, opt := range []string{"", "OmitEmpty"} {
ptrOrNot := ptrOrNot
opt := opt
typ := typ
@ -240,7 +224,7 @@ func (t OpType) FieldToStringTagField() OpType {
}
}
for _, typ := range append(primitiveTypesUpper, "") {
for _, opt := range []string{"", "OmitEmpty", "StringTag"} {
for _, opt := range []string{"", "OmitEmpty"} {
opt := opt
typ := typ
@ -254,7 +238,7 @@ func (t OpType) FieldToStringTagField() OpType {
Code: "StructField",
})
}
for _, opt := range []string{"", "OmitEmpty", "StringTag"} {
for _, opt := range []string{"", "OmitEmpty"} {
opt := opt
typ := typ

View File

@ -1019,23 +1019,17 @@ func compileMapValue(ctx *compileContext) (*Opcode, error) {
}
func optimizeStructHeader(code *Opcode, tag *runtime.StructTag) OpType {
headType := code.ToHeaderType()
switch {
case tag.IsOmitEmpty:
headType := code.ToHeaderType(tag.IsString)
if tag.IsOmitEmpty {
headType = headType.HeadToOmitEmptyHead()
case tag.IsString:
headType = headType.HeadToStringTagHead()
}
return headType
}
func optimizeStructField(code *Opcode, tag *runtime.StructTag) OpType {
fieldType := code.ToFieldType()
switch {
case tag.IsOmitEmpty:
fieldType := code.ToFieldType(tag.IsString)
if tag.IsOmitEmpty {
fieldType = fieldType.FieldToOmitEmptyField()
case tag.IsString:
fieldType = fieldType.FieldToStringTagField()
}
return fieldType
}

View File

@ -41,38 +41,24 @@ func (t OpType) IsMultipleOpHead() bool {
return true
case OpStructHeadOmitEmptySlice:
return true
case OpStructHeadStringTagSlice:
return true
case OpStructHeadOmitEmptyArray:
return true
case OpStructHeadStringTagArray:
return true
case OpStructHeadOmitEmptyMap:
return true
case OpStructHeadStringTagMap:
return true
case OpStructHeadOmitEmptyStruct:
return true
case OpStructHeadStringTag:
return true
case OpStructHeadSlicePtr:
return true
case OpStructHeadOmitEmptySlicePtr:
return true
case OpStructHeadStringTagSlicePtr:
return true
case OpStructHeadArrayPtr:
return true
case OpStructHeadOmitEmptyArrayPtr:
return true
case OpStructHeadStringTagArrayPtr:
return true
case OpStructHeadMapPtr:
return true
case OpStructHeadOmitEmptyMapPtr:
return true
case OpStructHeadStringTagMapPtr:
return true
}
return false
}
@ -93,38 +79,24 @@ func (t OpType) IsMultipleOpField() bool {
return true
case OpStructFieldOmitEmptySlice:
return true
case OpStructFieldStringTagSlice:
return true
case OpStructFieldOmitEmptyArray:
return true
case OpStructFieldStringTagArray:
return true
case OpStructFieldOmitEmptyMap:
return true
case OpStructFieldStringTagMap:
return true
case OpStructFieldOmitEmptyStruct:
return true
case OpStructFieldStringTag:
return true
case OpStructFieldSlicePtr:
return true
case OpStructFieldOmitEmptySlicePtr:
return true
case OpStructFieldStringTagSlicePtr:
return true
case OpStructFieldArrayPtr:
return true
case OpStructFieldOmitEmptyArrayPtr:
return true
case OpStructFieldStringTagArrayPtr:
return true
case OpStructFieldMapPtr:
return true
case OpStructFieldOmitEmptyMapPtr:
return true
case OpStructFieldStringTagMapPtr:
return true
}
return false
}

View File

@ -68,35 +68,77 @@ func (c *Opcode) setMaskAndRshiftNum(bitSize uint8) {
c.RshiftNum = rshitNum(bitSize)
}
func (c *Opcode) ToHeaderType() OpType {
func (c *Opcode) ToHeaderType(isString bool) OpType {
switch c.Op {
case OpInt:
if isString {
return OpStructHeadIntString
}
return OpStructHeadInt
case OpIntPtr:
if isString {
return OpStructHeadIntPtrString
}
return OpStructHeadIntPtr
case OpUint:
if isString {
return OpStructHeadUintString
}
return OpStructHeadUint
case OpUintPtr:
if isString {
return OpStructHeadUintPtrString
}
return OpStructHeadUintPtr
case OpFloat32:
if isString {
return OpStructHeadFloat32String
}
return OpStructHeadFloat32
case OpFloat32Ptr:
if isString {
return OpStructHeadFloat32PtrString
}
return OpStructHeadFloat32Ptr
case OpFloat64:
if isString {
return OpStructHeadFloat64String
}
return OpStructHeadFloat64
case OpFloat64Ptr:
if isString {
return OpStructHeadFloat64PtrString
}
return OpStructHeadFloat64Ptr
case OpString:
if isString {
return OpStructHeadStringString
}
return OpStructHeadString
case OpStringPtr:
if isString {
return OpStructHeadStringPtrString
}
return OpStructHeadStringPtr
case OpNumber:
if isString {
return OpStructHeadNumberString
}
return OpStructHeadNumber
case OpNumberPtr:
if isString {
return OpStructHeadNumberPtrString
}
return OpStructHeadNumberPtr
case OpBool:
if isString {
return OpStructHeadBoolString
}
return OpStructHeadBool
case OpBoolPtr:
if isString {
return OpStructHeadBoolPtrString
}
return OpStructHeadBoolPtr
case OpBytes:
return OpStructHeadBytes
@ -129,35 +171,77 @@ func (c *Opcode) ToHeaderType() OpType {
return OpStructHead
}
func (c *Opcode) ToFieldType() OpType {
func (c *Opcode) ToFieldType(isString bool) OpType {
switch c.Op {
case OpInt:
if isString {
return OpStructFieldIntString
}
return OpStructFieldInt
case OpIntPtr:
if isString {
return OpStructFieldIntPtrString
}
return OpStructFieldIntPtr
case OpUint:
if isString {
return OpStructFieldUintString
}
return OpStructFieldUint
case OpUintPtr:
if isString {
return OpStructFieldUintPtrString
}
return OpStructFieldUintPtr
case OpFloat32:
if isString {
return OpStructFieldFloat32String
}
return OpStructFieldFloat32
case OpFloat32Ptr:
if isString {
return OpStructFieldFloat32PtrString
}
return OpStructFieldFloat32Ptr
case OpFloat64:
if isString {
return OpStructFieldFloat64String
}
return OpStructFieldFloat64
case OpFloat64Ptr:
if isString {
return OpStructFieldFloat64PtrString
}
return OpStructFieldFloat64Ptr
case OpString:
if isString {
return OpStructFieldStringString
}
return OpStructFieldString
case OpStringPtr:
if isString {
return OpStructFieldStringPtrString
}
return OpStructFieldStringPtr
case OpNumber:
if isString {
return OpStructFieldNumberString
}
return OpStructFieldNumber
case OpNumberPtr:
if isString {
return OpStructFieldNumberPtrString
}
return OpStructFieldNumberPtr
case OpBool:
if isString {
return OpStructFieldBoolString
}
return OpStructFieldBool
case OpBoolPtr:
if isString {
return OpStructFieldBoolPtrString
}
return OpStructFieldBoolPtr
case OpBytes:
return OpStructFieldBytes

File diff suppressed because it is too large Load Diff

View File

@ -79,3 +79,12 @@ func appendComma(b []byte) []byte {
func appendStructEnd(b []byte) []byte {
return append(b, '}', ',')
}
func appendStructEndSkipLast(b []byte) []byte {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
return appendComma(b)
}
return appendStructEnd(b)
}

File diff suppressed because it is too large Load Diff

View File

@ -79,3 +79,12 @@ func appendComma(b []byte) []byte {
func appendStructEnd(b []byte) []byte {
return append(b, '}', ',')
}
func appendStructEndSkipLast(b []byte) []byte {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
return appendComma(b)
}
return appendStructEnd(b)
}

File diff suppressed because it is too large Load Diff

View File

@ -79,3 +79,12 @@ func appendComma(b []byte) []byte {
func appendStructEnd(b []byte) []byte {
return append(b, '}', ',')
}
func appendStructEndSkipLast(b []byte) []byte {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
return appendComma(b)
}
return appendStructEnd(b)
}

File diff suppressed because it is too large Load Diff

View File

@ -75,3 +75,19 @@ func appendNull(b []byte) []byte {
func appendComma(b []byte) []byte {
return append(b, ',', '\n')
}
func appendStructEndSkipLast(ctx *encoder.RuntimeContext, b []byte, code *encoder.Opcode) []byte {
last := len(b) - 1
if b[last-1] == '{' {
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = appendIndent(ctx, b, code.Indent-1)
b = append(b, '}')
}
return appendComma(b)
}

File diff suppressed because it is too large Load Diff

View File

@ -75,3 +75,19 @@ func appendNull(b []byte) []byte {
func appendComma(b []byte) []byte {
return append(b, ',', '\n')
}
func appendStructEndSkipLast(ctx *encoder.RuntimeContext, b []byte, code *encoder.Opcode) []byte {
last := len(b) - 1
if b[last-1] == '{' {
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = appendIndent(ctx, b, code.Indent-1)
b = append(b, '}')
}
return appendComma(b)
}

File diff suppressed because it is too large Load Diff

View File

@ -74,8 +74,14 @@ func StructTagFromField(field reflect.StructField) *StructTag {
}
st.Key = keyName
if len(opts) > 1 {
st.IsOmitEmpty = opts[1] == "omitempty"
st.IsString = opts[1] == "string"
for _, opt := range opts[1:] {
switch opt {
case "omitempty":
st.IsOmitEmpty = true
case "string":
st.IsString = true
}
}
}
return st
}