Add fuzz.sh to do fuzzing with go-fuzz (#194)

Fixes #181
This commit is contained in:
Kazuyoshi Kato
2017-10-21 16:37:53 -07:00
committed by Thomas Pelletier
parent a410399d2c
commit 1916042ba2
3 changed files with 47 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
// +build gofuzz
package toml
func Fuzz(data []byte) int {
tree, err := LoadBytes(data)
if err != nil {
if tree != nil {
panic("tree must be nil if there is an error")
}
return 0
}
str, err := tree.ToTomlString()
if err != nil {
if str != "" {
panic(`str must be "" if there is an error`)
}
panic(err)
}
tree, err = LoadString(str)
if err != nil {
if tree != nil {
panic("tree must be nil if there is an error")
}
return 0
}
return 1
}