Debian Codegraph @

pkg/internal/third_party/go-json-experiment/json/fuzz_test.go

raw
1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package json
6
7 import (
8 "bytes"
9 "testing"
10 )
11
12 func FuzzEqualFold(f *testing.F) {
13 for _, tt := range equalFoldTestdata {
14 f.Add([]byte(tt.in1), []byte(tt.in2))
15 }
16
17 equalFoldSimple := func(x, y []byte) bool {
18 strip := func(b []byte) []byte {
19 return bytes.Map(func(r rune) rune {
20 if r == '_' || r == '-' {
21 return -1 // ignore underscores and dashes
22 }
23 return r
24 }, b)
25 }
26 return bytes.EqualFold(strip(x), strip(y))
27 }
28
29 f.Fuzz(func(t *testing.T, s1, s2 []byte) {
30 // Compare the optimized and simplified implementations.
31 got := equalFold(s1, s2)
32 want := equalFoldSimple(s1, s2)
33 if got != want {
34 t.Errorf("equalFold(%q, %q) = %v, want %v", s1, s2, got, want)
35 }
36 })
37 }