fuzzing test on parse

This commit is contained in:
Josh Baker 2016-10-18 17:13:15 -07:00
parent 800ce5e927
commit 27c108f475
2 changed files with 28 additions and 1 deletions

View File

@ -27,6 +27,26 @@ const (
JSON JSON
) )
// String returns a string representation of the type.
func (t Type) String() string {
switch t {
default:
return ""
case Null:
return "Null"
case False:
return "False"
case Number:
return "Number"
case String:
return "String"
case True:
return "True"
case JSON:
return "JSON"
}
}
// Result represents a json value that is returned from Get(). // Result represents a json value that is returned from Get().
type Result struct { type Result struct {
// Type is the json type // Type is the json type
@ -389,7 +409,13 @@ func tostr(json string) (raw string, str string) {
break break
} }
} }
return json[:i+1], unescape(json[1:i]) var ret string
if i+1 < len(json) {
ret = json[:i+1]
} else {
ret = json[:i]
}
return ret, unescape(json[1:i])
} }
} }
return json, json[1:] return json, json[1:]

View File

@ -36,6 +36,7 @@ func TestRandomData(t *testing.T) {
} }
lstr = string(b[:n]) lstr = string(b[:n])
GetBytes([]byte(lstr), "zzzz") GetBytes([]byte(lstr), "zzzz")
Parse(lstr)
} }
} }