mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
ba333a3061
commit
098b62644f
2 changed files with 51 additions and 1 deletions
|
|
@ -57,6 +57,36 @@ func TestEncoder(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
var streamEncodedIndent = `0.1
|
||||
"hello"
|
||||
null
|
||||
true
|
||||
false
|
||||
[
|
||||
>."a",
|
||||
>."b",
|
||||
>."c"
|
||||
>]
|
||||
{
|
||||
>."ß": "long s",
|
||||
>."K": "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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue