encoding/json: add (*Encoder).Indent

Fixes #6492.

Change-Id: Ibc633c43a6d134bb140addb59780a5758b35a5c5
Reviewed-on: https://go-review.googlesource.com/21057
Run-TryBot: Caleb Spare <cespare@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Caleb Spare 2016-03-23 23:14:35 -07:00 committed by Brad Fitzpatrick
parent ba333a3061
commit 098b62644f
2 changed files with 51 additions and 1 deletions

View file

@ -57,6 +57,36 @@ func TestEncoder(t *testing.T) {
}
}
var streamEncodedIndent = `0.1
"hello"
null
true
false
[
>."a",
>."b",
>."c"
>]
{
>."ß": "long s",
>."": "Kelvin"
>}
3.14
`
func TestEncoderIndent(t *testing.T) {
var buf bytes.Buffer
enc := NewEncoder(&buf)
enc.Indent(">", ".")
for _, v := range streamTest {
enc.Encode(v)
}
if have, want := buf.String(), streamEncodedIndent; have != want {
t.Error("indented encoding mismatch")
diff(t, []byte(have), []byte(want))
}
}
func TestDecoder(t *testing.T) {
for i := 0; i <= len(streamTest); i++ {
// Use stream without newlines as input,