Skip to content

Commit 840be7b

Browse files
committed
test: added fuzz test for parsing
Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
1 parent b834f57 commit 840be7b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

fuzz_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package jsonpointer
2+
3+
import (
4+
"iter"
5+
"slices"
6+
"strings"
7+
"testing"
8+
9+
"github.com/go-openapi/testify/v2/require"
10+
)
11+
12+
func FuzzParse(f *testing.F) {
13+
cumulated := make([]string, 0, 100)
14+
for generator := range generators() {
15+
f.Add(generator)
16+
17+
cumulated = append(cumulated, generator)
18+
f.Add(strings.Join(cumulated, ""))
19+
}
20+
21+
f.Fuzz(func(t *testing.T, input string) {
22+
require.NotPanics(t, func() {
23+
_, _ = New(input)
24+
})
25+
})
26+
}
27+
28+
func generators() iter.Seq[string] {
29+
return slices.Values([]string{
30+
`a`,
31+
``, `/`, `/`, `/a~1b`, `/a~1b`, `/c%d`, `/e^f`, `/g|h`, `/i\j`, `/k"l`, `/ `, `/m~0n`,
32+
`/foo`, `/0`,
33+
})
34+
}

0 commit comments

Comments
 (0)