Skip to content

Commit

Permalink
Add fuzz target for FromString
Browse files Browse the repository at this point in the history
  • Loading branch information
jwkohnen committed Apr 28, 2021
1 parent 1563baf commit ad98b2f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
30 changes: 30 additions & 0 deletions airac_fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//+build go.dev.fuzz

package airac

import (
"strconv"
"strings"
"testing"
)

//goland:noinspection GoUnusedExportedFunction
func FuzzFromString(f *testing.F) {
for i := -999; i <= 9999; i++ {
f.Add(strconv.Itoa(i))
}

f.Fuzz(func(t *testing.T, s string) {
t.Parallel()

a, err := FromString(s)
if err != nil {
t.SkipNow()
}

s2 := a.String()
if strings.TrimSpace(s) != s2 {
t.Errorf("%q != %q", s, s2)
}
})
}
4 changes: 4 additions & 0 deletions airac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ func TestFromString(t *testing.T) {

// found by fuzzer (case testdata/corpus/FuzzFromString/44ea5456f4caf7ee4b0cb896e30cb4f52cd0e65cd3c1843393c5a535f97c7a6e)
{"+911", "", 0, 0, false},


// found by fuzzer (case testdata/corpus/FuzzFromString/cde16d0f1e64e24bd633e50af05f0e1c4b74934119ed36156d64e32768cbcc4e)
{" 7807", "1978-07-13", 1978, 07, true},
}

for i, tt := range testt {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/jwkohnen/airac

go 1.12
go 1.16
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("+911")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string(" 7807")

0 comments on commit ad98b2f

Please sign in to comment.