forked from mirror/go-json
Add indent test cases for int8 type
This commit is contained in:
parent
5600902a4c
commit
9f0ff9c509
389
coverage_test.go
389
coverage_test.go
|
@ -639,7 +639,6 @@ null
|
|||
}
|
||||
}
|
||||
`,
|
||||
|
||||
data: &struct {
|
||||
A *struct {
|
||||
A int `json:"a"`
|
||||
|
@ -981,13 +980,13 @@ null
|
|||
var buf bytes.Buffer
|
||||
enc := NewEncoder(&buf)
|
||||
enc.SetEscapeHTML(htmlEscape)
|
||||
if indent && test.indentExpected != "" {
|
||||
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)
|
||||
}
|
||||
if indent && test.indentExpected != "" {
|
||||
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)
|
||||
|
@ -1011,13 +1010,19 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
expected string
|
||||
data interface{}
|
||||
name string
|
||||
expected string
|
||||
indentExpected string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "HeadInt8Zero",
|
||||
expected: `{"a":0}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 0
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A int8 `json:"a"`
|
||||
}{},
|
||||
|
@ -1025,6 +1030,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8",
|
||||
expected: `{"a":1}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A int8 `json:"a"`
|
||||
}{A: 1},
|
||||
|
@ -1032,6 +1042,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8Ptr",
|
||||
expected: `{"a":1}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *int8 `json:"a"`
|
||||
}{A: int8ptr(1)},
|
||||
|
@ -1039,6 +1054,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8PtrNil",
|
||||
expected: `{"a":null}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": null
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *int8 `json:"a"`
|
||||
}{A: nil},
|
||||
|
@ -1046,6 +1066,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8Zero",
|
||||
expected: `{"a":0}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 0
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A int8 `json:"a"`
|
||||
}{},
|
||||
|
@ -1053,6 +1078,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8",
|
||||
expected: `{"a":1}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A int8 `json:"a"`
|
||||
}{A: 1},
|
||||
|
@ -1060,6 +1090,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8Ptr",
|
||||
expected: `{"a":1}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *int8 `json:"a"`
|
||||
}{A: int8ptr(1)},
|
||||
|
@ -1067,6 +1102,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8PtrNil",
|
||||
expected: `{"a":null}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": null
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *int8 `json:"a"`
|
||||
}{A: nil},
|
||||
|
@ -1074,6 +1114,9 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8Nil",
|
||||
expected: `null`,
|
||||
indentExpected: `
|
||||
null
|
||||
`,
|
||||
data: (*struct {
|
||||
A *int8 `json:"a"`
|
||||
})(nil),
|
||||
|
@ -1081,6 +1124,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8ZeroMultiFields",
|
||||
expected: `{"a":0,"b":0}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 0,
|
||||
"b": 0
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A int8 `json:"a"`
|
||||
B int8 `json:"b"`
|
||||
|
@ -1089,6 +1138,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8MultiFields",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A int8 `json:"a"`
|
||||
B int8 `json:"b"`
|
||||
|
@ -1097,6 +1152,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8PtrMultiFields",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *int8 `json:"a"`
|
||||
B *int8 `json:"b"`
|
||||
|
@ -1105,6 +1166,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8PtrNilMultiFields",
|
||||
expected: `{"a":null,"b":null}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": null,
|
||||
"b": null
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *int8 `json:"a"`
|
||||
B *int8 `json:"b"`
|
||||
|
@ -1113,6 +1180,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8ZeroMultiFields",
|
||||
expected: `{"a":0,"b":0}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 0,
|
||||
"b": 0
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A int8 `json:"a"`
|
||||
B int8 `json:"b"`
|
||||
|
@ -1121,6 +1194,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8MultiFields",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A int8 `json:"a"`
|
||||
B int8 `json:"b"`
|
||||
|
@ -1129,6 +1208,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8PtrMultiFields",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *int8 `json:"a"`
|
||||
B *int8 `json:"b"`
|
||||
|
@ -1137,6 +1222,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8PtrNilMultiFields",
|
||||
expected: `{"a":null,"b":null}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": null,
|
||||
"b": null
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *int8 `json:"a"`
|
||||
B *int8 `json:"b"`
|
||||
|
@ -1145,6 +1236,9 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8NilMultiFields",
|
||||
expected: `null`,
|
||||
indentExpected: `
|
||||
null
|
||||
`,
|
||||
data: (*struct {
|
||||
A *int8 `json:"a"`
|
||||
B *int8 `json:"b"`
|
||||
|
@ -1153,6 +1247,13 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8ZeroNotRoot",
|
||||
expected: `{"A":{"a":0}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": 0
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A struct {
|
||||
A int8 `json:"a"`
|
||||
|
@ -1162,6 +1263,13 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8NotRoot",
|
||||
expected: `{"A":{"a":1}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": 1
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A struct {
|
||||
A int8 `json:"a"`
|
||||
|
@ -1173,6 +1281,13 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8PtrNotRoot",
|
||||
expected: `{"A":{"a":1}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": 1
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A struct {
|
||||
A *int8 `json:"a"`
|
||||
|
@ -1184,6 +1299,13 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8PtrNilNotRoot",
|
||||
expected: `{"A":{"a":null}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": null
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A struct {
|
||||
A *int8 `json:"a"`
|
||||
|
@ -1193,6 +1315,13 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8ZeroNotRoot",
|
||||
expected: `{"A":{"a":0}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": 0
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *struct {
|
||||
A int8 `json:"a"`
|
||||
|
@ -1204,6 +1333,13 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8NotRoot",
|
||||
expected: `{"A":{"a":1}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": 1
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *struct {
|
||||
A int8 `json:"a"`
|
||||
|
@ -1215,6 +1351,13 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8PtrNotRoot",
|
||||
expected: `{"A":{"a":1}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": 1
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *struct {
|
||||
A *int8 `json:"a"`
|
||||
|
@ -1226,6 +1369,13 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8PtrNilNotRoot",
|
||||
expected: `{"A":{"a":null}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": null
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *struct {
|
||||
A *int8 `json:"a"`
|
||||
|
@ -1237,6 +1387,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8NilNotRoot",
|
||||
expected: `{"A":null}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": null
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *struct {
|
||||
A *int8 `json:"a"`
|
||||
|
@ -1246,6 +1401,16 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8ZeroMultiFieldsNotRoot",
|
||||
expected: `{"A":{"a":0},"B":{"b":0}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": 0
|
||||
},
|
||||
"B": {
|
||||
"b": 0
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A struct {
|
||||
A int8 `json:"a"`
|
||||
|
@ -1258,6 +1423,16 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8MultiFieldsNotRoot",
|
||||
expected: `{"A":{"a":1},"B":{"b":2}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": 1
|
||||
},
|
||||
"B": {
|
||||
"b": 2
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A struct {
|
||||
A int8 `json:"a"`
|
||||
|
@ -1274,6 +1449,16 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8PtrMultiFieldsNotRoot",
|
||||
expected: `{"A":{"a":1},"B":{"b":2}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": 1
|
||||
},
|
||||
"B": {
|
||||
"b": 2
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A struct {
|
||||
A *int8 `json:"a"`
|
||||
|
@ -1290,6 +1475,16 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "HeadInt8PtrNilMultiFieldsNotRoot",
|
||||
expected: `{"A":{"a":null},"B":{"b":null}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": null
|
||||
},
|
||||
"B": {
|
||||
"b": null
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A struct {
|
||||
A *int8 `json:"a"`
|
||||
|
@ -1306,6 +1501,16 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8ZeroMultiFieldsNotRoot",
|
||||
expected: `{"A":{"a":0},"B":{"b":0}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": 0
|
||||
},
|
||||
"B": {
|
||||
"b": 0
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A struct {
|
||||
A int8 `json:"a"`
|
||||
|
@ -1318,6 +1523,16 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8MultiFieldsNotRoot",
|
||||
expected: `{"A":{"a":1},"B":{"b":2}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": 1
|
||||
},
|
||||
"B": {
|
||||
"b": 2
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A struct {
|
||||
A int8 `json:"a"`
|
||||
|
@ -1334,6 +1549,16 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8PtrMultiFieldsNotRoot",
|
||||
expected: `{"A":{"a":1},"B":{"b":2}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": 1
|
||||
},
|
||||
"B": {
|
||||
"b": 2
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *struct {
|
||||
A *int8 `json:"a"`
|
||||
|
@ -1350,6 +1575,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8PtrNilMultiFieldsNotRoot",
|
||||
expected: `{"A":null,"B":null}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": null,
|
||||
"B": null
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *struct {
|
||||
A *int8 `json:"a"`
|
||||
|
@ -1362,6 +1593,9 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8NilMultiFieldsNotRoot",
|
||||
expected: `null`,
|
||||
indentExpected: `
|
||||
null
|
||||
`,
|
||||
data: (*struct {
|
||||
A *struct {
|
||||
A *int8 `json:"a"`
|
||||
|
@ -1374,6 +1608,18 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8DoubleMultiFieldsNotRoot",
|
||||
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 int8 `json:"a"`
|
||||
|
@ -1394,6 +1640,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8NilDoubleMultiFieldsNotRoot",
|
||||
expected: `{"A":null,"B":null}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": null,
|
||||
"B": null
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *struct {
|
||||
A int8 `json:"a"`
|
||||
|
@ -1408,6 +1660,9 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8NilDoubleMultiFieldsNotRoot",
|
||||
expected: `null`,
|
||||
indentExpected: `
|
||||
null
|
||||
`,
|
||||
data: (*struct {
|
||||
A *struct {
|
||||
A int8 `json:"a"`
|
||||
|
@ -1422,6 +1677,18 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8PtrDoubleMultiFieldsNotRoot",
|
||||
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 *int8 `json:"a"`
|
||||
|
@ -1442,6 +1709,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8PtrNilDoubleMultiFieldsNotRoot",
|
||||
expected: `{"A":null,"B":null}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": null,
|
||||
"B": null
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *struct {
|
||||
A *int8 `json:"a"`
|
||||
|
@ -1456,6 +1729,9 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrHeadInt8PtrNilDoubleMultiFieldsNotRoot",
|
||||
expected: `null`,
|
||||
indentExpected: `
|
||||
null
|
||||
`,
|
||||
data: (*struct {
|
||||
A *struct {
|
||||
A *int8 `json:"a"`
|
||||
|
@ -1470,6 +1746,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "AnonymousHeadInt8",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
structInt8
|
||||
B int8 `json:"b"`
|
||||
|
@ -1481,6 +1763,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrAnonymousHeadInt8",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
*structInt8
|
||||
B int8 `json:"b"`
|
||||
|
@ -1492,6 +1780,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "NilPtrAnonymousHeadInt8",
|
||||
expected: `{"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
*structInt8
|
||||
B int8 `json:"b"`
|
||||
|
@ -1503,6 +1796,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "AnonymousHeadInt8Ptr",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
structInt8Ptr
|
||||
B *int8 `json:"b"`
|
||||
|
@ -1514,6 +1813,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "AnonymousHeadInt8PtrNil",
|
||||
expected: `{"a":null,"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": null,
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
structInt8Ptr
|
||||
B *int8 `json:"b"`
|
||||
|
@ -1525,6 +1830,12 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrAnonymousHeadInt8Ptr",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
*structInt8Ptr
|
||||
B *int8 `json:"b"`
|
||||
|
@ -1536,6 +1847,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "NilPtrAnonymousHeadInt8Ptr",
|
||||
expected: `{"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
*structInt8Ptr
|
||||
B *int8 `json:"b"`
|
||||
|
@ -1547,6 +1863,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "AnonymousHeadInt8Only",
|
||||
expected: `{"a":1}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
structInt8
|
||||
}{
|
||||
|
@ -1556,6 +1877,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrAnonymousHeadInt8Only",
|
||||
expected: `{"a":1}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
*structInt8
|
||||
}{
|
||||
|
@ -1565,6 +1891,9 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "NilPtrAnonymousHeadInt8Only",
|
||||
expected: `{}`,
|
||||
indentExpected: `
|
||||
{}
|
||||
`,
|
||||
data: struct {
|
||||
*structInt8
|
||||
}{
|
||||
|
@ -1574,6 +1903,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "AnonymousHeadInt8PtrOnly",
|
||||
expected: `{"a":1}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
structInt8Ptr
|
||||
}{
|
||||
|
@ -1583,6 +1917,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "AnonymousHeadInt8PtrNilOnly",
|
||||
expected: `{"a":null}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": null
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
structInt8Ptr
|
||||
}{
|
||||
|
@ -1592,6 +1931,11 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "PtrAnonymousHeadInt8PtrOnly",
|
||||
expected: `{"a":1}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
*structInt8Ptr
|
||||
}{
|
||||
|
@ -1601,6 +1945,9 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
{
|
||||
name: "NilPtrAnonymousHeadInt8PtrOnly",
|
||||
expected: `{}`,
|
||||
indentExpected: `
|
||||
{}
|
||||
`,
|
||||
data: struct {
|
||||
*structInt8Ptr
|
||||
}{
|
||||
|
@ -1609,15 +1956,27 @@ func TestCoverStructHeadInt8(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
for _, htmlEscape := range []bool{true, false} {
|
||||
var buf bytes.Buffer
|
||||
enc := NewEncoder(&buf)
|
||||
enc.SetEscapeHTML(htmlEscape)
|
||||
if err := enc.Encode(test.data); err != nil {
|
||||
t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err)
|
||||
}
|
||||
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())
|
||||
for _, indent := range []bool{true, false} {
|
||||
for _, htmlEscape := range []bool{true, false} {
|
||||
var buf bytes.Buffer
|
||||
enc := 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)
|
||||
}
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
326
encode_vm.go
326
encode_vm.go
|
@ -5713,13 +5713,11 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
case opStructFieldHeadInt8Indent:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = encodeIndentComma(b)
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
|
@ -5727,19 +5725,26 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadInt8OnlyIndent, opStructFieldHeadInt8OnlyIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(e.ptrToInt8(p)))
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructEscapedFieldPtrHeadInt8Indent:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructEscapedFieldHeadInt8Indent:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = encodeIndentComma(b)
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
|
@ -5747,6 +5752,289 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructEscapedFieldPtrHeadInt8OnlyIndent, opStructEscapedFieldHeadInt8OnlyIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(e.ptrToInt8(p)))
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadInt8PtrIndent:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructFieldHeadInt8PtrIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
p = e.ptrToPtr(p)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = appendInt(b, int64(e.ptrToInt8(p+code.offset)))
|
||||
}
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadInt8PtrOnlyIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
store(ctxptr, code.idx, e.ptrToPtr(p))
|
||||
fallthrough
|
||||
case opStructFieldHeadInt8PtrOnlyIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = appendInt(b, int64(e.ptrToInt8(p+code.offset)))
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructEscapedFieldPtrHeadInt8PtrIndent:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructEscapedFieldHeadInt8PtrIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
p = e.ptrToPtr(p)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = appendInt(b, int64(e.ptrToInt8(p+code.offset)))
|
||||
}
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructEscapedFieldPtrHeadInt8PtrOnlyIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
store(ctxptr, code.idx, e.ptrToPtr(p))
|
||||
fallthrough
|
||||
case opStructEscapedFieldHeadInt8PtrOnlyIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = appendInt(b, int64(e.ptrToInt8(p+code.offset)))
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldHeadInt8NPtrIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
for i := 0; i < code.ptrNum; i++ {
|
||||
if p == 0 {
|
||||
break
|
||||
}
|
||||
p = e.ptrToPtr(p)
|
||||
}
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = appendInt(b, int64(e.ptrToInt8(p+code.offset)))
|
||||
}
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructEscapedFieldHeadInt8NPtrIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
for i := 0; i < code.ptrNum; i++ {
|
||||
if p == 0 {
|
||||
break
|
||||
}
|
||||
p = e.ptrToPtr(p)
|
||||
}
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = appendInt(b, int64(e.ptrToInt8(p+code.offset)))
|
||||
}
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrAnonymousHeadInt8Indent:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructFieldAnonymousHeadInt8Indent:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset)))
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructEscapedFieldPtrAnonymousHeadInt8Indent:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructEscapedFieldAnonymousHeadInt8Indent:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset)))
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrAnonymousHeadInt8OnlyIndent, opStructFieldAnonymousHeadInt8OnlyIndent:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset)))
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructEscapedFieldPtrAnonymousHeadInt8OnlyIndent, opStructEscapedFieldAnonymousHeadInt8OnlyIndent:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset)))
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrAnonymousHeadInt8PtrIndent:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructFieldAnonymousHeadInt8PtrIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
p = e.ptrToPtr(p)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = appendInt(b, int64(e.ptrToInt8(p+code.offset)))
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructEscapedFieldPtrAnonymousHeadInt8PtrIndent:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructEscapedFieldAnonymousHeadInt8PtrIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
p = e.ptrToPtr(p)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = appendInt(b, int64(e.ptrToInt8(p+code.offset)))
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrAnonymousHeadInt8PtrOnlyIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
store(ctxptr, code.idx, e.ptrToPtr(p))
|
||||
fallthrough
|
||||
case opStructFieldAnonymousHeadInt8PtrOnlyIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = appendInt(b, int64(e.ptrToInt8(p+code.offset)))
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructEscapedFieldPtrAnonymousHeadInt8PtrOnlyIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
store(ctxptr, code.idx, e.ptrToPtr(p))
|
||||
fallthrough
|
||||
case opStructEscapedFieldAnonymousHeadInt8PtrOnlyIndent:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = appendInt(b, int64(e.ptrToInt8(p+code.offset)))
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadInt16Indent:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
|
@ -14696,6 +14984,32 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset)))
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndInt8PtrIndent:
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
p := e.ptrToPtr(ptr + code.offset)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = appendInt(b, int64(e.ptrToInt8(p)))
|
||||
}
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEscapedEndInt8PtrIndent:
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
p := e.ptrToPtr(ptr + code.offset)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
} else {
|
||||
b = appendInt(b, int64(e.ptrToInt8(p)))
|
||||
}
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndInt16Indent:
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
|
|
Loading…
Reference in New Issue