forked from mirror/go-json
Add test case for string type
This commit is contained in:
parent
7d6d61df68
commit
a6c1f6442c
|
@ -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} {
|
||||
|
|
|
@ -2155,9 +2155,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
|||
if p != 0 {
|
||||
b = appendIndent(ctx, b, code.Indent+1)
|
||||
b = append(b, code.EscapedKey...)
|
||||
b = append(b, ' ', '"')
|
||||
b = append(b, ' ')
|
||||
b = appendString(b, string(appendString([]byte{}, ptrToString(p))))
|
||||
b = append(b, '"')
|
||||
b = appendComma(b)
|
||||
}
|
||||
code = code.Next
|
||||
|
|
|
@ -2155,9 +2155,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
|||
if p != 0 {
|
||||
b = appendIndent(ctx, b, code.Indent+1)
|
||||
b = append(b, code.Key...)
|
||||
b = append(b, ' ', '"')
|
||||
b = append(b, ' ')
|
||||
b = appendString(b, string(appendString([]byte{}, ptrToString(p))))
|
||||
b = append(b, '"')
|
||||
b = appendComma(b)
|
||||
}
|
||||
code = code.Next
|
||||
|
|
Loading…
Reference in New Issue