mirror of https://github.com/golang/go.git
json: calculate Offset for Indent correctly
Fixes #2171 This is the real change. R=adg CC=golang-dev, r, rsc https://golang.org/cl/4943041
This commit is contained in:
parent
aca4293715
commit
07490c0f05
|
|
@ -59,6 +59,7 @@ func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) os.Error {
|
|||
needIndent := false
|
||||
depth := 0
|
||||
for _, c := range src {
|
||||
scan.bytes++
|
||||
v := scan.step(&scan, int(c))
|
||||
if v == scanSkipSpace {
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ package json
|
|||
import (
|
||||
"bytes"
|
||||
"math"
|
||||
"os"
|
||||
"rand"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
@ -136,6 +138,29 @@ func TestIndentBig(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
type indentErrorTest struct {
|
||||
in string
|
||||
err os.Error
|
||||
}
|
||||
|
||||
var indentErrorTests = []indentErrorTest{
|
||||
{`{"X": "foo", "Y"}`, &SyntaxError{"invalid character '}' after object key", 17}},
|
||||
{`{"X": "foo" "Y": "bar"}`, &SyntaxError{"invalid character '\"' after object key:value pair", 13}},
|
||||
}
|
||||
|
||||
func TestIdentErrors(t *testing.T) {
|
||||
for i, tt := range indentErrorTests {
|
||||
slice := make([]uint8, 0)
|
||||
buf := bytes.NewBuffer(slice)
|
||||
if err := Indent(buf, []uint8(tt.in), "", ""); err != nil {
|
||||
if !reflect.DeepEqual(err, tt.err) {
|
||||
t.Errorf("#%d: Indent: %#v", i, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextValueBig(t *testing.T) {
|
||||
initBig()
|
||||
var scan scanner
|
||||
|
|
|
|||
Loading…
Reference in New Issue