go-json/cover_int64_test.go

2943 lines
48 KiB
Go
Raw Normal View History

2021-01-16 16:16:26 +03:00
package json_test
import (
"bytes"
"strings"
"testing"
"github.com/goccy/go-json"
)
func TestCoverInt64(t *testing.T) {
type structInt64 struct {
A int64 `json:"a"`
}
2021-01-18 16:35:10 +03:00
type structInt64OmitEmpty struct {
A int64 `json:"a,omitempty"`
}
type structInt64String struct {
A int64 `json:"a,string"`
}
2021-01-16 16:16:26 +03:00
type structInt64Ptr struct {
A *int64 `json:"a"`
}
2021-01-18 16:35:10 +03:00
type structInt64PtrOmitEmpty struct {
A *int64 `json:"a,omitempty"`
}
type structInt64PtrString struct {
A *int64 `json:"a,string"`
}
2021-01-16 16:16:26 +03:00
tests := []struct {
name string
expected string
indentExpected string
data interface{}
}{
2021-01-18 16:35:10 +03:00
// HeadInt64Zero
2021-01-16 16:16:26 +03:00
{
name: "HeadInt64Zero",
expected: `{"a":0}`,
indentExpected: `
{
"a": 0
}
`,
data: struct {
A int64 `json:"a"`
}{},
},
2021-01-18 16:35:10 +03:00
{
name: "HeadInt64ZeroOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
A int64 `json:"a,omitempty"`
}{},
},
{
name: "HeadInt64ZeroString",
expected: `{"a":"0"}`,
indentExpected: `
{
"a": "0"
}
`,
data: struct {
A int64 `json:"a,string"`
}{},
},
// HeadInt64
2021-01-16 16:16:26 +03:00
{
name: "HeadInt64",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
A int64 `json:"a"`
}{A: 1},
},
2021-01-18 16:35:10 +03:00
{
name: "HeadInt64OmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
A int64 `json:"a,omitempty"`
}{A: 1},
},
{
name: "HeadInt64String",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: struct {
A int64 `json:"a,string"`
}{A: 1},
},
// HeadInt64Ptr
2021-01-16 16:16:26 +03:00
{
name: "HeadInt64Ptr",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
A *int64 `json:"a"`
}{A: int64ptr(1)},
},
2021-01-18 16:35:10 +03:00
{
name: "HeadInt64PtrOmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
A *int64 `json:"a,omitempty"`
}{A: int64ptr(1)},
},
{
name: "HeadInt64PtrString",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: struct {
A *int64 `json:"a,string"`
}{A: int64ptr(1)},
},
// HeadInt64PtrNil
2021-01-16 16:16:26 +03:00
{
name: "HeadInt64PtrNil",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: struct {
A *int64 `json:"a"`
}{A: nil},
},
2021-01-18 16:35:10 +03:00
{
name: "HeadInt64PtrNilOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
A *int64 `json:"a,omitempty"`
}{A: nil},
},
{
name: "HeadInt64PtrNilString",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: struct {
A *int64 `json:"a,string"`
}{A: nil},
},
// PtrHeadInt64Zero
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadInt64Zero",
expected: `{"a":0}`,
indentExpected: `
{
"a": 0
}
`,
data: &struct {
A int64 `json:"a"`
}{},
},
2021-01-18 16:35:10 +03:00
{
name: "PtrHeadInt64ZeroOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: &struct {
A int64 `json:"a,omitempty"`
}{},
},
{
name: "PtrHeadInt64ZeroString",
expected: `{"a":"0"}`,
indentExpected: `
{
"a": "0"
}
`,
data: &struct {
A int64 `json:"a,string"`
}{},
},
// PtrHeadInt64
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadInt64",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: &struct {
A int64 `json:"a"`
}{A: 1},
},
2021-01-18 16:35:10 +03:00
{
name: "PtrHeadInt64OmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: &struct {
A int64 `json:"a,omitempty"`
}{A: 1},
},
{
name: "PtrHeadInt64String",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: &struct {
A int64 `json:"a,string"`
}{A: 1},
},
// PtrHeadInt64Ptr
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadInt64Ptr",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: &struct {
A *int64 `json:"a"`
}{A: int64ptr(1)},
},
2021-01-18 16:35:10 +03:00
{
name: "PtrHeadInt64PtrOmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: &struct {
A *int64 `json:"a,omitempty"`
}{A: int64ptr(1)},
},
{
name: "PtrHeadInt64PtrString",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: &struct {
A *int64 `json:"a,string"`
}{A: int64ptr(1)},
},
// PtrHeadInt64PtrNil
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadInt64PtrNil",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: &struct {
A *int64 `json:"a"`
}{A: nil},
},
2021-01-18 16:35:10 +03:00
{
name: "PtrHeadInt64PtrNilOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: &struct {
A *int64 `json:"a,omitempty"`
}{A: nil},
},
{
name: "PtrHeadInt64PtrNilString",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: &struct {
A *int64 `json:"a,string"`
}{A: nil},
},
// PtrHeadInt64Nil
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadInt64Nil",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *int64 `json:"a"`
})(nil),
},
2021-01-18 16:35:10 +03:00
{
name: "PtrHeadInt64NilOmitEmpty",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *int64 `json:"a,omitempty"`
})(nil),
},
{
name: "PtrHeadInt64NilString",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *int64 `json:"a,string"`
})(nil),
},
// HeadInt64ZeroMultiFields
2021-01-16 16:16:26 +03:00
{
name: "HeadInt64ZeroMultiFields",
expected: `{"a":0,"b":0}`,
indentExpected: `
{
"a": 0,
"b": 0
}
`,
data: struct {
A int64 `json:"a"`
B int64 `json:"b"`
}{},
},
2021-01-18 16:35:10 +03:00
{
name: "HeadInt64ZeroMultiFieldsOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
A int64 `json:"a,omitempty"`
B int64 `json:"b,omitempty"`
}{},
},
{
name: "HeadInt64ZeroMultiFields",
expected: `{"a":"0","b":"0"}`,
indentExpected: `
{
"a": "0",
"b": "0"
}
`,
data: struct {
A int64 `json:"a,string"`
B int64 `json:"b,string"`
}{},
},
// HeadInt64MultiFields
2021-01-16 16:16:26 +03:00
{
name: "HeadInt64MultiFields",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
A int64 `json:"a"`
B int64 `json:"b"`
}{A: 1, B: 2},
},
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64MultiFieldsOmitEmpty",
2021-01-16 16:16:26 +03:00
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,omitempty"`
B int64 `json:"b,omitempty"`
}{A: 1, B: 2},
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64MultiFieldsString",
expected: `{"a":"1","b":"2"}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
2021-01-18 16:35:10 +03:00
"a": "1",
"b": "2"
2021-01-16 16:16:26 +03:00
}
`,
data: struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,string"`
B int64 `json:"b,string"`
}{A: 1, B: 2},
2021-01-16 16:16:26 +03:00
},
2021-01-18 16:35:10 +03:00
// HeadInt64PtrMultiFields
2021-01-16 16:16:26 +03:00
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64PtrMultiFields",
expected: `{"a":1,"b":2}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
2021-01-18 16:35:10 +03:00
"a": 1,
"b": 2
2021-01-16 16:16:26 +03:00
}
`,
2021-01-18 16:35:10 +03:00
data: struct {
A *int64 `json:"a"`
B *int64 `json:"b"`
}{A: int64ptr(1), B: int64ptr(2)},
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64PtrMultiFieldsOmitEmpty",
2021-01-16 16:16:26 +03:00
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
2021-01-18 16:35:10 +03:00
data: struct {
A *int64 `json:"a,omitempty"`
B *int64 `json:"b,omitempty"`
}{A: int64ptr(1), B: int64ptr(2)},
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64PtrMultiFieldsString",
expected: `{"a":"1","b":"2"}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
2021-01-18 16:35:10 +03:00
"a": "1",
"b": "2"
2021-01-16 16:16:26 +03:00
}
`,
2021-01-18 16:35:10 +03:00
data: struct {
A *int64 `json:"a,string"`
B *int64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}{A: int64ptr(1), B: int64ptr(2)},
},
2021-01-18 16:35:10 +03:00
// HeadInt64PtrNilMultiFields
2021-01-16 16:16:26 +03:00
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64PtrNilMultiFields",
2021-01-16 16:16:26 +03:00
expected: `{"a":null,"b":null}`,
indentExpected: `
{
"a": null,
"b": null
}
`,
2021-01-18 16:35:10 +03:00
data: struct {
2021-01-16 16:16:26 +03:00
A *int64 `json:"a"`
B *int64 `json:"b"`
}{A: nil, B: nil},
},
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64PtrNilMultiFieldsOmitEmpty",
expected: `{}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
2021-01-18 16:35:10 +03:00
{}
2021-01-16 16:16:26 +03:00
`,
2021-01-18 16:35:10 +03:00
data: struct {
A *int64 `json:"a,omitempty"`
B *int64 `json:"b,omitempty"`
}{A: nil, B: nil},
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64PtrNilMultiFieldsString",
expected: `{"a":null,"b":null}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
2021-01-18 16:35:10 +03:00
"a": null,
"b": null
}
`,
data: struct {
A *int64 `json:"a,string"`
B *int64 `json:"b,string"`
}{A: nil, B: nil},
},
// PtrHeadInt64ZeroMultiFields
{
name: "PtrHeadInt64ZeroMultiFields",
expected: `{"a":0,"b":0}`,
indentExpected: `
{
"a": 0,
"b": 0
}
`,
data: &struct {
A int64 `json:"a"`
B int64 `json:"b"`
}{},
},
{
name: "PtrHeadInt64ZeroMultiFieldsOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: &struct {
A int64 `json:"a,omitempty"`
B int64 `json:"b,omitempty"`
}{},
},
{
name: "PtrHeadInt64ZeroMultiFieldsString",
expected: `{"a":"0","b":"0"}`,
indentExpected: `
{
"a": "0",
"b": "0"
}
`,
data: &struct {
A int64 `json:"a,string"`
B int64 `json:"b,string"`
}{},
},
// PtrHeadInt64MultiFields
{
name: "PtrHeadInt64MultiFields",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: &struct {
A int64 `json:"a"`
B int64 `json:"b"`
}{A: 1, B: 2},
},
{
name: "PtrHeadInt64MultiFieldsOmitEmpty",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: &struct {
A int64 `json:"a,omitempty"`
B int64 `json:"b,omitempty"`
}{A: 1, B: 2},
},
{
name: "PtrHeadInt64MultiFieldsString",
expected: `{"a":"1","b":"2"}`,
indentExpected: `
{
"a": "1",
"b": "2"
}
`,
data: &struct {
A int64 `json:"a,string"`
B int64 `json:"b,string"`
}{A: 1, B: 2},
},
// PtrHeadInt64PtrMultiFields
{
name: "PtrHeadInt64PtrMultiFields",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: &struct {
A *int64 `json:"a"`
B *int64 `json:"b"`
}{A: int64ptr(1), B: int64ptr(2)},
},
{
name: "PtrHeadInt64PtrMultiFieldsOmitEmpty",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: &struct {
A *int64 `json:"a,omitempty"`
B *int64 `json:"b,omitempty"`
}{A: int64ptr(1), B: int64ptr(2)},
},
{
name: "PtrHeadInt64PtrMultiFieldsString",
expected: `{"a":"1","b":"2"}`,
indentExpected: `
{
"a": "1",
"b": "2"
}
`,
data: &struct {
A *int64 `json:"a,string"`
B *int64 `json:"b,string"`
}{A: int64ptr(1), B: int64ptr(2)},
},
// PtrHeadInt64PtrNilMultiFields
{
name: "PtrHeadInt64PtrNilMultiFields",
expected: `{"a":null,"b":null}`,
indentExpected: `
{
"a": null,
"b": null
}
`,
data: &struct {
A *int64 `json:"a"`
B *int64 `json:"b"`
}{A: nil, B: nil},
},
{
name: "PtrHeadInt64PtrNilMultiFieldsOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: &struct {
A *int64 `json:"a,omitempty"`
B *int64 `json:"b,omitempty"`
}{A: nil, B: nil},
},
{
name: "PtrHeadInt64PtrNilMultiFieldsString",
expected: `{"a":null,"b":null}`,
indentExpected: `
{
"a": null,
"b": null
}
`,
data: &struct {
A *int64 `json:"a,string"`
B *int64 `json:"b,string"`
}{A: nil, B: nil},
},
// PtrHeadInt64NilMultiFields
{
name: "PtrHeadInt64NilMultiFields",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *int64 `json:"a"`
B *int64 `json:"b"`
})(nil),
},
{
name: "PtrHeadInt64NilMultiFieldsOmitEmpty",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *int64 `json:"a,omitempty"`
B *int64 `json:"b,omitempty"`
})(nil),
},
{
name: "PtrHeadInt64NilMultiFieldsString",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *int64 `json:"a,string"`
B *int64 `json:"b,string"`
})(nil),
},
// HeadInt64ZeroNotRoot
{
name: "HeadInt64ZeroNotRoot",
expected: `{"A":{"a":0}}`,
indentExpected: `
{
"A": {
"a": 0
}
}
2021-01-16 16:16:26 +03:00
`,
data: struct {
A struct {
A int64 `json:"a"`
}
}{},
},
2021-01-18 16:35:10 +03:00
{
name: "HeadInt64ZeroNotRootOmitEmpty",
expected: `{"A":{}}`,
indentExpected: `
{
"A": {}
}
`,
data: struct {
A struct {
A int64 `json:"a,omitempty"`
}
}{},
},
{
name: "HeadInt64ZeroNotRootString",
expected: `{"A":{"a":"0"}}`,
indentExpected: `
{
"A": {
"a": "0"
}
}
`,
data: struct {
A struct {
A int64 `json:"a,string"`
}
}{},
},
// HeadInt64NotRoot
2021-01-16 16:16:26 +03:00
{
name: "HeadInt64NotRoot",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A struct {
A int64 `json:"a"`
}
}{A: struct {
A int64 `json:"a"`
}{A: 1}},
},
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64NotRootOmitEmpty",
2021-01-16 16:16:26 +03:00
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,omitempty"`
2021-01-16 16:16:26 +03:00
}
}{A: struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,omitempty"`
}{A: 1}},
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64NotRootString",
expected: `{"A":{"a":"1"}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
2021-01-18 16:35:10 +03:00
"a": "1"
2021-01-16 16:16:26 +03:00
}
}
`,
data: struct {
A struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,string"`
2021-01-16 16:16:26 +03:00
}
2021-01-18 16:35:10 +03:00
}{A: struct {
A int64 `json:"a,string"`
}{A: 1}},
2021-01-16 16:16:26 +03:00
},
2021-01-18 16:35:10 +03:00
// HeadInt64PtrNotRoot
2021-01-16 16:16:26 +03:00
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64PtrNotRoot",
expected: `{"A":{"a":1}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
2021-01-18 16:35:10 +03:00
"a": 1
2021-01-16 16:16:26 +03:00
}
}
`,
data: struct {
2021-01-18 16:35:10 +03:00
A struct {
A *int64 `json:"a"`
2021-01-16 16:16:26 +03:00
}
2021-01-18 16:35:10 +03:00
}{A: struct {
A *int64 `json:"a"`
}{int64ptr(1)}},
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64PtrNotRootOmitEmpty",
2021-01-16 16:16:26 +03:00
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
2021-01-18 16:35:10 +03:00
A struct {
A *int64 `json:"a,omitempty"`
2021-01-16 16:16:26 +03:00
}
2021-01-18 16:35:10 +03:00
}{A: struct {
A *int64 `json:"a,omitempty"`
}{int64ptr(1)}},
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64PtrNotRootString",
expected: `{"A":{"a":"1"}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
2021-01-18 16:35:10 +03:00
"a": "1"
2021-01-16 16:16:26 +03:00
}
}
`,
data: struct {
2021-01-18 16:35:10 +03:00
A struct {
A *int64 `json:"a,string"`
2021-01-16 16:16:26 +03:00
}
2021-01-18 16:35:10 +03:00
}{A: struct {
A *int64 `json:"a,string"`
}{int64ptr(1)}},
2021-01-16 16:16:26 +03:00
},
2021-01-18 16:35:10 +03:00
// HeadInt64PtrNilNotRoot
2021-01-16 16:16:26 +03:00
{
2021-01-18 16:35:10 +03:00
name: "HeadInt64PtrNilNotRoot",
2021-01-16 16:16:26 +03:00
expected: `{"A":{"a":null}}`,
indentExpected: `
{
"A": {
2021-01-18 16:35:10 +03:00
"a": null
}
}
`,
data: struct {
A struct {
A *int64 `json:"a"`
}
}{},
},
{
name: "HeadInt64PtrNilNotRootOmitEmpty",
expected: `{"A":{}}`,
indentExpected: `
{
"A": {}
}
`,
data: struct {
A struct {
A *int64 `json:"a,omitempty"`
}
}{},
},
{
name: "HeadInt64PtrNilNotRootString",
expected: `{"A":{"a":null}}`,
indentExpected: `
{
"A": {
"a": null
}
}
`,
data: struct {
A struct {
A *int64 `json:"a,string"`
}
}{},
},
// PtrHeadInt64ZeroNotRoot
{
name: "PtrHeadInt64ZeroNotRoot",
expected: `{"A":{"a":0}}`,
indentExpected: `
{
"A": {
"a": 0
}
}
`,
data: struct {
A *struct {
A int64 `json:"a"`
}
}{A: new(struct {
A int64 `json:"a"`
})},
},
{
name: "PtrHeadInt64ZeroNotRootOmitEmpty",
expected: `{"A":{}}`,
indentExpected: `
{
"A": {}
}
`,
data: struct {
A *struct {
A int64 `json:"a,omitempty"`
}
}{A: new(struct {
A int64 `json:"a,omitempty"`
})},
},
{
name: "PtrHeadInt64ZeroNotRootString",
expected: `{"A":{"a":"0"}}`,
indentExpected: `
{
"A": {
"a": "0"
}
}
`,
data: struct {
A *struct {
A int64 `json:"a,string"`
}
}{A: new(struct {
A int64 `json:"a,string"`
})},
},
// PtrHeadInt64NotRoot
{
name: "PtrHeadInt64NotRoot",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A *struct {
A int64 `json:"a"`
}
}{A: &(struct {
A int64 `json:"a"`
}{A: 1})},
},
{
name: "PtrHeadInt64NotRootOmitEmpty",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A *struct {
A int64 `json:"a,omitempty"`
}
}{A: &(struct {
A int64 `json:"a,omitempty"`
}{A: 1})},
},
{
name: "PtrHeadInt64NotRootString",
expected: `{"A":{"a":"1"}}`,
indentExpected: `
{
"A": {
"a": "1"
}
}
`,
data: struct {
A *struct {
A int64 `json:"a,string"`
}
}{A: &(struct {
A int64 `json:"a,string"`
}{A: 1})},
},
// PtrHeadInt64PtrNotRoot
{
name: "PtrHeadInt64PtrNotRoot",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A *struct {
A *int64 `json:"a"`
}
}{A: &(struct {
A *int64 `json:"a"`
}{A: int64ptr(1)})},
},
{
name: "PtrHeadInt64PtrNotRootOmitEmpty",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A *struct {
A *int64 `json:"a,omitempty"`
}
}{A: &(struct {
A *int64 `json:"a,omitempty"`
}{A: int64ptr(1)})},
},
{
name: "PtrHeadInt64PtrNotRootString",
expected: `{"A":{"a":"1"}}`,
indentExpected: `
{
"A": {
"a": "1"
}
}
`,
data: struct {
A *struct {
A *int64 `json:"a,string"`
}
}{A: &(struct {
A *int64 `json:"a,string"`
}{A: int64ptr(1)})},
},
// PtrHeadInt64PtrNilNotRoot
{
name: "PtrHeadInt64PtrNilNotRoot",
expected: `{"A":{"a":null}}`,
indentExpected: `
{
"A": {
"a": null
}
}
`,
data: struct {
A *struct {
A *int64 `json:"a"`
}
}{A: &(struct {
A *int64 `json:"a"`
}{A: nil})},
},
{
name: "PtrHeadInt64PtrNilNotRootOmitEmpty",
expected: `{"A":{}}`,
indentExpected: `
{
"A": {}
}
`,
data: struct {
A *struct {
A *int64 `json:"a,omitempty"`
}
}{A: &(struct {
A *int64 `json:"a,omitempty"`
}{A: nil})},
},
{
name: "PtrHeadInt64PtrNilNotRootString",
expected: `{"A":{"a":null}}`,
indentExpected: `
{
"A": {
"a": null
}
}
`,
data: struct {
A *struct {
A *int64 `json:"a,string"`
}
}{A: &(struct {
A *int64 `json:"a,string"`
}{A: nil})},
},
// PtrHeadInt64NilNotRoot
{
name: "PtrHeadInt64NilNotRoot",
expected: `{"A":null}`,
indentExpected: `
{
"A": null
}
`,
data: struct {
A *struct {
A *int64 `json:"a"`
}
}{A: nil},
},
{
name: "PtrHeadInt64NilNotRootOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
A *struct {
A *int64 `json:"a,omitempty"`
} `json:",omitempty"`
}{A: nil},
},
{
name: "PtrHeadInt64NilNotRootString",
expected: `{"A":null}`,
indentExpected: `
{
"A": null
}
`,
data: struct {
A *struct {
A *int64 `json:"a,string"`
} `json:",string"`
}{A: nil},
},
// HeadInt64ZeroMultiFieldsNotRoot
{
name: "HeadInt64ZeroMultiFieldsNotRoot",
expected: `{"A":{"a":0},"B":{"b":0}}`,
indentExpected: `
{
"A": {
"a": 0
},
"B": {
"b": 0
}
}
`,
data: struct {
A struct {
A int64 `json:"a"`
}
B struct {
B int64 `json:"b"`
}
}{},
},
{
name: "HeadInt64ZeroMultiFieldsNotRootOmitEmpty",
expected: `{"A":{},"B":{}}`,
indentExpected: `
{
"A": {},
"B": {}
}
`,
data: struct {
A struct {
A int64 `json:"a,omitempty"`
}
B struct {
B int64 `json:"b,omitempty"`
}
}{},
},
{
name: "HeadInt64ZeroMultiFieldsNotRootString",
expected: `{"A":{"a":"0"},"B":{"b":"0"}}`,
indentExpected: `
{
"A": {
"a": "0"
},
"B": {
"b": "0"
}
}
`,
data: struct {
A struct {
A int64 `json:"a,string"`
}
B struct {
B int64 `json:"b,string"`
}
}{},
},
// HeadInt64MultiFieldsNotRoot
{
name: "HeadInt64MultiFieldsNotRoot",
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: struct {
A struct {
A int64 `json:"a"`
}
B struct {
B int64 `json:"b"`
}
}{A: struct {
A int64 `json:"a"`
}{A: 1}, B: struct {
B int64 `json:"b"`
}{B: 2}},
},
{
name: "HeadInt64MultiFieldsNotRootOmitEmpty",
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: struct {
A struct {
A int64 `json:"a,omitempty"`
}
B struct {
B int64 `json:"b,omitempty"`
}
}{A: struct {
A int64 `json:"a,omitempty"`
}{A: 1}, B: struct {
B int64 `json:"b,omitempty"`
}{B: 2}},
},
{
name: "HeadInt64MultiFieldsNotRootString",
expected: `{"A":{"a":"1"},"B":{"b":"2"}}`,
indentExpected: `
{
"A": {
"a": "1"
},
"B": {
"b": "2"
}
}
`,
data: struct {
A struct {
A int64 `json:"a,string"`
}
B struct {
B int64 `json:"b,string"`
}
}{A: struct {
A int64 `json:"a,string"`
}{A: 1}, B: struct {
B int64 `json:"b,string"`
}{B: 2}},
},
// HeadInt64PtrMultiFieldsNotRoot
{
name: "HeadInt64PtrMultiFieldsNotRoot",
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: struct {
A struct {
A *int64 `json:"a"`
}
B struct {
B *int64 `json:"b"`
}
}{A: struct {
A *int64 `json:"a"`
}{A: int64ptr(1)}, B: struct {
B *int64 `json:"b"`
}{B: int64ptr(2)}},
},
{
name: "HeadInt64PtrMultiFieldsNotRootOmitEmpty",
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: struct {
A struct {
A *int64 `json:"a,omitempty"`
}
B struct {
B *int64 `json:"b,omitempty"`
}
}{A: struct {
A *int64 `json:"a,omitempty"`
}{A: int64ptr(1)}, B: struct {
B *int64 `json:"b,omitempty"`
}{B: int64ptr(2)}},
},
{
name: "HeadInt64PtrMultiFieldsNotRootString",
expected: `{"A":{"a":"1"},"B":{"b":"2"}}`,
indentExpected: `
{
"A": {
"a": "1"
},
"B": {
"b": "2"
}
}
`,
data: struct {
A struct {
A *int64 `json:"a,string"`
}
B struct {
B *int64 `json:"b,string"`
}
}{A: struct {
A *int64 `json:"a,string"`
}{A: int64ptr(1)}, B: struct {
B *int64 `json:"b,string"`
}{B: int64ptr(2)}},
},
// HeadInt64PtrNilMultiFieldsNotRoot
{
name: "HeadInt64PtrNilMultiFieldsNotRoot",
expected: `{"A":{"a":null},"B":{"b":null}}`,
indentExpected: `
{
"A": {
"a": null
},
"B": {
"b": null
}
}
`,
data: struct {
A struct {
A *int64 `json:"a"`
}
B struct {
B *int64 `json:"b"`
}
}{A: struct {
A *int64 `json:"a"`
}{A: nil}, B: struct {
B *int64 `json:"b"`
}{B: nil}},
},
{
name: "HeadInt64PtrNilMultiFieldsNotRootOmitEmpty",
expected: `{"A":{},"B":{}}`,
indentExpected: `
{
"A": {},
"B": {}
}
`,
data: struct {
A struct {
A *int64 `json:"a,omitempty"`
}
B struct {
B *int64 `json:"b,omitempty"`
}
}{A: struct {
A *int64 `json:"a,omitempty"`
}{A: nil}, B: struct {
B *int64 `json:"b,omitempty"`
}{B: nil}},
},
{
name: "HeadInt64PtrNilMultiFieldsNotRootString",
expected: `{"A":{"a":null},"B":{"b":null}}`,
indentExpected: `
{
"A": {
"a": null
},
"B": {
"b": null
}
}
`,
data: struct {
A struct {
A *int64 `json:"a,string"`
}
B struct {
B *int64 `json:"b,string"`
}
}{A: struct {
A *int64 `json:"a,string"`
}{A: nil}, B: struct {
B *int64 `json:"b,string"`
}{B: nil}},
},
// PtrHeadInt64ZeroMultiFieldsNotRoot
{
name: "PtrHeadInt64ZeroMultiFieldsNotRoot",
expected: `{"A":{"a":0},"B":{"b":0}}`,
indentExpected: `
{
"A": {
"a": 0
},
"B": {
"b": 0
2021-01-16 16:16:26 +03:00
}
}
`,
2021-01-18 16:35:10 +03:00
data: &struct {
A struct {
A int64 `json:"a"`
2021-01-16 16:16:26 +03:00
}
2021-01-18 16:35:10 +03:00
B struct {
B int64 `json:"b"`
}
}{},
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "PtrHeadInt64ZeroMultiFieldsNotRootOmitEmpty",
expected: `{"A":{},"B":{}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
2021-01-18 16:35:10 +03:00
"A": {},
"B": {}
2021-01-16 16:16:26 +03:00
}
`,
2021-01-18 16:35:10 +03:00
data: &struct {
A struct {
A int64 `json:"a,omitempty"`
2021-01-16 16:16:26 +03:00
}
2021-01-18 16:35:10 +03:00
B struct {
B int64 `json:"b,omitempty"`
}
}{},
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "PtrHeadInt64ZeroMultiFieldsNotRootString",
expected: `{"A":{"a":"0"},"B":{"b":"0"}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
2021-01-18 16:35:10 +03:00
"a": "0"
2021-01-16 16:16:26 +03:00
},
"B": {
2021-01-18 16:35:10 +03:00
"b": "0"
2021-01-16 16:16:26 +03:00
}
}
`,
2021-01-18 16:35:10 +03:00
data: &struct {
2021-01-16 16:16:26 +03:00
A struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,string"`
2021-01-16 16:16:26 +03:00
}
B struct {
2021-01-18 16:35:10 +03:00
B int64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
}{},
},
2021-01-18 16:35:10 +03:00
// PtrHeadInt64MultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
2021-01-18 16:35:10 +03:00
name: "PtrHeadInt64MultiFieldsNotRoot",
2021-01-16 16:16:26 +03:00
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
2021-01-18 16:35:10 +03:00
data: &struct {
2021-01-16 16:16:26 +03:00
A struct {
A int64 `json:"a"`
}
B struct {
B int64 `json:"b"`
}
}{A: struct {
A int64 `json:"a"`
}{A: 1}, B: struct {
B int64 `json:"b"`
}{B: 2}},
},
{
2021-01-18 16:35:10 +03:00
name: "PtrHeadInt64MultiFieldsNotRootOmitEmpty",
2021-01-16 16:16:26 +03:00
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
2021-01-18 16:35:10 +03:00
data: &struct {
2021-01-16 16:16:26 +03:00
A struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,omitempty"`
2021-01-16 16:16:26 +03:00
}
B struct {
2021-01-18 16:35:10 +03:00
B int64 `json:"b,omitempty"`
2021-01-16 16:16:26 +03:00
}
}{A: struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,omitempty"`
}{A: 1}, B: struct {
B int64 `json:"b,omitempty"`
}{B: 2}},
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "PtrHeadInt64MultiFieldsNotRootString",
expected: `{"A":{"a":"1"},"B":{"b":"2"}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
2021-01-18 16:35:10 +03:00
"a": "1"
2021-01-16 16:16:26 +03:00
},
"B": {
2021-01-18 16:35:10 +03:00
"b": "2"
2021-01-16 16:16:26 +03:00
}
}
`,
2021-01-18 16:35:10 +03:00
data: &struct {
2021-01-16 16:16:26 +03:00
A struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,string"`
2021-01-16 16:16:26 +03:00
}
B struct {
2021-01-18 16:35:10 +03:00
B int64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
}{A: struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,string"`
}{A: 1}, B: struct {
B int64 `json:"b,string"`
}{B: 2}},
2021-01-16 16:16:26 +03:00
},
2021-01-18 16:35:10 +03:00
// PtrHeadInt64PtrMultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
2021-01-18 16:35:10 +03:00
name: "PtrHeadInt64PtrMultiFieldsNotRoot",
expected: `{"A":{"a":1},"B":{"b":2}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
2021-01-18 16:35:10 +03:00
"a": 1
2021-01-16 16:16:26 +03:00
},
"B": {
2021-01-18 16:35:10 +03:00
"b": 2
2021-01-16 16:16:26 +03:00
}
}
`,
data: &struct {
2021-01-18 16:35:10 +03:00
A *struct {
A *int64 `json:"a"`
2021-01-16 16:16:26 +03:00
}
2021-01-18 16:35:10 +03:00
B *struct {
B *int64 `json:"b"`
2021-01-16 16:16:26 +03:00
}
2021-01-18 16:35:10 +03:00
}{A: &(struct {
A *int64 `json:"a"`
}{A: int64ptr(1)}), B: &(struct {
B *int64 `json:"b"`
}{B: int64ptr(2)})},
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "PtrHeadInt64PtrMultiFieldsNotRootOmitEmpty",
2021-01-16 16:16:26 +03:00
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: &struct {
2021-01-18 16:35:10 +03:00
A *struct {
A *int64 `json:"a,omitempty"`
}
B *struct {
B *int64 `json:"b,omitempty"`
}
}{A: &(struct {
A *int64 `json:"a,omitempty"`
}{A: int64ptr(1)}), B: &(struct {
B *int64 `json:"b,omitempty"`
}{B: int64ptr(2)})},
},
{
name: "PtrHeadInt64PtrMultiFieldsNotRootString",
expected: `{"A":{"a":"1"},"B":{"b":"2"}}`,
indentExpected: `
{
"A": {
"a": "1"
},
"B": {
"b": "2"
}
}
`,
data: &struct {
A *struct {
A *int64 `json:"a,string"`
}
B *struct {
B *int64 `json:"b,string"`
}
}{A: &(struct {
A *int64 `json:"a,string"`
}{A: int64ptr(1)}), B: &(struct {
B *int64 `json:"b,string"`
}{B: int64ptr(2)})},
},
// PtrHeadInt64PtrNilMultiFieldsNotRoot
{
name: "PtrHeadInt64PtrNilMultiFieldsNotRoot",
expected: `{"A":null,"B":null}`,
indentExpected: `
{
"A": null,
"B": null
}
`,
data: &struct {
A *struct {
A *int64 `json:"a"`
}
B *struct {
B *int64 `json:"b"`
}
}{A: nil, B: nil},
},
{
name: "PtrHeadInt64PtrNilMultiFieldsNotRootOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: &struct {
A *struct {
A *int64 `json:"a,omitempty"`
} `json:",omitempty"`
B *struct {
B *int64 `json:"b,omitempty"`
} `json:",omitempty"`
}{A: nil, B: nil},
},
{
name: "PtrHeadInt64PtrNilMultiFieldsNotRootString",
expected: `{"A":null,"B":null}`,
indentExpected: `
{
"A": null,
"B": null
}
`,
data: &struct {
A *struct {
A *int64 `json:"a,string"`
} `json:",string"`
B *struct {
B *int64 `json:"b,string"`
} `json:",string"`
}{A: nil, B: nil},
},
// PtrHeadInt64NilMultiFieldsNotRoot
{
name: "PtrHeadInt64NilMultiFieldsNotRoot",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *int64 `json:"a"`
}
B *struct {
B *int64 `json:"b"`
}
})(nil),
},
{
name: "PtrHeadInt64NilMultiFieldsNotRootOmitEmpty",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *int64 `json:"a,omitempty"`
}
B *struct {
B *int64 `json:"b,omitempty"`
}
})(nil),
},
{
name: "PtrHeadInt64NilMultiFieldsNotRootString",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *int64 `json:"a,string"`
}
B *struct {
B *int64 `json:"b,string"`
}
})(nil),
},
// PtrHeadInt64DoubleMultiFieldsNotRoot
{
name: "PtrHeadInt64DoubleMultiFieldsNotRoot",
expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`,
indentExpected: `
{
"A": {
"a": 1,
"b": 2
},
"B": {
"a": 3,
"b": 4
}
}
`,
data: &struct {
A *struct {
2021-01-16 16:16:26 +03:00
A int64 `json:"a"`
2021-01-18 16:35:10 +03:00
B int64 `json:"b"`
2021-01-16 16:16:26 +03:00
}
2021-01-18 16:35:10 +03:00
B *struct {
A int64 `json:"a"`
2021-01-16 16:16:26 +03:00
B int64 `json:"b"`
}
2021-01-18 16:35:10 +03:00
}{A: &(struct {
2021-01-16 16:16:26 +03:00
A int64 `json:"a"`
B int64 `json:"b"`
2021-01-18 16:35:10 +03:00
}{A: 1, B: 2}), B: &(struct {
A int64 `json:"a"`
B int64 `json:"b"`
}{A: 3, B: 4})},
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "PtrHeadInt64DoubleMultiFieldsNotRootOmitEmpty",
expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`,
indentExpected: `
{
"A": {
"a": 1,
"b": 2
},
"B": {
"a": 3,
"b": 4
}
}
`,
data: &struct {
A *struct {
A int64 `json:"a,omitempty"`
B int64 `json:"b,omitempty"`
}
B *struct {
A int64 `json:"a,omitempty"`
B int64 `json:"b,omitempty"`
}
}{A: &(struct {
A int64 `json:"a,omitempty"`
B int64 `json:"b,omitempty"`
}{A: 1, B: 2}), B: &(struct {
A int64 `json:"a,omitempty"`
B int64 `json:"b,omitempty"`
}{A: 3, B: 4})},
},
{
name: "PtrHeadInt64DoubleMultiFieldsNotRootString",
expected: `{"A":{"a":"1","b":"2"},"B":{"a":"3","b":"4"}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
2021-01-18 16:35:10 +03:00
"a": "1",
"b": "2"
2021-01-16 16:16:26 +03:00
},
"B": {
2021-01-18 16:35:10 +03:00
"a": "3",
"b": "4"
2021-01-16 16:16:26 +03:00
}
}
`,
data: &struct {
A *struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,string"`
B int64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
B *struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,string"`
B int64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
}{A: &(struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,string"`
B int64 `json:"b,string"`
}{A: 1, B: 2}), B: &(struct {
A int64 `json:"a,string"`
B int64 `json:"b,string"`
}{A: 3, B: 4})},
2021-01-16 16:16:26 +03:00
},
2021-01-18 16:35:10 +03:00
// PtrHeadInt64NilDoubleMultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
2021-01-18 16:35:10 +03:00
name: "PtrHeadInt64NilDoubleMultiFieldsNotRoot",
2021-01-16 16:16:26 +03:00
expected: `{"A":null,"B":null}`,
indentExpected: `
{
"A": null,
"B": null
}
`,
data: &struct {
A *struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a"`
B int64 `json:"b"`
2021-01-16 16:16:26 +03:00
}
B *struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a"`
B int64 `json:"b"`
2021-01-16 16:16:26 +03:00
}
}{A: nil, B: nil},
},
{
2021-01-18 16:35:10 +03:00
name: "PtrHeadInt64NilDoubleMultiFieldsNotRootOmitEmpty",
expected: `{}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
2021-01-18 16:35:10 +03:00
{}
2021-01-16 16:16:26 +03:00
`,
2021-01-18 16:35:10 +03:00
data: &struct {
2021-01-16 16:16:26 +03:00
A *struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,omitempty"`
B int64 `json:"b,omitempty"`
} `json:",omitempty"`
2021-01-16 16:16:26 +03:00
B *struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,omitempty"`
B int64 `json:"b,omitempty"`
} `json:",omitempty"`
}{A: nil, B: nil},
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "PtrHeadInt64NilDoubleMultiFieldsNotRootString",
expected: `{"A":null,"B":null}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
2021-01-18 16:35:10 +03:00
"A": null,
"B": null
2021-01-16 16:16:26 +03:00
}
`,
data: &struct {
A *struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,string"`
B int64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
B *struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,string"`
B int64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
2021-01-18 16:35:10 +03:00
}{A: nil, B: nil},
2021-01-16 16:16:26 +03:00
},
2021-01-18 16:35:10 +03:00
// PtrHeadInt64NilDoubleMultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadInt64NilDoubleMultiFieldsNotRoot",
2021-01-18 16:35:10 +03:00
expected: `null`,
2021-01-16 16:16:26 +03:00
indentExpected: `
2021-01-18 16:35:10 +03:00
null
2021-01-16 16:16:26 +03:00
`,
2021-01-18 16:35:10 +03:00
data: (*struct {
2021-01-16 16:16:26 +03:00
A *struct {
A int64 `json:"a"`
B int64 `json:"b"`
}
B *struct {
A int64 `json:"a"`
B int64 `json:"b"`
}
2021-01-18 16:35:10 +03:00
})(nil),
2021-01-16 16:16:26 +03:00
},
{
2021-01-18 16:35:10 +03:00
name: "PtrHeadInt64NilDoubleMultiFieldsNotRootOmitEmpty",
2021-01-16 16:16:26 +03:00
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,omitempty"`
B int64 `json:"b,omitempty"`
2021-01-16 16:16:26 +03:00
}
B *struct {
2021-01-18 16:35:10 +03:00
A int64 `json:"a,omitempty"`
B int64 `json:"b,omitempty"`
}
})(nil),
},
{
name: "PtrHeadInt64NilDoubleMultiFieldsNotRootString",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A int64 `json:"a,string"`
B int64 `json:"b,string"`
}
B *struct {
A int64 `json:"a,string"`
B int64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
})(nil),
},
2021-01-18 16:35:10 +03:00
// PtrHeadInt64PtrDoubleMultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadInt64PtrDoubleMultiFieldsNotRoot",
expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`,
indentExpected: `
{
"A": {
"a": 1,
"b": 2
},
"B": {
"a": 3,
"b": 4
}
}
`,
data: &struct {
A *struct {
A *int64 `json:"a"`
B *int64 `json:"b"`
}
B *struct {
A *int64 `json:"a"`
B *int64 `json:"b"`
}
}{A: &(struct {
A *int64 `json:"a"`
B *int64 `json:"b"`
}{A: int64ptr(1), B: int64ptr(2)}), B: &(struct {
A *int64 `json:"a"`
B *int64 `json:"b"`
}{A: int64ptr(3), B: int64ptr(4)})},
},
2021-01-18 16:35:10 +03:00
{
name: "PtrHeadInt64PtrDoubleMultiFieldsNotRootOmitEmpty",
expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`,
indentExpected: `
{
"A": {
"a": 1,
"b": 2
},
"B": {
"a": 3,
"b": 4
}
}
`,
data: &struct {
A *struct {
A *int64 `json:"a,omitempty"`
B *int64 `json:"b,omitempty"`
}
B *struct {
A *int64 `json:"a,omitempty"`
B *int64 `json:"b,omitempty"`
}
}{A: &(struct {
A *int64 `json:"a,omitempty"`
B *int64 `json:"b,omitempty"`
}{A: int64ptr(1), B: int64ptr(2)}), B: &(struct {
A *int64 `json:"a,omitempty"`
B *int64 `json:"b,omitempty"`
}{A: int64ptr(3), B: int64ptr(4)})},
},
{
name: "PtrHeadInt64PtrDoubleMultiFieldsNotRootString",
expected: `{"A":{"a":"1","b":"2"},"B":{"a":"3","b":"4"}}`,
indentExpected: `
{
"A": {
"a": "1",
"b": "2"
},
"B": {
"a": "3",
"b": "4"
}
}
`,
data: &struct {
A *struct {
A *int64 `json:"a,string"`
B *int64 `json:"b,string"`
}
B *struct {
A *int64 `json:"a,string"`
B *int64 `json:"b,string"`
}
}{A: &(struct {
A *int64 `json:"a,string"`
B *int64 `json:"b,string"`
}{A: int64ptr(1), B: int64ptr(2)}), B: &(struct {
A *int64 `json:"a,string"`
B *int64 `json:"b,string"`
}{A: int64ptr(3), B: int64ptr(4)})},
},
// PtrHeadInt64PtrNilDoubleMultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadInt64PtrNilDoubleMultiFieldsNotRoot",
expected: `{"A":null,"B":null}`,
indentExpected: `
{
"A": null,
"B": null
}
`,
data: &struct {
A *struct {
A *int64 `json:"a"`
B *int64 `json:"b"`
}
B *struct {
A *int64 `json:"a"`
B *int64 `json:"b"`
}
}{A: nil, B: nil},
},
2021-01-18 16:35:10 +03:00
{
name: "PtrHeadInt64PtrNilDoubleMultiFieldsNotRootOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: &struct {
A *struct {
A *int64 `json:"a,omitempty"`
B *int64 `json:"b,omitempty"`
} `json:",omitempty"`
B *struct {
A *int64 `json:"a,omitempty"`
B *int64 `json:"b,omitempty"`
} `json:",omitempty"`
}{A: nil, B: nil},
},
{
name: "PtrHeadInt64PtrNilDoubleMultiFieldsNotRootString",
expected: `{"A":null,"B":null}`,
indentExpected: `
{
"A": null,
"B": null
}
`,
data: &struct {
A *struct {
A *int64 `json:"a,string"`
B *int64 `json:"b,string"`
}
B *struct {
A *int64 `json:"a,string"`
B *int64 `json:"b,string"`
}
}{A: nil, B: nil},
},
// PtrHeadInt64PtrNilDoubleMultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadInt64PtrNilDoubleMultiFieldsNotRoot",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *int64 `json:"a"`
B *int64 `json:"b"`
}
B *struct {
A *int64 `json:"a"`
B *int64 `json:"b"`
}
})(nil),
},
{
2021-01-18 16:35:10 +03:00
name: "PtrHeadInt64PtrNilDoubleMultiFieldsNotRootOmitEmpty",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *int64 `json:"a,omitempty"`
B *int64 `json:"b,omitempty"`
}
B *struct {
A *int64 `json:"a,omitempty"`
B *int64 `json:"b,omitempty"`
}
})(nil),
},
{
name: "PtrHeadInt64PtrNilDoubleMultiFieldsNotRootString",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *int64 `json:"a,string"`
B *int64 `json:"b,string"`
}
B *struct {
A *int64 `json:"a,string"`
B *int64 `json:"b,string"`
}
})(nil),
},
// AnonymousHeadInt64
{
name: "AnonymousHeadInt64",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
structInt64
B int64 `json:"b"`
}{
structInt64: structInt64{A: 1},
B: 2,
},
},
{
name: "AnonymousHeadInt64OmitEmpty",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
structInt64OmitEmpty
B int64 `json:"b,omitempty"`
}{
structInt64OmitEmpty: structInt64OmitEmpty{A: 1},
B: 2,
},
},
{
name: "AnonymousHeadInt64String",
expected: `{"a":"1","b":"2"}`,
indentExpected: `
{
"a": "1",
"b": "2"
}
`,
data: struct {
structInt64String
B int64 `json:"b,string"`
}{
structInt64String: structInt64String{A: 1},
B: 2,
},
},
// PtrAnonymousHeadInt64
{
name: "PtrAnonymousHeadInt64",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
*structInt64
B int64 `json:"b"`
}{
structInt64: &structInt64{A: 1},
B: 2,
},
},
{
name: "PtrAnonymousHeadInt64OmitEmpty",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
*structInt64OmitEmpty
B int64 `json:"b,omitempty"`
}{
structInt64OmitEmpty: &structInt64OmitEmpty{A: 1},
B: 2,
},
},
{
name: "PtrAnonymousHeadInt64String",
expected: `{"a":"1","b":"2"}`,
indentExpected: `
{
"a": "1",
"b": "2"
}
`,
data: struct {
*structInt64String
B int64 `json:"b,string"`
}{
structInt64String: &structInt64String{A: 1},
B: 2,
},
},
// NilPtrAnonymousHeadInt64
{
name: "NilPtrAnonymousHeadInt64",
expected: `{"b":2}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"b": 2
}
`,
data: struct {
2021-01-18 16:35:10 +03:00
*structInt64
2021-01-16 16:16:26 +03:00
B int64 `json:"b"`
}{
2021-01-18 16:35:10 +03:00
structInt64: nil,
2021-01-16 16:16:26 +03:00
B: 2,
},
},
{
2021-01-18 16:35:10 +03:00
name: "NilPtrAnonymousHeadInt64OmitEmpty",
expected: `{"b":2}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"b": 2
}
`,
data: struct {
2021-01-18 16:35:10 +03:00
*structInt64OmitEmpty
B int64 `json:"b,omitempty"`
2021-01-16 16:16:26 +03:00
}{
2021-01-18 16:35:10 +03:00
structInt64OmitEmpty: nil,
B: 2,
2021-01-16 16:16:26 +03:00
},
},
{
2021-01-18 16:35:10 +03:00
name: "NilPtrAnonymousHeadInt64String",
expected: `{"b":"2"}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
2021-01-18 16:35:10 +03:00
"b": "2"
2021-01-16 16:16:26 +03:00
}
`,
data: struct {
2021-01-18 16:35:10 +03:00
*structInt64String
B int64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}{
2021-01-18 16:35:10 +03:00
structInt64String: nil,
B: 2,
2021-01-16 16:16:26 +03:00
},
},
2021-01-18 16:35:10 +03:00
// AnonymousHeadInt64Ptr
2021-01-16 16:16:26 +03:00
{
name: "AnonymousHeadInt64Ptr",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
structInt64Ptr
B *int64 `json:"b"`
}{
structInt64Ptr: structInt64Ptr{A: int64ptr(1)},
B: int64ptr(2),
},
},
2021-01-18 16:35:10 +03:00
{
name: "AnonymousHeadInt64PtrOmitEmpty",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
structInt64PtrOmitEmpty
B *int64 `json:"b,omitempty"`
}{
structInt64PtrOmitEmpty: structInt64PtrOmitEmpty{A: int64ptr(1)},
B: int64ptr(2),
},
},
{
name: "AnonymousHeadInt64PtrString",
expected: `{"a":"1","b":"2"}`,
indentExpected: `
{
"a": "1",
"b": "2"
}
`,
data: struct {
structInt64PtrString
B *int64 `json:"b,string"`
}{
structInt64PtrString: structInt64PtrString{A: int64ptr(1)},
B: int64ptr(2),
},
},
// AnonymousHeadInt64PtrNil
2021-01-16 16:16:26 +03:00
{
name: "AnonymousHeadInt64PtrNil",
expected: `{"a":null,"b":2}`,
indentExpected: `
{
"a": null,
"b": 2
}
`,
data: struct {
structInt64Ptr
B *int64 `json:"b"`
}{
structInt64Ptr: structInt64Ptr{A: nil},
B: int64ptr(2),
},
},
2021-01-18 16:35:10 +03:00
{
name: "AnonymousHeadInt64PtrNilOmitEmpty",
expected: `{"b":2}`,
indentExpected: `
{
"b": 2
}
`,
data: struct {
structInt64PtrOmitEmpty
B *int64 `json:"b,omitempty"`
}{
structInt64PtrOmitEmpty: structInt64PtrOmitEmpty{A: nil},
B: int64ptr(2),
},
},
{
name: "AnonymousHeadInt64PtrNilString",
expected: `{"a":null,"b":"2"}`,
indentExpected: `
{
"a": null,
"b": "2"
}
`,
data: struct {
structInt64PtrString
B *int64 `json:"b,string"`
}{
structInt64PtrString: structInt64PtrString{A: nil},
B: int64ptr(2),
},
},
// PtrAnonymousHeadInt64Ptr
2021-01-16 16:16:26 +03:00
{
name: "PtrAnonymousHeadInt64Ptr",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
*structInt64Ptr
B *int64 `json:"b"`
}{
structInt64Ptr: &structInt64Ptr{A: int64ptr(1)},
B: int64ptr(2),
},
},
2021-01-18 16:35:10 +03:00
{
name: "PtrAnonymousHeadInt64PtrOmitEmpty",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
*structInt64PtrOmitEmpty
B *int64 `json:"b,omitempty"`
}{
structInt64PtrOmitEmpty: &structInt64PtrOmitEmpty{A: int64ptr(1)},
B: int64ptr(2),
},
},
{
name: "PtrAnonymousHeadInt64PtrString",
expected: `{"a":"1","b":"2"}`,
indentExpected: `
{
"a": "1",
"b": "2"
}
`,
data: struct {
*structInt64PtrString
B *int64 `json:"b,string"`
}{
structInt64PtrString: &structInt64PtrString{A: int64ptr(1)},
B: int64ptr(2),
},
},
// NilPtrAnonymousHeadInt64Ptr
2021-01-16 16:16:26 +03:00
{
name: "NilPtrAnonymousHeadInt64Ptr",
expected: `{"b":2}`,
indentExpected: `
{
"b": 2
}
`,
data: struct {
*structInt64Ptr
B *int64 `json:"b"`
}{
structInt64Ptr: nil,
B: int64ptr(2),
},
},
2021-01-18 16:35:10 +03:00
{
name: "NilPtrAnonymousHeadInt64PtrOmitEmpty",
expected: `{"b":2}`,
indentExpected: `
{
"b": 2
}
`,
data: struct {
*structInt64PtrOmitEmpty
B *int64 `json:"b,omitempty"`
}{
structInt64PtrOmitEmpty: nil,
B: int64ptr(2),
},
},
{
name: "NilPtrAnonymousHeadInt64PtrString",
expected: `{"b":"2"}`,
indentExpected: `
{
"b": "2"
}
`,
data: struct {
*structInt64PtrString
B *int64 `json:"b,string"`
}{
structInt64PtrString: nil,
B: int64ptr(2),
},
},
// AnonymousHeadInt64Only
2021-01-16 16:16:26 +03:00
{
name: "AnonymousHeadInt64Only",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
structInt64
}{
structInt64: structInt64{A: 1},
},
},
2021-01-18 16:35:10 +03:00
{
name: "AnonymousHeadInt64OnlyOmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
structInt64OmitEmpty
}{
structInt64OmitEmpty: structInt64OmitEmpty{A: 1},
},
},
{
name: "AnonymousHeadInt64OnlyString",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: struct {
structInt64String
}{
structInt64String: structInt64String{A: 1},
},
},
// PtrAnonymousHeadInt64Only
2021-01-16 16:16:26 +03:00
{
name: "PtrAnonymousHeadInt64Only",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
*structInt64
}{
structInt64: &structInt64{A: 1},
},
},
2021-01-18 16:35:10 +03:00
{
name: "PtrAnonymousHeadInt64OnlyOmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
*structInt64OmitEmpty
}{
structInt64OmitEmpty: &structInt64OmitEmpty{A: 1},
},
},
{
name: "PtrAnonymousHeadInt64OnlyString",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: struct {
*structInt64String
}{
structInt64String: &structInt64String{A: 1},
},
},
// NilPtrAnonymousHeadInt64Only
2021-01-16 16:16:26 +03:00
{
name: "NilPtrAnonymousHeadInt64Only",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structInt64
}{
structInt64: nil,
},
},
2021-01-18 16:35:10 +03:00
{
name: "NilPtrAnonymousHeadInt64OnlyOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structInt64OmitEmpty
}{
structInt64OmitEmpty: nil,
},
},
{
name: "NilPtrAnonymousHeadInt64OnlyString",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structInt64String
}{
structInt64String: nil,
},
},
// AnonymousHeadInt64PtrOnly
2021-01-16 16:16:26 +03:00
{
name: "AnonymousHeadInt64PtrOnly",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
structInt64Ptr
}{
structInt64Ptr: structInt64Ptr{A: int64ptr(1)},
},
},
2021-01-18 16:35:10 +03:00
{
name: "AnonymousHeadInt64PtrOnlyOmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
structInt64PtrOmitEmpty
}{
structInt64PtrOmitEmpty: structInt64PtrOmitEmpty{A: int64ptr(1)},
},
},
{
name: "AnonymousHeadInt64PtrOnlyString",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: struct {
structInt64PtrString
}{
structInt64PtrString: structInt64PtrString{A: int64ptr(1)},
},
},
// AnonymousHeadInt64PtrNilOnly
2021-01-16 16:16:26 +03:00
{
name: "AnonymousHeadInt64PtrNilOnly",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: struct {
structInt64Ptr
}{
structInt64Ptr: structInt64Ptr{A: nil},
},
},
2021-01-18 16:35:10 +03:00
{
name: "AnonymousHeadInt64PtrNilOnlyOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
structInt64PtrOmitEmpty
}{
structInt64PtrOmitEmpty: structInt64PtrOmitEmpty{A: nil},
},
},
{
name: "AnonymousHeadInt64PtrNilOnlyString",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: struct {
structInt64PtrString
}{
structInt64PtrString: structInt64PtrString{A: nil},
},
},
// PtrAnonymousHeadInt64PtrOnly
2021-01-16 16:16:26 +03:00
{
name: "PtrAnonymousHeadInt64PtrOnly",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
*structInt64Ptr
}{
structInt64Ptr: &structInt64Ptr{A: int64ptr(1)},
},
},
2021-01-18 16:35:10 +03:00
{
name: "PtrAnonymousHeadInt64PtrOnlyOmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
*structInt64PtrOmitEmpty
}{
structInt64PtrOmitEmpty: &structInt64PtrOmitEmpty{A: int64ptr(1)},
},
},
{
name: "PtrAnonymousHeadInt64PtrOnlyString",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: struct {
*structInt64PtrString
}{
structInt64PtrString: &structInt64PtrString{A: int64ptr(1)},
},
},
// NilPtrAnonymousHeadInt64PtrOnly
2021-01-16 16:16:26 +03:00
{
name: "NilPtrAnonymousHeadInt64PtrOnly",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structInt64Ptr
}{
structInt64Ptr: nil,
},
},
2021-01-18 16:35:10 +03:00
{
name: "NilPtrAnonymousHeadInt64PtrOnlyOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structInt64PtrOmitEmpty
}{
structInt64PtrOmitEmpty: nil,
},
},
{
name: "NilPtrAnonymousHeadInt64PtrOnlyString",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structInt64PtrString
}{
structInt64PtrString: nil,
},
},
2021-01-16 16:16:26 +03:00
}
for _, test := range tests {
for _, indent := range []bool{true, false} {
for _, htmlEscape := range []bool{true, false} {
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
enc.SetEscapeHTML(htmlEscape)
if indent {
enc.SetIndent("", " ")
}
if err := enc.Encode(test.data); err != nil {
t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err)
}
2021-01-19 08:01:43 +03:00
stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape)
if buf.String() != stdresult {
t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String())
}
2021-01-16 16:16:26 +03:00
if indent {
got := "\n" + buf.String()
if got != test.indentExpected {
t.Fatalf("%s(htmlEscape:%T): expected %q but got %q", test.name, htmlEscape, test.indentExpected, got)
}
} else {
if strings.TrimRight(buf.String(), "\n") != test.expected {
t.Fatalf("%s(htmlEscape:%T): expected %q but got %q", test.name, htmlEscape, test.expected, buf.String())
}
}
}
}
}
}