Skip to content

Commit

Permalink
add simple fuzz test
Browse files Browse the repository at this point in the history
This is about as minimal as it gets, but it was enough to catch #54.

It's a bit weird to have a file called fuzz_test.go
and another called fuzzy_test.go.
I guess that's life in a fuzzy matching project.
  • Loading branch information
josharian committed May 4, 2023
1 parent 24e57ae commit 675978e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions fuzzy/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package fuzzy

import (
"sort"
"testing"
)

func FuzzFind(f *testing.F) {
f.Fuzz(func(t *testing.T, n string, h []byte) {
s := make([]string, len(h))
for i, b := range h {
s[i] = string(b)
}
Find(n, s)
FindFold(n, s)
FindNormalized(n, s)
FindNormalizedFold(n, s)
r := RankFind(n, s)
sort.Sort(r)
// No need to sort the other Rank calls;
// assume first sort can catch any bugs.
RankFindFold(n, s)
RankFindNormalized(n, s)
RankFindNormalizedFold(n, s)
if len(s) > 0 {
x := s[0]
LevenshteinDistance(n, x)
Match(n, x)
MatchFold(n, x)
MatchNormalized(n, x)
MatchNormalizedFold(n, x)
}
})
}

0 comments on commit 675978e

Please sign in to comment.