Add indent test cases for int type

This commit is contained in:
Masaaki Goshima 2021-01-10 09:40:38 +09:00
parent a9396cb5d1
commit 56326bfb35
2 changed files with 745 additions and 37 deletions

View File

@ -29,13 +29,19 @@ func TestCoverStructHeadInt(t *testing.T) {
}
tests := []struct {
name string
expected string
data interface{}
name string
expected string
indentExpected string
data interface{}
}{
{
name: "HeadIntZero",
expected: `{"a":0}`,
indentExpected: `
{
"a": 0
}
`,
data: struct {
A int `json:"a"`
}{},
@ -43,6 +49,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadInt",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
A int `json:"a"`
}{A: 1},
@ -50,6 +61,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadIntPtr",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
A *int `json:"a"`
}{A: intptr(1)},
@ -57,6 +73,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadIntPtrNil",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: struct {
A *int `json:"a"`
}{A: nil},
@ -64,6 +85,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntZero",
expected: `{"a":0}`,
indentExpected: `
{
"a": 0
}
`,
data: &struct {
A int `json:"a"`
}{},
@ -71,6 +97,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadInt",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: &struct {
A int `json:"a"`
}{A: 1},
@ -78,6 +109,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntPtr",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: &struct {
A *int `json:"a"`
}{A: intptr(1)},
@ -85,6 +121,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntPtrNil",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: &struct {
A *int `json:"a"`
}{A: nil},
@ -92,6 +133,9 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntNil",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *int `json:"a"`
})(nil),
@ -99,6 +143,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadIntZeroMultiFields",
expected: `{"a":0,"b":0}`,
indentExpected: `
{
"a": 0,
"b": 0
}
`,
data: struct {
A int `json:"a"`
B int `json:"b"`
@ -107,6 +157,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadIntMultiFields",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
A int `json:"a"`
B int `json:"b"`
@ -115,6 +171,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadIntPtrMultiFields",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
A *int `json:"a"`
B *int `json:"b"`
@ -123,6 +185,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadIntPtrNilMultiFields",
expected: `{"a":null,"b":null}`,
indentExpected: `
{
"a": null,
"b": null
}
`,
data: struct {
A *int `json:"a"`
B *int `json:"b"`
@ -131,6 +199,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntZeroMultiFields",
expected: `{"a":0,"b":0}`,
indentExpected: `
{
"a": 0,
"b": 0
}
`,
data: &struct {
A int `json:"a"`
B int `json:"b"`
@ -139,6 +213,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntMultiFields",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: &struct {
A int `json:"a"`
B int `json:"b"`
@ -147,6 +227,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntPtrMultiFields",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: &struct {
A *int `json:"a"`
B *int `json:"b"`
@ -155,6 +241,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntPtrNilMultiFields",
expected: `{"a":null,"b":null}`,
indentExpected: `
{
"a": null,
"b": null
}
`,
data: &struct {
A *int `json:"a"`
B *int `json:"b"`
@ -163,15 +255,24 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntNilMultiFields",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *int `json:"a"`
B *int `json:"b"`
})(nil),
},
{
name: "HeadIntZeroNotRoot",
expected: `{"A":{"a":0}}`,
indentExpected: `
{
"A": {
"a": 0
}
}
`,
data: struct {
A struct {
A int `json:"a"`
@ -181,6 +282,13 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadIntNotRoot",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A struct {
A int `json:"a"`
@ -192,6 +300,13 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadIntPtrNotRoot",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A struct {
A *int `json:"a"`
@ -203,6 +318,13 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadIntPtrNilNotRoot",
expected: `{"A":{"a":null}}`,
indentExpected: `
{
"A": {
"a": null
}
}
`,
data: struct {
A struct {
A *int `json:"a"`
@ -212,6 +334,13 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntZeroNotRoot",
expected: `{"A":{"a":0}}`,
indentExpected: `
{
"A": {
"a": 0
}
}
`,
data: struct {
A *struct {
A int `json:"a"`
@ -223,6 +352,13 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntNotRoot",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A *struct {
A int `json:"a"`
@ -234,6 +370,13 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntPtrNotRoot",
expected: `{"A":{"a":1}}`,
indentExpected: `
{
"A": {
"a": 1
}
}
`,
data: struct {
A *struct {
A *int `json:"a"`
@ -245,6 +388,13 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntPtrNilNotRoot",
expected: `{"A":{"a":null}}`,
indentExpected: `
{
"A": {
"a": null
}
}
`,
data: struct {
A *struct {
A *int `json:"a"`
@ -256,6 +406,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntNilNotRoot",
expected: `{"A":null}`,
indentExpected: `
{
"A": null
}
`,
data: struct {
A *struct {
A *int `json:"a"`
@ -265,6 +420,16 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadIntZeroMultiFieldsNotRoot",
expected: `{"A":{"a":0},"B":{"b":0}}`,
indentExpected: `
{
"A": {
"a": 0
},
"B": {
"b": 0
}
}
`,
data: struct {
A struct {
A int `json:"a"`
@ -277,6 +442,16 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadIntMultiFieldsNotRoot",
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: struct {
A struct {
A int `json:"a"`
@ -293,6 +468,16 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadIntPtrMultiFieldsNotRoot",
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: struct {
A struct {
A *int `json:"a"`
@ -309,6 +494,16 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "HeadIntPtrNilMultiFieldsNotRoot",
expected: `{"A":{"a":null},"B":{"b":null}}`,
indentExpected: `
{
"A": {
"a": null
},
"B": {
"b": null
}
}
`,
data: struct {
A struct {
A *int `json:"a"`
@ -325,6 +520,16 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntZeroMultiFieldsNotRoot",
expected: `{"A":{"a":0},"B":{"b":0}}`,
indentExpected: `
{
"A": {
"a": 0
},
"B": {
"b": 0
}
}
`,
data: &struct {
A struct {
A int `json:"a"`
@ -337,6 +542,16 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntMultiFieldsNotRoot",
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: &struct {
A struct {
A int `json:"a"`
@ -353,6 +568,16 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntPtrMultiFieldsNotRoot",
expected: `{"A":{"a":1},"B":{"b":2}}`,
indentExpected: `
{
"A": {
"a": 1
},
"B": {
"b": 2
}
}
`,
data: &struct {
A *struct {
A *int `json:"a"`
@ -369,6 +594,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntPtrNilMultiFieldsNotRoot",
expected: `{"A":null,"B":null}`,
indentExpected: `
{
"A": null,
"B": null
}
`,
data: &struct {
A *struct {
A *int `json:"a"`
@ -381,6 +612,9 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntNilMultiFieldsNotRoot",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *int `json:"a"`
@ -393,6 +627,19 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntDoubleMultiFieldsNotRoot",
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 int `json:"a"`
@ -413,6 +660,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntNilDoubleMultiFieldsNotRoot",
expected: `{"A":null,"B":null}`,
indentExpected: `
{
"A": null,
"B": null
}
`,
data: &struct {
A *struct {
A int `json:"a"`
@ -427,6 +680,9 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntNilDoubleMultiFieldsNotRoot",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A int `json:"a"`
@ -441,6 +697,18 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntPtrDoubleMultiFieldsNotRoot",
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 *int `json:"a"`
@ -461,6 +729,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntPtrNilDoubleMultiFieldsNotRoot",
expected: `{"A":null,"B":null}`,
indentExpected: `
{
"A": null,
"B": null
}
`,
data: &struct {
A *struct {
A *int `json:"a"`
@ -475,6 +749,9 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrHeadIntPtrNilDoubleMultiFieldsNotRoot",
expected: `null`,
indentExpected: `
null
`,
data: (*struct {
A *struct {
A *int `json:"a"`
@ -489,6 +766,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "AnonymousHeadInt",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
structInt
B int `json:"b"`
@ -500,6 +783,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrAnonymousHeadInt",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
*structInt
B int `json:"b"`
@ -511,6 +800,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "NilPtrAnonymousHeadInt",
expected: `{"b":2}`,
indentExpected: `
{
"b": 2
}
`,
data: struct {
*structInt
B int `json:"b"`
@ -522,6 +816,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "AnonymousHeadIntPtr",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
structIntPtr
B *int `json:"b"`
@ -533,6 +833,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "AnonymousHeadIntPtrNil",
expected: `{"a":null,"b":2}`,
indentExpected: `
{
"a": null,
"b": 2
}
`,
data: struct {
structIntPtr
B *int `json:"b"`
@ -544,6 +850,12 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrAnonymousHeadIntPtr",
expected: `{"a":1,"b":2}`,
indentExpected: `
{
"a": 1,
"b": 2
}
`,
data: struct {
*structIntPtr
B *int `json:"b"`
@ -555,6 +867,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "NilPtrAnonymousHeadIntPtr",
expected: `{"b":2}`,
indentExpected: `
{
"b": 2
}
`,
data: struct {
*structIntPtr
B *int `json:"b"`
@ -566,6 +883,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "AnonymousHeadIntOnly",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
structInt
}{
@ -575,6 +897,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrAnonymousHeadIntOnly",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
*structInt
}{
@ -584,6 +911,9 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "NilPtrAnonymousHeadIntOnly",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structInt
}{
@ -593,6 +923,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "AnonymousHeadIntPtrOnly",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
structIntPtr
}{
@ -602,6 +937,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "AnonymousHeadIntPtrNilOnly",
expected: `{"a":null}`,
indentExpected: `
{
"a": null
}
`,
data: struct {
structIntPtr
}{
@ -611,6 +951,11 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "PtrAnonymousHeadIntPtrOnly",
expected: `{"a":1}`,
indentExpected: `
{
"a": 1
}
`,
data: struct {
*structIntPtr
}{
@ -620,6 +965,9 @@ func TestCoverStructHeadInt(t *testing.T) {
{
name: "NilPtrAnonymousHeadIntPtrOnly",
expected: `{}`,
indentExpected: `
{}
`,
data: struct {
*structIntPtr
}{
@ -628,15 +976,27 @@ func TestCoverStructHeadInt(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 && test.indentExpected != "" {
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 != "" {
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())
}
}
}
}
}

View File

@ -5292,10 +5292,13 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
code = code.next
}
case opStructFieldPtrHeadIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
fallthrough
case opStructFieldHeadIndent:
ptr := load(ctxptr, code.idx)
@ -5312,17 +5315,34 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
store(ctxptr, code.idx, ptr)
} else {
b = append(b, '{', '\n')
if !code.anonymousKey {
b = e.encodeIndent(b, code.indent+1)
b = append(b, code.key...)
b = append(b, ' ')
}
p := ptr + code.offset
code = code.next
store(ctxptr, code.idx, p)
}
case opStructFieldHeadOnlyIndent:
ptr := load(ctxptr, code.idx)
b = append(b, '{', '\n')
if !code.anonymousKey {
b = e.encodeIndent(b, code.indent+1)
b = append(b, code.key...)
b = append(b, ' ')
code = code.next
store(ctxptr, code.idx, ptr)
}
p := ptr + code.offset
code = code.next
store(ctxptr, code.idx, p)
case opStructEscapedFieldPtrHeadIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
fallthrough
case opStructEscapedFieldHeadIndent:
ptr := load(ctxptr, code.idx)
@ -5339,25 +5359,34 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
store(ctxptr, code.idx, ptr)
} else {
b = append(b, '{', '\n')
if !code.anonymousKey {
b = e.encodeIndent(b, code.indent+1)
b = append(b, code.escapedKey...)
b = append(b, ' ')
}
p := ptr + code.offset
code = code.next
store(ctxptr, code.idx, p)
}
case opStructEscapedFieldHeadOnlyIndent:
ptr := load(ctxptr, code.idx)
b = append(b, '{', '\n')
if !code.anonymousKey {
b = e.encodeIndent(b, code.indent+1)
b = append(b, code.escapedKey...)
b = append(b, ' ')
code = code.next
store(ctxptr, code.idx, ptr)
}
p := ptr + code.offset
code = code.next
store(ctxptr, code.idx, p)
case opStructFieldPtrHeadIntIndent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
case opStructFieldHeadIntIndent:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
if code.op == opStructFieldPtrHeadIntIndent {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
} else {
b = append(b, '{', '}', ',', '\n')
}
b = encodeNull(b)
b = encodeIndentComma(b)
code = code.end.next
} else {
b = append(b, '{', '\n')
@ -5368,19 +5397,23 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
b = encodeIndentComma(b)
code = code.next
}
case opStructFieldPtrHeadIntOnlyIndent, opStructFieldHeadIntOnlyIndent:
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.ptrToInt(p)))
b = encodeIndentComma(b)
code = code.next
case opStructEscapedFieldPtrHeadIntIndent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
case opStructEscapedFieldHeadIntIndent:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
if code.op == opStructEscapedFieldPtrHeadIntIndent {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
} else {
b = append(b, '{', '}', ',', '\n')
}
b = encodeNull(b)
b = encodeIndentComma(b)
code = code.end.next
} else {
b = append(b, '{', '\n')
@ -5391,6 +5424,289 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
b = encodeIndentComma(b)
code = code.next
}
case opStructEscapedFieldPtrHeadIntOnlyIndent, opStructEscapedFieldHeadIntOnlyIndent:
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.ptrToInt(p)))
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadIntPtrIndent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
case opStructFieldHeadIntPtrIndent:
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.ptrToInt(p+code.offset)))
}
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadIntPtrOnlyIndent:
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 opStructFieldHeadIntPtrOnlyIndent:
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.ptrToInt(p+code.offset)))
}
b = encodeIndentComma(b)
code = code.next
case opStructEscapedFieldPtrHeadIntPtrIndent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
case opStructEscapedFieldHeadIntPtrIndent:
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.ptrToInt(p+code.offset)))
}
}
b = encodeIndentComma(b)
code = code.next
case opStructEscapedFieldPtrHeadIntPtrOnlyIndent:
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 opStructEscapedFieldHeadIntPtrOnlyIndent:
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.ptrToInt(p+code.offset)))
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldHeadIntNPtrIndent:
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.ptrToInt(p+code.offset)))
}
}
b = encodeIndentComma(b)
code = code.next
case opStructEscapedFieldHeadIntNPtrIndent:
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.ptrToInt(p+code.offset)))
}
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrAnonymousHeadIntIndent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
case opStructFieldAnonymousHeadIntIndent:
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.ptrToInt(ptr+code.offset)))
b = encodeIndentComma(b)
code = code.next
}
case opStructEscapedFieldPtrAnonymousHeadIntIndent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
case opStructEscapedFieldAnonymousHeadIntIndent:
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.ptrToInt(ptr+code.offset)))
b = encodeIndentComma(b)
code = code.next
}
case opStructFieldPtrAnonymousHeadIntOnlyIndent, opStructFieldAnonymousHeadIntOnlyIndent:
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.ptrToInt(ptr+code.offset)))
b = encodeIndentComma(b)
code = code.next
}
case opStructEscapedFieldPtrAnonymousHeadIntOnlyIndent, opStructEscapedFieldAnonymousHeadIntOnlyIndent:
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.ptrToInt(ptr+code.offset)))
b = encodeIndentComma(b)
code = code.next
}
case opStructFieldPtrAnonymousHeadIntPtrIndent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
case opStructFieldAnonymousHeadIntPtrIndent:
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.ptrToInt(p+code.offset)))
}
b = encodeIndentComma(b)
code = code.next
case opStructEscapedFieldPtrAnonymousHeadIntPtrIndent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
case opStructEscapedFieldAnonymousHeadIntPtrIndent:
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.ptrToInt(p+code.offset)))
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrAnonymousHeadIntPtrOnlyIndent:
p := load(ctxptr, code.idx)
if p == 0 {
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
fallthrough
case opStructFieldAnonymousHeadIntPtrOnlyIndent:
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.ptrToInt(p+code.offset)))
}
b = encodeIndentComma(b)
code = code.next
case opStructEscapedFieldPtrAnonymousHeadIntPtrOnlyIndent:
p := load(ctxptr, code.idx)
if p == 0 {
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
fallthrough
case opStructEscapedFieldAnonymousHeadIntPtrOnlyIndent:
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.ptrToInt(p+code.offset)))
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadInt8Indent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
@ -13709,6 +14025,12 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
code = code.next
case opStructEndIndent, opStructEscapedEndIndent:
last := len(b) - 1
if b[last-1] == '{' {
b[last] = '}'
b = encodeIndentComma(b)
code = code.next
break
}
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
@ -14332,6 +14654,32 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
b = e.appendStructEndIndent(b, code.indent-1)
code = code.next
case opStructEndIntPtrIndent:
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.ptrToInt(p)))
}
b = e.appendStructEndIndent(b, code.indent-1)
code = code.next
case opStructEscapedEndIntPtrIndent:
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.ptrToInt(p)))
}
b = e.appendStructEndIndent(b, code.indent-1)
code = code.next
case opStructEndInt8Indent:
b = e.encodeIndent(b, code.indent)
b = append(b, code.key...)