vendor/github.com/pelletier/go-toml/fuzz.go
changeset 265 05c40b36d3b2
parent 264 8f478162d991
child 266 80973a656b81
equal deleted inserted replaced
264:8f478162d991 265:05c40b36d3b2
     1 // +build gofuzz
       
     2 
       
     3 package toml
       
     4 
       
     5 func Fuzz(data []byte) int {
       
     6 	tree, err := LoadBytes(data)
       
     7 	if err != nil {
       
     8 		if tree != nil {
       
     9 			panic("tree must be nil if there is an error")
       
    10 		}
       
    11 		return 0
       
    12 	}
       
    13 
       
    14 	str, err := tree.ToTomlString()
       
    15 	if err != nil {
       
    16 		if str != "" {
       
    17 			panic(`str must be "" if there is an error`)
       
    18 		}
       
    19 		panic(err)
       
    20 	}
       
    21 
       
    22 	tree, err = Load(str)
       
    23 	if err != nil {
       
    24 		if tree != nil {
       
    25 			panic("tree must be nil if there is an error")
       
    26 		}
       
    27 		return 0
       
    28 	}
       
    29 
       
    30 	return 1
       
    31 }