From 675978ecdefe0bb4b8c84ca343382e0f6e0ab763 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 4 May 2023 15:36:58 -0700 Subject: [PATCH] add simple fuzz test 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. --- fuzzy/fuzz_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 fuzzy/fuzz_test.go diff --git a/fuzzy/fuzz_test.go b/fuzzy/fuzz_test.go new file mode 100644 index 0000000..d606fc5 --- /dev/null +++ b/fuzzy/fuzz_test.go @@ -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) + } + }) +}