1
2
3
4
5
6
7 package json
8
9 import (
10 "bytes"
11 "testing"
12 )
13
14 func FuzzEqualFold(f *testing.F) {
15 for _, tt := range equalFoldTestdata {
16 f.Add([]byte(tt.in1), []byte(tt.in2))
17 }
18
19 equalFoldSimple := func(x, y []byte) bool {
20 strip := func(b []byte) []byte {
21 return bytes.Map(func(r rune) rune {
22 if r == '_' || r == '-' {
23 return -1
24 }
25 return r
26 }, b)
27 }
28 return bytes.EqualFold(strip(x), strip(y))
29 }
30
31 f.Fuzz(func(t *testing.T, s1, s2 []byte) {
32
33 got := equalFold(s1, s2)
34 want := equalFoldSimple(s1, s2)
35 if got != want {
36 t.Errorf("equalFold(%q, %q) = %v, want %v", s1, s2, got, want)
37 }
38 })
39 }
40
View as plain text