Skip to content

Commit

Permalink
Add all primitive parsing functions to the fuzz matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
FollowTheProcess committed Feb 2, 2024
1 parent 514add6 commit 3a8e453
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ jobs:
- FuzzTakeUntil
- FuzzTakeWhileBetween
- FuzzTakeTo
- FuzzOneOf
- FuzzNoneOf
- FuzzAnyOf
- FuzzNotAnyOf
- FuzzOptional

steps:
- name: Checkout Code
Expand Down
55 changes: 55 additions & 0 deletions fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,61 @@ func FuzzTakeTo(f *testing.F) {
})
}

func FuzzOneOf(f *testing.F) {
for _, item := range corpus {
f.Add(item, randomString(rand.Intn(10)))
}

f.Fuzz(func(t *testing.T, input string, chars string) {
value, remainder, err := parser.OneOf(chars)(input)
fuzzParser(t, value, remainder, err)
})
}

func FuzzNoneOf(f *testing.F) {
for _, item := range corpus {
f.Add(item, randomString(rand.Intn(10)))
}

f.Fuzz(func(t *testing.T, input string, chars string) {
value, remainder, err := parser.NoneOf(chars)(input)
fuzzParser(t, value, remainder, err)
})
}

func FuzzAnyOf(f *testing.F) {
for _, item := range corpus {
f.Add(item, randomString(rand.Intn(10)))
}

f.Fuzz(func(t *testing.T, input string, chars string) {
value, remainder, err := parser.AnyOf(chars)(input)
fuzzParser(t, value, remainder, err)
})
}

func FuzzNotAnyOf(f *testing.F) {
for _, item := range corpus {
f.Add(item, randomString(rand.Intn(10)))
}

f.Fuzz(func(t *testing.T, input string, chars string) {
value, remainder, err := parser.NotAnyOf(chars)(input)
fuzzParser(t, value, remainder, err)
})
}

func FuzzOptional(f *testing.F) {
for _, item := range corpus {
f.Add(item, randomString(5))
}

f.Fuzz(func(t *testing.T, input string, match string) {
value, remainder, err := parser.Optional(match)(input)
fuzzParser(t, value, remainder, err)
})
}

// fuzzParser is a helper that asserts empty value and remainders were returned if the
// err was not nil.
func fuzzParser[T any](t *testing.T, value T, remainder string, err error) {
Expand Down

0 comments on commit 3a8e453

Please sign in to comment.