mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json: more tests to cover decoding edge cases
The overall coverage of the json package goes up from 90.8% to 91.3%. While at it, apply two minor code simplifications found while inspecting the HTML coverage report. Change-Id: I0fba968afeedc813b1385e4bde72d93b878854d7 Reviewed-on: https://go-review.googlesource.com/134735 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
023dbb188d
commit
dc3680865a
3 changed files with 29 additions and 14 deletions
|
|
@ -533,8 +533,7 @@ func (d *decodeState) array(v reflect.Value) error {
|
|||
d.saveError(&UnmarshalTypeError{Value: "array", Type: v.Type(), Offset: int64(d.off)})
|
||||
d.skip()
|
||||
return nil
|
||||
case reflect.Array:
|
||||
case reflect.Slice:
|
||||
case reflect.Array, reflect.Slice:
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -871,18 +870,16 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
|
|||
if item[0] != '"' {
|
||||
if fromQuoted {
|
||||
d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type()))
|
||||
} else {
|
||||
var val string
|
||||
switch item[0] {
|
||||
case 'n':
|
||||
val = "null"
|
||||
case 't', 'f':
|
||||
val = "bool"
|
||||
default:
|
||||
val = "number"
|
||||
}
|
||||
d.saveError(&UnmarshalTypeError{Value: val, Type: v.Type(), Offset: int64(d.readIndex())})
|
||||
return nil
|
||||
}
|
||||
val := "number"
|
||||
switch item[0] {
|
||||
case 'n':
|
||||
val = "null"
|
||||
case 't', 'f':
|
||||
val = "bool"
|
||||
}
|
||||
d.saveError(&UnmarshalTypeError{Value: val, Type: v.Type(), Offset: int64(d.readIndex())})
|
||||
return nil
|
||||
}
|
||||
s, ok := unquoteBytes(item)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue