Add test case for string type

This commit is contained in:
Masaaki Goshima 2021-05-09 00:40:18 +09:00
parent 7d6d61df68
commit a6c1f6442c
3 changed files with 553 additions and 4 deletions

View File

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

View File

@ -2155,9 +2155,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
if p != 0 { if p != 0 {
b = appendIndent(ctx, b, code.Indent+1) b = appendIndent(ctx, b, code.Indent+1)
b = append(b, code.EscapedKey...) b = append(b, code.EscapedKey...)
b = append(b, ' ', '"') b = append(b, ' ')
b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendString(b, string(appendString([]byte{}, ptrToString(p))))
b = append(b, '"')
b = appendComma(b) b = appendComma(b)
} }
code = code.Next code = code.Next

View File

@ -2155,9 +2155,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
if p != 0 { if p != 0 {
b = appendIndent(ctx, b, code.Indent+1) b = appendIndent(ctx, b, code.Indent+1)
b = append(b, code.Key...) b = append(b, code.Key...)
b = append(b, ' ', '"') b = append(b, ' ')
b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendString(b, string(appendString([]byte{}, ptrToString(p))))
b = append(b, '"')
b = appendComma(b) b = appendComma(b)
} }
code = code.Next code = code.Next