go-json/cover_float64_test.go

2943 lines
50 KiB
Go
Raw Permalink Normal View History

2021-01-16 16:16:26 +03:00
package json_test
import (
"bytes"
"strings"
"testing"
"github.com/goccy/go-json"
)
func TestCoverFloat64(t *testing.T) {
type structFloat64 struct {
A float64 `json:"a"`
}
type structFloat64OmitEmpty struct {
A float64 `json:"a,omitempty"`
}
type structFloat64String struct {
A float64 `json:"a,string"`
}
2021-01-16 16:16:26 +03:00
type structFloat64Ptr struct {
A *float64 `json:"a"`
}
type structFloat64PtrOmitEmpty struct {
A *float64 `json:"a,omitempty"`
}
type structFloat64PtrString struct {
A *float64 `json:"a,string"`
}
2021-01-16 16:16:26 +03:00
tests := []struct {
name string
expected string
indentExpected string
data interface{}
}{
// HeadFloat64Zero
2021-01-16 16:16:26 +03:00
{
name: "HeadFloat64Zero",
expected: `{"a":0}`,
indentExpected: `
{
"a": 0
}
`,
data: struct {
A float64 `json:"a"`
}{},
},
{
name: "HeadFloat64ZeroOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
A float64 `json:"a,omitempty"`
}{},
},
{
name: "HeadFloat64ZeroString",
expected: `{"a":"0"}`,
indentExpected: `
{
"a": "0"
}
`,
data: struct {
A float64 `json:"a,string"`
}{},
},
// HeadFloat64
2021-01-16 16:16:26 +03:00
{
name: "HeadFloat64",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
A float64 `json:"a"`
}{A: 1},
},
{
name: "HeadFloat64OmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
A float64 `json:"a,omitempty"`
}{A: 1},
},
{
name: "HeadFloat64String",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: struct {
A float64 `json:"a,string"`
}{A: 1},
},
// HeadFloat64Ptr
2021-01-16 16:16:26 +03:00
{
name: "HeadFloat64Ptr",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
A *float64 `json:"a"`
}{A: float64ptr(1)},
},
{
name: "HeadFloat64PtrOmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
A *float64 `json:"a,omitempty"`
}{A: float64ptr(1)},
},
{
name: "HeadFloat64PtrString",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: struct {
A *float64 `json:"a,string"`
}{A: float64ptr(1)},
},
// HeadFloat64PtrNil
2021-01-16 16:16:26 +03:00
{
name: "HeadFloat64PtrNil",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: struct {
A *float64 `json:"a"`
}{A: nil},
},
{
name: "HeadFloat64PtrNilOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
A *float64 `json:"a,omitempty"`
}{A: nil},
},
{
name: "HeadFloat64PtrNilString",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: struct {
A *float64 `json:"a,string"`
}{A: nil},
},
// PtrHeadFloat64Zero
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadFloat64Zero",
expected: `{"a":0}`,
indentExpected: `
{
"a": 0
}
`,
data: &struct {
A float64 `json:"a"`
}{},
},
{
name: "PtrHeadFloat64ZeroOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: &struct {
A float64 `json:"a,omitempty"`
}{},
},
{
name: "PtrHeadFloat64ZeroString",
expected: `{"a":"0"}`,
indentExpected: `
{
"a": "0"
}
`,
data: &struct {
A float64 `json:"a,string"`
}{},
},
// PtrHeadFloat64
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadFloat64",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: &struct {
A float64 `json:"a"`
}{A: 1},
},
{
name: "PtrHeadFloat64OmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: &struct {
A float64 `json:"a,omitempty"`
}{A: 1},
},
{
name: "PtrHeadFloat64String",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: &struct {
A float64 `json:"a,string"`
}{A: 1},
},
// PtrHeadFloat64Ptr
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadFloat64Ptr",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: &struct {
A *float64 `json:"a"`
}{A: float64ptr(1)},
},
{
name: "PtrHeadFloat64PtrOmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: &struct {
A *float64 `json:"a,omitempty"`
}{A: float64ptr(1)},
},
{
name: "PtrHeadFloat64PtrString",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: &struct {
A *float64 `json:"a,string"`
}{A: float64ptr(1)},
},
// PtrHeadFloat64PtrNil
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadFloat64PtrNil",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: &struct {
A *float64 `json:"a"`
}{A: nil},
},
{
name: "PtrHeadFloat64PtrNilOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: &struct {
A *float64 `json:"a,omitempty"`
}{A: nil},
},
{
name: "PtrHeadFloat64PtrNilString",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: &struct {
A *float64 `json:"a,string"`
}{A: nil},
},
// PtrHeadFloat64Nil
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadFloat64Nil",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *float64 `json:"a"`
})(nil),
},
{
name: "PtrHeadFloat64NilOmitEmpty",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *float64 `json:"a,omitempty"`
})(nil),
},
{
name: "PtrHeadFloat64NilString",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *float64 `json:"a,string"`
})(nil),
},
// HeadFloat64ZeroMultiFields
2021-01-16 16:16:26 +03:00
{
name: "HeadFloat64ZeroMultiFields",
expected: `{"a":0,"b":0}`,
indentExpected: `
{
"a": 0,
"b": 0
}
`,
data: struct {
A float64 `json:"a"`
B float64 `json:"b"`
}{},
},
{
name: "HeadFloat64ZeroMultiFieldsOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
A float64 `json:"a,omitempty"`
B float64 `json:"b,omitempty"`
}{},
},
{
name: "HeadFloat64ZeroMultiFields",
expected: `{"a":"0","b":"0"}`,
indentExpected: `
{
"a": "0",
"b": "0"
}
`,
data: struct {
A float64 `json:"a,string"`
B float64 `json:"b,string"`
}{},
},
// HeadFloat64MultiFields
2021-01-16 16:16:26 +03:00
{
name: "HeadFloat64MultiFields",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
A float64 `json:"a"`
B float64 `json:"b"`
}{A: 1, B: 2},
},
{
name: "HeadFloat64MultiFieldsOmitEmpty",
2021-01-16 16:16:26 +03:00
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
A float64 `json:"a,omitempty"`
B float64 `json:"b,omitempty"`
}{A: 1, B: 2},
2021-01-16 16:16:26 +03:00
},
{
name: "HeadFloat64MultiFieldsString",
expected: `{"a":"1","b":"2"}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"a": "1",
"b": "2"
2021-01-16 16:16:26 +03:00
}
`,
data: struct {
A float64 `json:"a,string"`
B float64 `json:"b,string"`
}{A: 1, B: 2},
2021-01-16 16:16:26 +03:00
},
// HeadFloat64PtrMultiFields
2021-01-16 16:16:26 +03:00
{
name: "HeadFloat64PtrMultiFields",
expected: `{"a":1,"b":2}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"a": 1,
"b": 2
2021-01-16 16:16:26 +03:00
}
`,
data: struct {
A *float64 `json:"a"`
B *float64 `json:"b"`
}{A: float64ptr(1), B: float64ptr(2)},
2021-01-16 16:16:26 +03:00
},
{
name: "HeadFloat64PtrMultiFieldsOmitEmpty",
2021-01-16 16:16:26 +03:00
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
A *float64 `json:"a,omitempty"`
B *float64 `json:"b,omitempty"`
}{A: float64ptr(1), B: float64ptr(2)},
2021-01-16 16:16:26 +03:00
},
{
name: "HeadFloat64PtrMultiFieldsString",
expected: `{"a":"1","b":"2"}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"a": "1",
"b": "2"
2021-01-16 16:16:26 +03:00
}
`,
data: struct {
A *float64 `json:"a,string"`
B *float64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}{A: float64ptr(1), B: float64ptr(2)},
},
// HeadFloat64PtrNilMultiFields
2021-01-16 16:16:26 +03:00
{
name: "HeadFloat64PtrNilMultiFields",
2021-01-16 16:16:26 +03:00
expected: `{"a":null,"b":null}`,
indentExpected: `
{
"a": null,
"b": null
}
`,
data: struct {
2021-01-16 16:16:26 +03:00
A *float64 `json:"a"`
B *float64 `json:"b"`
}{A: nil, B: nil},
},
{
name: "HeadFloat64PtrNilMultiFieldsOmitEmpty",
expected: `{}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{}
2021-01-16 16:16:26 +03:00
`,
data: struct {
A *float64 `json:"a,omitempty"`
B *float64 `json:"b,omitempty"`
}{A: nil, B: nil},
2021-01-16 16:16:26 +03:00
},
{
name: "HeadFloat64PtrNilMultiFieldsString",
expected: `{"a":null,"b":null}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"a": null,
"b": null
}
`,
data: struct {
A *float64 `json:"a,string"`
B *float64 `json:"b,string"`
}{A: nil, B: nil},
},
// PtrHeadFloat64ZeroMultiFields
{
name: "PtrHeadFloat64ZeroMultiFields",
expected: `{"a":0,"b":0}`,
indentExpected: `
{
"a": 0,
"b": 0
}
`,
data: &struct {
A float64 `json:"a"`
B float64 `json:"b"`
}{},
},
{
name: "PtrHeadFloat64ZeroMultiFieldsOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: &struct {
A float64 `json:"a,omitempty"`
B float64 `json:"b,omitempty"`
}{},
},
{
name: "PtrHeadFloat64ZeroMultiFieldsString",
expected: `{"a":"0","b":"0"}`,
indentExpected: `
{
"a": "0",
"b": "0"
}
`,
data: &struct {
A float64 `json:"a,string"`
B float64 `json:"b,string"`
}{},
},
// PtrHeadFloat64MultiFields
{
name: "PtrHeadFloat64MultiFields",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: &struct {
A float64 `json:"a"`
B float64 `json:"b"`
}{A: 1, B: 2},
},
{
name: "PtrHeadFloat64MultiFieldsOmitEmpty",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: &struct {
A float64 `json:"a,omitempty"`
B float64 `json:"b,omitempty"`
}{A: 1, B: 2},
},
{
name: "PtrHeadFloat64MultiFieldsString",
expected: `{"a":"1","b":"2"}`,
indentExpected: `
{
"a": "1",
"b": "2"
}
`,
data: &struct {
A float64 `json:"a,string"`
B float64 `json:"b,string"`
}{A: 1, B: 2},
},
// PtrHeadFloat64PtrMultiFields
{
name: "PtrHeadFloat64PtrMultiFields",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: &struct {
A *float64 `json:"a"`
B *float64 `json:"b"`
}{A: float64ptr(1), B: float64ptr(2)},
},
{
name: "PtrHeadFloat64PtrMultiFieldsOmitEmpty",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: &struct {
A *float64 `json:"a,omitempty"`
B *float64 `json:"b,omitempty"`
}{A: float64ptr(1), B: float64ptr(2)},
},
{
name: "PtrHeadFloat64PtrMultiFieldsString",
expected: `{"a":"1","b":"2"}`,
indentExpected: `
{
"a": "1",
"b": "2"
}
`,
data: &struct {
A *float64 `json:"a,string"`
B *float64 `json:"b,string"`
}{A: float64ptr(1), B: float64ptr(2)},
},
// PtrHeadFloat64PtrNilMultiFields
{
name: "PtrHeadFloat64PtrNilMultiFields",
expected: `{"a":null,"b":null}`,
indentExpected: `
{
"a": null,
"b": null
}
`,
data: &struct {
A *float64 `json:"a"`
B *float64 `json:"b"`
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat64PtrNilMultiFieldsOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: &struct {
A *float64 `json:"a,omitempty"`
B *float64 `json:"b,omitempty"`
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat64PtrNilMultiFieldsString",
expected: `{"a":null,"b":null}`,
indentExpected: `
{
"a": null,
"b": null
}
`,
data: &struct {
A *float64 `json:"a,string"`
B *float64 `json:"b,string"`
}{A: nil, B: nil},
},
// PtrHeadFloat64NilMultiFields
{
name: "PtrHeadFloat64NilMultiFields",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *float64 `json:"a"`
B *float64 `json:"b"`
})(nil),
},
{
name: "PtrHeadFloat64NilMultiFieldsOmitEmpty",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *float64 `json:"a,omitempty"`
B *float64 `json:"b,omitempty"`
})(nil),
},
{
name: "PtrHeadFloat64NilMultiFieldsString",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *float64 `json:"a,string"`
B *float64 `json:"b,string"`
})(nil),
},
// HeadFloat64ZeroNotRoot
{
name: "HeadFloat64ZeroNotRoot",
expected: `{"A":{"a":0}}`,
indentExpected: `
{
"A": {
"a": 0
}
}
2021-01-16 16:16:26 +03:00
`,
data: struct {
A struct {
A float64 `json:"a"`
}
}{},
},
{
name: "HeadFloat64ZeroNotRootOmitEmpty",
expected: `{"A":{}}`,
indentExpected: `
{
"A": {}
}
`,
data: struct {
A struct {
A float64 `json:"a,omitempty"`
}
}{},
},
{
name: "HeadFloat64ZeroNotRootString",
expected: `{"A":{"a":"0"}}`,
indentExpected: `
{
"A": {
"a": "0"
}
}
`,
data: struct {
A struct {
A float64 `json:"a,string"`
}
}{},
},
// HeadFloat64NotRoot
2021-01-16 16:16:26 +03:00
{
name: "HeadFloat64NotRoot",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A struct {
A float64 `json:"a"`
}
}{A: struct {
A float64 `json:"a"`
}{A: 1}},
},
{
name: "HeadFloat64NotRootOmitEmpty",
2021-01-16 16:16:26 +03:00
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A struct {
A float64 `json:"a,omitempty"`
2021-01-16 16:16:26 +03:00
}
}{A: struct {
A float64 `json:"a,omitempty"`
}{A: 1}},
2021-01-16 16:16:26 +03:00
},
{
name: "HeadFloat64NotRootString",
expected: `{"A":{"a":"1"}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
"a": "1"
2021-01-16 16:16:26 +03:00
}
}
`,
data: struct {
A struct {
A float64 `json:"a,string"`
2021-01-16 16:16:26 +03:00
}
}{A: struct {
A float64 `json:"a,string"`
}{A: 1}},
2021-01-16 16:16:26 +03:00
},
// HeadFloat64PtrNotRoot
2021-01-16 16:16:26 +03:00
{
name: "HeadFloat64PtrNotRoot",
expected: `{"A":{"a":1}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
"a": 1
2021-01-16 16:16:26 +03:00
}
}
`,
data: struct {
A struct {
A *float64 `json:"a"`
2021-01-16 16:16:26 +03:00
}
}{A: struct {
A *float64 `json:"a"`
}{float64ptr(1)}},
2021-01-16 16:16:26 +03:00
},
{
name: "HeadFloat64PtrNotRootOmitEmpty",
2021-01-16 16:16:26 +03:00
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A struct {
A *float64 `json:"a,omitempty"`
2021-01-16 16:16:26 +03:00
}
}{A: struct {
A *float64 `json:"a,omitempty"`
}{float64ptr(1)}},
2021-01-16 16:16:26 +03:00
},
{
name: "HeadFloat64PtrNotRootString",
expected: `{"A":{"a":"1"}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
"a": "1"
2021-01-16 16:16:26 +03:00
}
}
`,
data: struct {
A struct {
A *float64 `json:"a,string"`
2021-01-16 16:16:26 +03:00
}
}{A: struct {
A *float64 `json:"a,string"`
}{float64ptr(1)}},
2021-01-16 16:16:26 +03:00
},
// HeadFloat64PtrNilNotRoot
2021-01-16 16:16:26 +03:00
{
name: "HeadFloat64PtrNilNotRoot",
2021-01-16 16:16:26 +03:00
expected: `{"A":{"a":null}}`,
indentExpected: `
{
"A": {
"a": null
}
}
`,
data: struct {
A struct {
A *float64 `json:"a"`
}
}{},
},
{
name: "HeadFloat64PtrNilNotRootOmitEmpty",
expected: `{"A":{}}`,
indentExpected: `
{
"A": {}
}
`,
data: struct {
A struct {
A *float64 `json:"a,omitempty"`
}
}{},
},
{
name: "HeadFloat64PtrNilNotRootString",
expected: `{"A":{"a":null}}`,
indentExpected: `
{
"A": {
"a": null
}
}
`,
data: struct {
A struct {
A *float64 `json:"a,string"`
}
}{},
},
// PtrHeadFloat64ZeroNotRoot
{
name: "PtrHeadFloat64ZeroNotRoot",
expected: `{"A":{"a":0}}`,
indentExpected: `
{
"A": {
"a": 0
}
}
`,
data: struct {
A *struct {
A float64 `json:"a"`
}
}{A: new(struct {
A float64 `json:"a"`
})},
},
{
name: "PtrHeadFloat64ZeroNotRootOmitEmpty",
expected: `{"A":{}}`,
indentExpected: `
{
"A": {}
}
`,
data: struct {
A *struct {
A float64 `json:"a,omitempty"`
}
}{A: new(struct {
A float64 `json:"a,omitempty"`
})},
},
{
name: "PtrHeadFloat64ZeroNotRootString",
expected: `{"A":{"a":"0"}}`,
indentExpected: `
{
"A": {
"a": "0"
}
}
`,
data: struct {
A *struct {
A float64 `json:"a,string"`
}
}{A: new(struct {
A float64 `json:"a,string"`
})},
},
// PtrHeadFloat64NotRoot
{
name: "PtrHeadFloat64NotRoot",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A *struct {
A float64 `json:"a"`
}
}{A: &(struct {
A float64 `json:"a"`
}{A: 1})},
},
{
name: "PtrHeadFloat64NotRootOmitEmpty",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A *struct {
A float64 `json:"a,omitempty"`
}
}{A: &(struct {
A float64 `json:"a,omitempty"`
}{A: 1})},
},
{
name: "PtrHeadFloat64NotRootString",
expected: `{"A":{"a":"1"}}`,
indentExpected: `
{
"A": {
"a": "1"
}
}
`,
data: struct {
A *struct {
A float64 `json:"a,string"`
}
}{A: &(struct {
A float64 `json:"a,string"`
}{A: 1})},
},
// PtrHeadFloat64PtrNotRoot
{
name: "PtrHeadFloat64PtrNotRoot",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A *struct {
A *float64 `json:"a"`
}
}{A: &(struct {
A *float64 `json:"a"`
}{A: float64ptr(1)})},
},
{
name: "PtrHeadFloat64PtrNotRootOmitEmpty",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A *struct {
A *float64 `json:"a,omitempty"`
}
}{A: &(struct {
A *float64 `json:"a,omitempty"`
}{A: float64ptr(1)})},
},
{
name: "PtrHeadFloat64PtrNotRootString",
expected: `{"A":{"a":"1"}}`,
indentExpected: `
{
"A": {
"a": "1"
}
}
`,
data: struct {
A *struct {
A *float64 `json:"a,string"`
}
}{A: &(struct {
A *float64 `json:"a,string"`
}{A: float64ptr(1)})},
},
// PtrHeadFloat64PtrNilNotRoot
{
name: "PtrHeadFloat64PtrNilNotRoot",
expected: `{"A":{"a":null}}`,
indentExpected: `
{
"A": {
"a": null
}
}
`,
data: struct {
A *struct {
A *float64 `json:"a"`
}
}{A: &(struct {
A *float64 `json:"a"`
}{A: nil})},
},
{
name: "PtrHeadFloat64PtrNilNotRootOmitEmpty",
expected: `{"A":{}}`,
indentExpected: `
{
"A": {}
}
`,
data: struct {
A *struct {
A *float64 `json:"a,omitempty"`
}
}{A: &(struct {
A *float64 `json:"a,omitempty"`
}{A: nil})},
},
{
name: "PtrHeadFloat64PtrNilNotRootString",
expected: `{"A":{"a":null}}`,
indentExpected: `
{
"A": {
"a": null
}
}
`,
data: struct {
A *struct {
A *float64 `json:"a,string"`
}
}{A: &(struct {
A *float64 `json:"a,string"`
}{A: nil})},
},
// PtrHeadFloat64NilNotRoot
{
name: "PtrHeadFloat64NilNotRoot",
expected: `{"A":null}`,
indentExpected: `
{
"A": null
}
`,
data: struct {
A *struct {
A *float64 `json:"a"`
}
}{A: nil},
},
{
name: "PtrHeadFloat64NilNotRootOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
A *struct {
A *float64 `json:"a,omitempty"`
} `json:",omitempty"`
}{A: nil},
},
{
name: "PtrHeadFloat64NilNotRootString",
expected: `{"A":null}`,
indentExpected: `
{
"A": null
}
`,
data: struct {
A *struct {
A *float64 `json:"a,string"`
} `json:",string"`
}{A: nil},
},
// HeadFloat64ZeroMultiFieldsNotRoot
{
name: "HeadFloat64ZeroMultiFieldsNotRoot",
expected: `{"A":{"a":0},"B":{"b":0}}`,
indentExpected: `
{
"A": {
"a": 0
},
"B": {
"b": 0
}
}
`,
data: struct {
A struct {
A float64 `json:"a"`
}
B struct {
B float64 `json:"b"`
}
}{},
},
{
name: "HeadFloat64ZeroMultiFieldsNotRootOmitEmpty",
expected: `{"A":{},"B":{}}`,
indentExpected: `
{
"A": {},
"B": {}
}
`,
data: struct {
A struct {
A float64 `json:"a,omitempty"`
}
B struct {
B float64 `json:"b,omitempty"`
}
}{},
},
{
name: "HeadFloat64ZeroMultiFieldsNotRootString",
expected: `{"A":{"a":"0"},"B":{"b":"0"}}`,
indentExpected: `
{
"A": {
"a": "0"
},
"B": {
"b": "0"
}
}
`,
data: struct {
A struct {
A float64 `json:"a,string"`
}
B struct {
B float64 `json:"b,string"`
}
}{},
},
// HeadFloat64MultiFieldsNotRoot
{
name: "HeadFloat64MultiFieldsNotRoot",
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: struct {
A struct {
A float64 `json:"a"`
}
B struct {
B float64 `json:"b"`
}
}{A: struct {
A float64 `json:"a"`
}{A: 1}, B: struct {
B float64 `json:"b"`
}{B: 2}},
},
{
name: "HeadFloat64MultiFieldsNotRootOmitEmpty",
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: struct {
A struct {
A float64 `json:"a,omitempty"`
}
B struct {
B float64 `json:"b,omitempty"`
}
}{A: struct {
A float64 `json:"a,omitempty"`
}{A: 1}, B: struct {
B float64 `json:"b,omitempty"`
}{B: 2}},
},
{
name: "HeadFloat64MultiFieldsNotRootString",
expected: `{"A":{"a":"1"},"B":{"b":"2"}}`,
indentExpected: `
{
"A": {
"a": "1"
},
"B": {
"b": "2"
}
}
`,
data: struct {
A struct {
A float64 `json:"a,string"`
}
B struct {
B float64 `json:"b,string"`
}
}{A: struct {
A float64 `json:"a,string"`
}{A: 1}, B: struct {
B float64 `json:"b,string"`
}{B: 2}},
},
// HeadFloat64PtrMultiFieldsNotRoot
{
name: "HeadFloat64PtrMultiFieldsNotRoot",
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: struct {
A struct {
A *float64 `json:"a"`
}
B struct {
B *float64 `json:"b"`
}
}{A: struct {
A *float64 `json:"a"`
}{A: float64ptr(1)}, B: struct {
B *float64 `json:"b"`
}{B: float64ptr(2)}},
},
{
name: "HeadFloat64PtrMultiFieldsNotRootOmitEmpty",
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: struct {
A struct {
A *float64 `json:"a,omitempty"`
}
B struct {
B *float64 `json:"b,omitempty"`
}
}{A: struct {
A *float64 `json:"a,omitempty"`
}{A: float64ptr(1)}, B: struct {
B *float64 `json:"b,omitempty"`
}{B: float64ptr(2)}},
},
{
name: "HeadFloat64PtrMultiFieldsNotRootString",
expected: `{"A":{"a":"1"},"B":{"b":"2"}}`,
indentExpected: `
{
"A": {
"a": "1"
},
"B": {
"b": "2"
}
}
`,
data: struct {
A struct {
A *float64 `json:"a,string"`
}
B struct {
B *float64 `json:"b,string"`
}
}{A: struct {
A *float64 `json:"a,string"`
}{A: float64ptr(1)}, B: struct {
B *float64 `json:"b,string"`
}{B: float64ptr(2)}},
},
// HeadFloat64PtrNilMultiFieldsNotRoot
{
name: "HeadFloat64PtrNilMultiFieldsNotRoot",
expected: `{"A":{"a":null},"B":{"b":null}}`,
indentExpected: `
{
"A": {
"a": null
},
"B": {
"b": null
}
}
`,
data: struct {
A struct {
A *float64 `json:"a"`
}
B struct {
B *float64 `json:"b"`
}
}{A: struct {
A *float64 `json:"a"`
}{A: nil}, B: struct {
B *float64 `json:"b"`
}{B: nil}},
},
{
name: "HeadFloat64PtrNilMultiFieldsNotRootOmitEmpty",
expected: `{"A":{},"B":{}}`,
indentExpected: `
{
"A": {},
"B": {}
}
`,
data: struct {
A struct {
A *float64 `json:"a,omitempty"`
}
B struct {
B *float64 `json:"b,omitempty"`
}
}{A: struct {
A *float64 `json:"a,omitempty"`
}{A: nil}, B: struct {
B *float64 `json:"b,omitempty"`
}{B: nil}},
},
{
name: "HeadFloat64PtrNilMultiFieldsNotRootString",
expected: `{"A":{"a":null},"B":{"b":null}}`,
indentExpected: `
{
"A": {
"a": null
},
"B": {
"b": null
}
}
`,
data: struct {
A struct {
A *float64 `json:"a,string"`
}
B struct {
B *float64 `json:"b,string"`
}
}{A: struct {
A *float64 `json:"a,string"`
}{A: nil}, B: struct {
B *float64 `json:"b,string"`
}{B: nil}},
},
// PtrHeadFloat64ZeroMultiFieldsNotRoot
{
name: "PtrHeadFloat64ZeroMultiFieldsNotRoot",
expected: `{"A":{"a":0},"B":{"b":0}}`,
indentExpected: `
{
"A": {
"a": 0
},
"B": {
"b": 0
}
}
`,
data: &struct {
A struct {
A float64 `json:"a"`
2021-01-16 16:16:26 +03:00
}
B struct {
B float64 `json:"b"`
}
}{},
2021-01-16 16:16:26 +03:00
},
{
name: "PtrHeadFloat64ZeroMultiFieldsNotRootOmitEmpty",
expected: `{"A":{},"B":{}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {},
"B": {}
2021-01-16 16:16:26 +03:00
}
`,
data: &struct {
A struct {
A float64 `json:"a,omitempty"`
2021-01-16 16:16:26 +03:00
}
B struct {
B float64 `json:"b,omitempty"`
}
}{},
2021-01-16 16:16:26 +03:00
},
{
name: "PtrHeadFloat64ZeroMultiFieldsNotRootString",
expected: `{"A":{"a":"0"},"B":{"b":"0"}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
"a": "0"
2021-01-16 16:16:26 +03:00
},
"B": {
"b": "0"
2021-01-16 16:16:26 +03:00
}
}
`,
data: &struct {
2021-01-16 16:16:26 +03:00
A struct {
A float64 `json:"a,string"`
2021-01-16 16:16:26 +03:00
}
B struct {
B float64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
}{},
},
// PtrHeadFloat64MultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadFloat64MultiFieldsNotRoot",
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-16 16:16:26 +03:00
A struct {
A float64 `json:"a"`
}
B struct {
B float64 `json:"b"`
}
}{A: struct {
A float64 `json:"a"`
}{A: 1}, B: struct {
B float64 `json:"b"`
}{B: 2}},
},
{
name: "PtrHeadFloat64MultiFieldsNotRootOmitEmpty",
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-16 16:16:26 +03:00
A struct {
A float64 `json:"a,omitempty"`
2021-01-16 16:16:26 +03:00
}
B struct {
B float64 `json:"b,omitempty"`
2021-01-16 16:16:26 +03:00
}
}{A: struct {
A float64 `json:"a,omitempty"`
}{A: 1}, B: struct {
B float64 `json:"b,omitempty"`
}{B: 2}},
2021-01-16 16:16:26 +03:00
},
{
name: "PtrHeadFloat64MultiFieldsNotRootString",
expected: `{"A":{"a":"1"},"B":{"b":"2"}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
"a": "1"
2021-01-16 16:16:26 +03:00
},
"B": {
"b": "2"
2021-01-16 16:16:26 +03:00
}
}
`,
data: &struct {
2021-01-16 16:16:26 +03:00
A struct {
A float64 `json:"a,string"`
2021-01-16 16:16:26 +03:00
}
B struct {
B float64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
}{A: struct {
A float64 `json:"a,string"`
}{A: 1}, B: struct {
B float64 `json:"b,string"`
}{B: 2}},
2021-01-16 16:16:26 +03:00
},
// PtrHeadFloat64PtrMultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadFloat64PtrMultiFieldsNotRoot",
expected: `{"A":{"a":1},"B":{"b":2}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
"a": 1
2021-01-16 16:16:26 +03:00
},
"B": {
"b": 2
2021-01-16 16:16:26 +03:00
}
}
`,
data: &struct {
A *struct {
A *float64 `json:"a"`
2021-01-16 16:16:26 +03:00
}
B *struct {
B *float64 `json:"b"`
2021-01-16 16:16:26 +03:00
}
}{A: &(struct {
A *float64 `json:"a"`
}{A: float64ptr(1)}), B: &(struct {
B *float64 `json:"b"`
}{B: float64ptr(2)})},
2021-01-16 16:16:26 +03:00
},
{
name: "PtrHeadFloat64PtrMultiFieldsNotRootOmitEmpty",
2021-01-16 16:16:26 +03:00
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: &struct {
A *struct {
A *float64 `json:"a,omitempty"`
}
B *struct {
B *float64 `json:"b,omitempty"`
}
}{A: &(struct {
A *float64 `json:"a,omitempty"`
}{A: float64ptr(1)}), B: &(struct {
B *float64 `json:"b,omitempty"`
}{B: float64ptr(2)})},
},
{
name: "PtrHeadFloat64PtrMultiFieldsNotRootString",
expected: `{"A":{"a":"1"},"B":{"b":"2"}}`,
indentExpected: `
{
"A": {
"a": "1"
},
"B": {
"b": "2"
}
}
`,
data: &struct {
A *struct {
A *float64 `json:"a,string"`
}
B *struct {
B *float64 `json:"b,string"`
}
}{A: &(struct {
A *float64 `json:"a,string"`
}{A: float64ptr(1)}), B: &(struct {
B *float64 `json:"b,string"`
}{B: float64ptr(2)})},
},
// PtrHeadFloat64PtrNilMultiFieldsNotRoot
{
name: "PtrHeadFloat64PtrNilMultiFieldsNotRoot",
expected: `{"A":null,"B":null}`,
indentExpected: `
{
"A": null,
"B": null
}
`,
data: &struct {
A *struct {
A *float64 `json:"a"`
}
B *struct {
B *float64 `json:"b"`
}
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat64PtrNilMultiFieldsNotRootOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: &struct {
A *struct {
A *float64 `json:"a,omitempty"`
} `json:",omitempty"`
B *struct {
B *float64 `json:"b,omitempty"`
} `json:",omitempty"`
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat64PtrNilMultiFieldsNotRootString",
expected: `{"A":null,"B":null}`,
indentExpected: `
{
"A": null,
"B": null
}
`,
data: &struct {
A *struct {
A *float64 `json:"a,string"`
} `json:",string"`
B *struct {
B *float64 `json:"b,string"`
} `json:",string"`
}{A: nil, B: nil},
},
// PtrHeadFloat64NilMultiFieldsNotRoot
{
name: "PtrHeadFloat64NilMultiFieldsNotRoot",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *float64 `json:"a"`
}
B *struct {
B *float64 `json:"b"`
}
})(nil),
},
{
name: "PtrHeadFloat64NilMultiFieldsNotRootOmitEmpty",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *float64 `json:"a,omitempty"`
}
B *struct {
B *float64 `json:"b,omitempty"`
}
})(nil),
},
{
name: "PtrHeadFloat64NilMultiFieldsNotRootString",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *float64 `json:"a,string"`
}
B *struct {
B *float64 `json:"b,string"`
}
})(nil),
},
// PtrHeadFloat64DoubleMultiFieldsNotRoot
{
name: "PtrHeadFloat64DoubleMultiFieldsNotRoot",
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 float64 `json:"a"`
B float64 `json:"b"`
2021-01-16 16:16:26 +03:00
}
B *struct {
A float64 `json:"a"`
2021-01-16 16:16:26 +03:00
B float64 `json:"b"`
}
}{A: &(struct {
2021-01-16 16:16:26 +03:00
A float64 `json:"a"`
B float64 `json:"b"`
}{A: 1, B: 2}), B: &(struct {
A float64 `json:"a"`
B float64 `json:"b"`
}{A: 3, B: 4})},
2021-01-16 16:16:26 +03:00
},
{
name: "PtrHeadFloat64DoubleMultiFieldsNotRootOmitEmpty",
expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": {
"a": 1,
"b": 2
},
"B": {
"a": 3,
"b": 4
}
}
`,
data: &struct {
A *struct {
A float64 `json:"a,omitempty"`
B float64 `json:"b,omitempty"`
}
B *struct {
A float64 `json:"a,omitempty"`
B float64 `json:"b,omitempty"`
}
}{A: &(struct {
A float64 `json:"a,omitempty"`
B float64 `json:"b,omitempty"`
}{A: 1, B: 2}), B: &(struct {
A float64 `json:"a,omitempty"`
B float64 `json:"b,omitempty"`
}{A: 3, B: 4})},
},
{
name: "PtrHeadFloat64DoubleMultiFieldsNotRootString",
expected: `{"A":{"a":"1","b":"2"},"B":{"a":"3","b":"4"}}`,
indentExpected: `
{
"A": {
"a": "1",
"b": "2"
2021-01-16 16:16:26 +03:00
},
"B": {
"a": "3",
"b": "4"
2021-01-16 16:16:26 +03:00
}
}
`,
data: &struct {
A *struct {
A float64 `json:"a,string"`
B float64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
B *struct {
A float64 `json:"a,string"`
B float64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
}{A: &(struct {
A float64 `json:"a,string"`
B float64 `json:"b,string"`
}{A: 1, B: 2}), B: &(struct {
A float64 `json:"a,string"`
B float64 `json:"b,string"`
}{A: 3, B: 4})},
2021-01-16 16:16:26 +03:00
},
// PtrHeadFloat64NilDoubleMultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadFloat64NilDoubleMultiFieldsNotRoot",
2021-01-16 16:16:26 +03:00
expected: `{"A":null,"B":null}`,
indentExpected: `
{
"A": null,
"B": null
}
`,
data: &struct {
A *struct {
A float64 `json:"a"`
B float64 `json:"b"`
2021-01-16 16:16:26 +03:00
}
B *struct {
A float64 `json:"a"`
B float64 `json:"b"`
2021-01-16 16:16:26 +03:00
}
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat64NilDoubleMultiFieldsNotRootOmitEmpty",
expected: `{}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{}
2021-01-16 16:16:26 +03:00
`,
data: &struct {
2021-01-16 16:16:26 +03:00
A *struct {
A float64 `json:"a,omitempty"`
B float64 `json:"b,omitempty"`
} `json:",omitempty"`
2021-01-16 16:16:26 +03:00
B *struct {
A float64 `json:"a,omitempty"`
B float64 `json:"b,omitempty"`
} `json:",omitempty"`
}{A: nil, B: nil},
2021-01-16 16:16:26 +03:00
},
{
name: "PtrHeadFloat64NilDoubleMultiFieldsNotRootString",
expected: `{"A":null,"B":null}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"A": null,
"B": null
2021-01-16 16:16:26 +03:00
}
`,
data: &struct {
A *struct {
A float64 `json:"a,string"`
B float64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
B *struct {
A float64 `json:"a,string"`
B float64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
}{A: nil, B: nil},
2021-01-16 16:16:26 +03:00
},
// PtrHeadFloat64NilDoubleMultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadFloat64NilDoubleMultiFieldsNotRoot",
expected: `null`,
2021-01-16 16:16:26 +03:00
indentExpected: `
null
2021-01-16 16:16:26 +03:00
`,
data: (*struct {
2021-01-16 16:16:26 +03:00
A *struct {
A float64 `json:"a"`
B float64 `json:"b"`
}
B *struct {
A float64 `json:"a"`
B float64 `json:"b"`
}
})(nil),
2021-01-16 16:16:26 +03:00
},
{
name: "PtrHeadFloat64NilDoubleMultiFieldsNotRootOmitEmpty",
2021-01-16 16:16:26 +03:00
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A float64 `json:"a,omitempty"`
B float64 `json:"b,omitempty"`
2021-01-16 16:16:26 +03:00
}
B *struct {
A float64 `json:"a,omitempty"`
B float64 `json:"b,omitempty"`
}
})(nil),
},
{
name: "PtrHeadFloat64NilDoubleMultiFieldsNotRootString",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A float64 `json:"a,string"`
B float64 `json:"b,string"`
}
B *struct {
A float64 `json:"a,string"`
B float64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}
})(nil),
},
// PtrHeadFloat64PtrDoubleMultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadFloat64PtrDoubleMultiFieldsNotRoot",
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 *float64 `json:"a"`
B *float64 `json:"b"`
}
B *struct {
A *float64 `json:"a"`
B *float64 `json:"b"`
}
}{A: &(struct {
A *float64 `json:"a"`
B *float64 `json:"b"`
}{A: float64ptr(1), B: float64ptr(2)}), B: &(struct {
A *float64 `json:"a"`
B *float64 `json:"b"`
}{A: float64ptr(3), B: float64ptr(4)})},
},
{
name: "PtrHeadFloat64PtrDoubleMultiFieldsNotRootOmitEmpty",
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 *float64 `json:"a,omitempty"`
B *float64 `json:"b,omitempty"`
}
B *struct {
A *float64 `json:"a,omitempty"`
B *float64 `json:"b,omitempty"`
}
}{A: &(struct {
A *float64 `json:"a,omitempty"`
B *float64 `json:"b,omitempty"`
}{A: float64ptr(1), B: float64ptr(2)}), B: &(struct {
A *float64 `json:"a,omitempty"`
B *float64 `json:"b,omitempty"`
}{A: float64ptr(3), B: float64ptr(4)})},
},
{
name: "PtrHeadFloat64PtrDoubleMultiFieldsNotRootString",
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 *float64 `json:"a,string"`
B *float64 `json:"b,string"`
}
B *struct {
A *float64 `json:"a,string"`
B *float64 `json:"b,string"`
}
}{A: &(struct {
A *float64 `json:"a,string"`
B *float64 `json:"b,string"`
}{A: float64ptr(1), B: float64ptr(2)}), B: &(struct {
A *float64 `json:"a,string"`
B *float64 `json:"b,string"`
}{A: float64ptr(3), B: float64ptr(4)})},
},
// PtrHeadFloat64PtrNilDoubleMultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRoot",
expected: `{"A":null,"B":null}`,
indentExpected: `
{
"A": null,
"B": null
}
`,
data: &struct {
A *struct {
A *float64 `json:"a"`
B *float64 `json:"b"`
}
B *struct {
A *float64 `json:"a"`
B *float64 `json:"b"`
}
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRootOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: &struct {
A *struct {
A *float64 `json:"a,omitempty"`
B *float64 `json:"b,omitempty"`
} `json:",omitempty"`
B *struct {
A *float64 `json:"a,omitempty"`
B *float64 `json:"b,omitempty"`
} `json:",omitempty"`
}{A: nil, B: nil},
},
{
name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRootString",
expected: `{"A":null,"B":null}`,
indentExpected: `
{
"A": null,
"B": null
}
`,
data: &struct {
A *struct {
A *float64 `json:"a,string"`
B *float64 `json:"b,string"`
}
B *struct {
A *float64 `json:"a,string"`
B *float64 `json:"b,string"`
}
}{A: nil, B: nil},
},
// PtrHeadFloat64PtrNilDoubleMultiFieldsNotRoot
2021-01-16 16:16:26 +03:00
{
name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRoot",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *float64 `json:"a"`
B *float64 `json:"b"`
}
B *struct {
A *float64 `json:"a"`
B *float64 `json:"b"`
}
})(nil),
},
{
name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRootOmitEmpty",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *float64 `json:"a,omitempty"`
B *float64 `json:"b,omitempty"`
}
B *struct {
A *float64 `json:"a,omitempty"`
B *float64 `json:"b,omitempty"`
}
})(nil),
},
{
name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRootString",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *float64 `json:"a,string"`
B *float64 `json:"b,string"`
}
B *struct {
A *float64 `json:"a,string"`
B *float64 `json:"b,string"`
}
})(nil),
},
// AnonymousHeadFloat64
{
name: "AnonymousHeadFloat64",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
structFloat64
B float64 `json:"b"`
}{
structFloat64: structFloat64{A: 1},
B: 2,
},
},
{
name: "AnonymousHeadFloat64OmitEmpty",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
structFloat64OmitEmpty
B float64 `json:"b,omitempty"`
}{
structFloat64OmitEmpty: structFloat64OmitEmpty{A: 1},
B: 2,
},
},
{
name: "AnonymousHeadFloat64String",
expected: `{"a":"1","b":"2"}`,
indentExpected: `
{
"a": "1",
"b": "2"
}
`,
data: struct {
structFloat64String
B float64 `json:"b,string"`
}{
structFloat64String: structFloat64String{A: 1},
B: 2,
},
},
// PtrAnonymousHeadFloat64
{
name: "PtrAnonymousHeadFloat64",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
*structFloat64
B float64 `json:"b"`
}{
structFloat64: &structFloat64{A: 1},
B: 2,
},
},
{
name: "PtrAnonymousHeadFloat64OmitEmpty",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
*structFloat64OmitEmpty
B float64 `json:"b,omitempty"`
}{
structFloat64OmitEmpty: &structFloat64OmitEmpty{A: 1},
B: 2,
},
},
{
name: "PtrAnonymousHeadFloat64String",
expected: `{"a":"1","b":"2"}`,
indentExpected: `
{
"a": "1",
"b": "2"
}
`,
data: struct {
*structFloat64String
B float64 `json:"b,string"`
}{
structFloat64String: &structFloat64String{A: 1},
B: 2,
},
},
// NilPtrAnonymousHeadFloat64
{
name: "NilPtrAnonymousHeadFloat64",
expected: `{"b":2}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"b": 2
}
`,
data: struct {
*structFloat64
2021-01-16 16:16:26 +03:00
B float64 `json:"b"`
}{
structFloat64: nil,
2021-01-16 16:16:26 +03:00
B: 2,
},
},
{
name: "NilPtrAnonymousHeadFloat64OmitEmpty",
expected: `{"b":2}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"b": 2
}
`,
data: struct {
*structFloat64OmitEmpty
B float64 `json:"b,omitempty"`
2021-01-16 16:16:26 +03:00
}{
structFloat64OmitEmpty: nil,
B: 2,
2021-01-16 16:16:26 +03:00
},
},
{
name: "NilPtrAnonymousHeadFloat64String",
expected: `{"b":"2"}`,
2021-01-16 16:16:26 +03:00
indentExpected: `
{
"b": "2"
2021-01-16 16:16:26 +03:00
}
`,
data: struct {
*structFloat64String
B float64 `json:"b,string"`
2021-01-16 16:16:26 +03:00
}{
structFloat64String: nil,
B: 2,
2021-01-16 16:16:26 +03:00
},
},
// AnonymousHeadFloat64Ptr
2021-01-16 16:16:26 +03:00
{
name: "AnonymousHeadFloat64Ptr",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
structFloat64Ptr
B *float64 `json:"b"`
}{
structFloat64Ptr: structFloat64Ptr{A: float64ptr(1)},
B: float64ptr(2),
},
},
{
name: "AnonymousHeadFloat64PtrOmitEmpty",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
structFloat64PtrOmitEmpty
B *float64 `json:"b,omitempty"`
}{
structFloat64PtrOmitEmpty: structFloat64PtrOmitEmpty{A: float64ptr(1)},
B: float64ptr(2),
},
},
{
name: "AnonymousHeadFloat64PtrString",
expected: `{"a":"1","b":"2"}`,
indentExpected: `
{
"a": "1",
"b": "2"
}
`,
data: struct {
structFloat64PtrString
B *float64 `json:"b,string"`
}{
structFloat64PtrString: structFloat64PtrString{A: float64ptr(1)},
B: float64ptr(2),
},
},
// AnonymousHeadFloat64PtrNil
2021-01-16 16:16:26 +03:00
{
name: "AnonymousHeadFloat64PtrNil",
expected: `{"a":null,"b":2}`,
indentExpected: `
{
"a": null,
"b": 2
}
`,
data: struct {
structFloat64Ptr
B *float64 `json:"b"`
}{
structFloat64Ptr: structFloat64Ptr{A: nil},
B: float64ptr(2),
},
},
{
name: "AnonymousHeadFloat64PtrNilOmitEmpty",
expected: `{"b":2}`,
indentExpected: `
{
"b": 2
}
`,
data: struct {
structFloat64PtrOmitEmpty
B *float64 `json:"b,omitempty"`
}{
structFloat64PtrOmitEmpty: structFloat64PtrOmitEmpty{A: nil},
B: float64ptr(2),
},
},
{
name: "AnonymousHeadFloat64PtrNilString",
expected: `{"a":null,"b":"2"}`,
indentExpected: `
{
"a": null,
"b": "2"
}
`,
data: struct {
structFloat64PtrString
B *float64 `json:"b,string"`
}{
structFloat64PtrString: structFloat64PtrString{A: nil},
B: float64ptr(2),
},
},
// PtrAnonymousHeadFloat64Ptr
2021-01-16 16:16:26 +03:00
{
name: "PtrAnonymousHeadFloat64Ptr",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
*structFloat64Ptr
B *float64 `json:"b"`
}{
structFloat64Ptr: &structFloat64Ptr{A: float64ptr(1)},
B: float64ptr(2),
},
},
{
name: "PtrAnonymousHeadFloat64PtrOmitEmpty",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
*structFloat64PtrOmitEmpty
B *float64 `json:"b,omitempty"`
}{
structFloat64PtrOmitEmpty: &structFloat64PtrOmitEmpty{A: float64ptr(1)},
B: float64ptr(2),
},
},
{
name: "PtrAnonymousHeadFloat64PtrString",
expected: `{"a":"1","b":"2"}`,
indentExpected: `
{
"a": "1",
"b": "2"
}
`,
data: struct {
*structFloat64PtrString
B *float64 `json:"b,string"`
}{
structFloat64PtrString: &structFloat64PtrString{A: float64ptr(1)},
B: float64ptr(2),
},
},
// NilPtrAnonymousHeadFloat64Ptr
2021-01-16 16:16:26 +03:00
{
name: "NilPtrAnonymousHeadFloat64Ptr",
expected: `{"b":2}`,
indentExpected: `
{
"b": 2
}
`,
data: struct {
*structFloat64Ptr
B *float64 `json:"b"`
}{
structFloat64Ptr: nil,
B: float64ptr(2),
},
},
{
name: "NilPtrAnonymousHeadFloat64PtrOmitEmpty",
expected: `{"b":2}`,
indentExpected: `
{
"b": 2
}
`,
data: struct {
*structFloat64PtrOmitEmpty
B *float64 `json:"b,omitempty"`
}{
structFloat64PtrOmitEmpty: nil,
B: float64ptr(2),
},
},
{
name: "NilPtrAnonymousHeadFloat64PtrString",
expected: `{"b":"2"}`,
indentExpected: `
{
"b": "2"
}
`,
data: struct {
*structFloat64PtrString
B *float64 `json:"b,string"`
}{
structFloat64PtrString: nil,
B: float64ptr(2),
},
},
// AnonymousHeadFloat64Only
2021-01-16 16:16:26 +03:00
{
name: "AnonymousHeadFloat64Only",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
structFloat64
}{
structFloat64: structFloat64{A: 1},
},
},
{
name: "AnonymousHeadFloat64OnlyOmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
structFloat64OmitEmpty
}{
structFloat64OmitEmpty: structFloat64OmitEmpty{A: 1},
},
},
{
name: "AnonymousHeadFloat64OnlyString",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: struct {
structFloat64String
}{
structFloat64String: structFloat64String{A: 1},
},
},
// PtrAnonymousHeadFloat64Only
2021-01-16 16:16:26 +03:00
{
name: "PtrAnonymousHeadFloat64Only",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
*structFloat64
}{
structFloat64: &structFloat64{A: 1},
},
},
{
name: "PtrAnonymousHeadFloat64OnlyOmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
*structFloat64OmitEmpty
}{
structFloat64OmitEmpty: &structFloat64OmitEmpty{A: 1},
},
},
{
name: "PtrAnonymousHeadFloat64OnlyString",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: struct {
*structFloat64String
}{
structFloat64String: &structFloat64String{A: 1},
},
},
// NilPtrAnonymousHeadFloat64Only
2021-01-16 16:16:26 +03:00
{
name: "NilPtrAnonymousHeadFloat64Only",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structFloat64
}{
structFloat64: nil,
},
},
{
name: "NilPtrAnonymousHeadFloat64OnlyOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structFloat64OmitEmpty
}{
structFloat64OmitEmpty: nil,
},
},
{
name: "NilPtrAnonymousHeadFloat64OnlyString",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structFloat64String
}{
structFloat64String: nil,
},
},
// AnonymousHeadFloat64PtrOnly
2021-01-16 16:16:26 +03:00
{
name: "AnonymousHeadFloat64PtrOnly",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
structFloat64Ptr
}{
structFloat64Ptr: structFloat64Ptr{A: float64ptr(1)},
},
},
{
name: "AnonymousHeadFloat64PtrOnlyOmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
structFloat64PtrOmitEmpty
}{
structFloat64PtrOmitEmpty: structFloat64PtrOmitEmpty{A: float64ptr(1)},
},
},
{
name: "AnonymousHeadFloat64PtrOnlyString",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: struct {
structFloat64PtrString
}{
structFloat64PtrString: structFloat64PtrString{A: float64ptr(1)},
},
},
// AnonymousHeadFloat64PtrNilOnly
2021-01-16 16:16:26 +03:00
{
name: "AnonymousHeadFloat64PtrNilOnly",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: struct {
structFloat64Ptr
}{
structFloat64Ptr: structFloat64Ptr{A: nil},
},
},
{
name: "AnonymousHeadFloat64PtrNilOnlyOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
structFloat64PtrOmitEmpty
}{
structFloat64PtrOmitEmpty: structFloat64PtrOmitEmpty{A: nil},
},
},
{
name: "AnonymousHeadFloat64PtrNilOnlyString",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: struct {
structFloat64PtrString
}{
structFloat64PtrString: structFloat64PtrString{A: nil},
},
},
// PtrAnonymousHeadFloat64PtrOnly
2021-01-16 16:16:26 +03:00
{
name: "PtrAnonymousHeadFloat64PtrOnly",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
*structFloat64Ptr
}{
structFloat64Ptr: &structFloat64Ptr{A: float64ptr(1)},
},
},
{
name: "PtrAnonymousHeadFloat64PtrOnlyOmitEmpty",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
*structFloat64PtrOmitEmpty
}{
structFloat64PtrOmitEmpty: &structFloat64PtrOmitEmpty{A: float64ptr(1)},
},
},
{
name: "PtrAnonymousHeadFloat64PtrOnlyString",
expected: `{"a":"1"}`,
indentExpected: `
{
"a": "1"
}
`,
data: struct {
*structFloat64PtrString
}{
structFloat64PtrString: &structFloat64PtrString{A: float64ptr(1)},
},
},
// NilPtrAnonymousHeadFloat64PtrOnly
2021-01-16 16:16:26 +03:00
{
name: "NilPtrAnonymousHeadFloat64PtrOnly",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structFloat64Ptr
}{
structFloat64Ptr: nil,
},
},
{
name: "NilPtrAnonymousHeadFloat64PtrOnlyOmitEmpty",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structFloat64PtrOmitEmpty
}{
structFloat64PtrOmitEmpty: nil,
},
},
{
name: "NilPtrAnonymousHeadFloat64PtrOnlyString",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structFloat64PtrString
}{
structFloat64PtrString: 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)
}
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())
}
}
}
}
}
}