mirror of https://github.com/goccy/go-json.git
Fix MarshalIndent for interface type
This commit is contained in:
parent
e17c06a7e8
commit
acc66cf172
|
@ -2278,3 +2278,25 @@ func TestRecursivePtrHead(t *testing.T) {
|
|||
t.Fatalf("failed to encode. expected %q but got %q", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalIndent(t *testing.T) {
|
||||
v := map[string]map[string]interface{}{
|
||||
"a": {
|
||||
"b": "1",
|
||||
"c": map[string]interface{}{
|
||||
"d": "1",
|
||||
},
|
||||
},
|
||||
}
|
||||
expected, err := stdjson.MarshalIndent(v, "", " ")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := json.MarshalIndent(v, "", " ")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(expected, got) {
|
||||
t.Fatalf("expected: %q but got %q", expected, got)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -218,8 +218,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
oldOffset := ptrOffset
|
||||
ptrOffset += totalLength * uintptrSize
|
||||
oldBaseIndent := ctx.BaseIndent
|
||||
indentDiffFromTop := c.Indent - 1
|
||||
ctx.BaseIndent += code.Indent - indentDiffFromTop
|
||||
ctx.BaseIndent += code.Indent
|
||||
|
||||
newLen := offsetNum + totalLength + nextTotalLength
|
||||
if curlen < newLen {
|
||||
|
|
|
@ -218,8 +218,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
oldOffset := ptrOffset
|
||||
ptrOffset += totalLength * uintptrSize
|
||||
oldBaseIndent := ctx.BaseIndent
|
||||
indentDiffFromTop := c.Indent - 1
|
||||
ctx.BaseIndent += code.Indent - indentDiffFromTop
|
||||
ctx.BaseIndent += code.Indent
|
||||
|
||||
newLen := offsetNum + totalLength + nextTotalLength
|
||||
if curlen < newLen {
|
||||
|
|
|
@ -218,8 +218,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
oldOffset := ptrOffset
|
||||
ptrOffset += totalLength * uintptrSize
|
||||
oldBaseIndent := ctx.BaseIndent
|
||||
indentDiffFromTop := c.Indent - 1
|
||||
ctx.BaseIndent += code.Indent - indentDiffFromTop
|
||||
ctx.BaseIndent += code.Indent
|
||||
|
||||
newLen := offsetNum + totalLength + nextTotalLength
|
||||
if curlen < newLen {
|
||||
|
|
|
@ -218,8 +218,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
oldOffset := ptrOffset
|
||||
ptrOffset += totalLength * uintptrSize
|
||||
oldBaseIndent := ctx.BaseIndent
|
||||
indentDiffFromTop := c.Indent - 1
|
||||
ctx.BaseIndent += code.Indent - indentDiffFromTop
|
||||
ctx.BaseIndent += code.Indent
|
||||
|
||||
newLen := offsetNum + totalLength + nextTotalLength
|
||||
if curlen < newLen {
|
||||
|
|
|
@ -218,8 +218,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
oldOffset := ptrOffset
|
||||
ptrOffset += totalLength * uintptrSize
|
||||
oldBaseIndent := ctx.BaseIndent
|
||||
indentDiffFromTop := c.Indent - 1
|
||||
ctx.BaseIndent += code.Indent - indentDiffFromTop
|
||||
ctx.BaseIndent += code.Indent
|
||||
|
||||
newLen := offsetNum + totalLength + nextTotalLength
|
||||
if curlen < newLen {
|
||||
|
|
Loading…
Reference in New Issue