forked from mirror/go-json
Merge pull request #181 from goccy/feature/fix-180
Fix unnecessary indent for empty slice/array
This commit is contained in:
commit
ca141f38b6
|
@ -1805,3 +1805,45 @@ func TestIssue104(t *testing.T) {
|
||||||
t.Fatalf("expect %q but got %q", string(expect), string(got))
|
t.Fatalf("expect %q but got %q", string(expect), string(got))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssue180(t *testing.T) {
|
||||||
|
v := struct {
|
||||||
|
T struct {
|
||||||
|
T1 bool `json:"t1"`
|
||||||
|
T2 float64 `json:"t2"`
|
||||||
|
T3 string `json:"t3"`
|
||||||
|
T4 []string `json:"t4"`
|
||||||
|
T5 *struct{} `json:"t5"`
|
||||||
|
T6 interface{} `json:"t6"`
|
||||||
|
T7 [][]string `json:"t7"`
|
||||||
|
} `json:"t"`
|
||||||
|
}{
|
||||||
|
T: struct {
|
||||||
|
T1 bool `json:"t1"`
|
||||||
|
T2 float64 `json:"t2"`
|
||||||
|
T3 string `json:"t3"`
|
||||||
|
T4 []string `json:"t4"`
|
||||||
|
T5 *struct{} `json:"t5"`
|
||||||
|
T6 interface{} `json:"t6"`
|
||||||
|
T7 [][]string `json:"t7"`
|
||||||
|
}{
|
||||||
|
T4: []string{},
|
||||||
|
T7: [][]string{
|
||||||
|
[]string{""},
|
||||||
|
[]string{"hello", "world"},
|
||||||
|
[]string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
b1, err := stdjson.MarshalIndent(v, "", "\t")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
b2, err := json.MarshalIndent(v, "", "\t")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !bytes.Equal(b1, b2) {
|
||||||
|
t.Fatalf("failed to equal encoded result: expected %s but got %s", string(b1), string(b2))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -338,7 +338,6 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
||||||
code = code.Next
|
code = code.Next
|
||||||
store(ctxptr, code.Idx, uintptr(slice.Data))
|
store(ctxptr, code.Idx, uintptr(slice.Data))
|
||||||
} else {
|
} else {
|
||||||
b = appendIndent(ctx, b, code.Indent)
|
|
||||||
b = append(b, '[', ']', ',', '\n')
|
b = append(b, '[', ']', ',', '\n')
|
||||||
code = code.End.Next
|
code = code.End.Next
|
||||||
}
|
}
|
||||||
|
@ -385,7 +384,6 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
||||||
code = code.Next
|
code = code.Next
|
||||||
store(ctxptr, code.Idx, p)
|
store(ctxptr, code.Idx, p)
|
||||||
} else {
|
} else {
|
||||||
b = appendIndent(ctx, b, code.Indent)
|
|
||||||
b = append(b, '[', ']', ',', '\n')
|
b = append(b, '[', ']', ',', '\n')
|
||||||
code = code.End.Next
|
code = code.End.Next
|
||||||
}
|
}
|
||||||
|
|
|
@ -338,7 +338,6 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
||||||
code = code.Next
|
code = code.Next
|
||||||
store(ctxptr, code.Idx, uintptr(slice.Data))
|
store(ctxptr, code.Idx, uintptr(slice.Data))
|
||||||
} else {
|
} else {
|
||||||
b = appendIndent(ctx, b, code.Indent)
|
|
||||||
b = append(b, '[', ']', ',', '\n')
|
b = append(b, '[', ']', ',', '\n')
|
||||||
code = code.End.Next
|
code = code.End.Next
|
||||||
}
|
}
|
||||||
|
@ -385,7 +384,6 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
||||||
code = code.Next
|
code = code.Next
|
||||||
store(ctxptr, code.Idx, p)
|
store(ctxptr, code.Idx, p)
|
||||||
} else {
|
} else {
|
||||||
b = appendIndent(ctx, b, code.Indent)
|
|
||||||
b = append(b, '[', ']', ',', '\n')
|
b = append(b, '[', ']', ',', '\n')
|
||||||
code = code.End.Next
|
code = code.End.Next
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue