Merge pull request #317 from goccy/feature/fix-indent

Fix MarshalIndent for interface type
This commit is contained in:
Masaaki Goshima 2022-01-05 20:45:00 +09:00 committed by GitHub
commit 923cda5039
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 10 deletions

View File

@ -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)
}
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {