Source file src/encoding/json/v2/fuzz_test.go

     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  //go:build goexperiment.jsonv2
     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 // ignore underscores and dashes
    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  		// Compare the optimized and simplified implementations.
    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