Fix unnecessary indent

This commit is contained in:
Masaaki Goshima 2021-04-10 15:25:02 +09:00
parent a39bc30ed9
commit ae56d8371d
3 changed files with 42 additions and 4 deletions

View File

@ -1805,3 +1805,45 @@ func TestIssue104(t *testing.T) {
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))
}
}

View File

@ -338,7 +338,6 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
code = code.Next
store(ctxptr, code.Idx, uintptr(slice.Data))
} else {
b = appendIndent(ctx, b, code.Indent)
b = append(b, '[', ']', ',', '\n')
code = code.End.Next
}
@ -385,7 +384,6 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
code = code.Next
store(ctxptr, code.Idx, p)
} else {
b = appendIndent(ctx, b, code.Indent)
b = append(b, '[', ']', ',', '\n')
code = code.End.Next
}

View File

@ -338,7 +338,6 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
code = code.Next
store(ctxptr, code.Idx, uintptr(slice.Data))
} else {
b = appendIndent(ctx, b, code.Indent)
b = append(b, '[', ']', ',', '\n')
code = code.End.Next
}
@ -385,7 +384,6 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
code = code.Next
store(ctxptr, code.Idx, p)
} else {
b = appendIndent(ctx, b, code.Indent)
b = append(b, '[', ']', ',', '\n')
code = code.End.Next
}