mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
This imports the proposed new v2 JSON API implemented in github.com/go-json-experiment/json as of commit d3c622f1b874954c355e60c8e6b6baa5f60d2fed. When GOEXPERIMENT=jsonv2 is set, the encoding/json/v2 and encoding/jsontext packages are visible, the encoding/json package is implemented in terms of encoding/json/v2, and the encoding/json package include various additional APIs. (See #71497 for details.) When GOEXPERIMENT=jsonv2 is not set, the new API is not present and the encoding/json package is unchanged. The experimental API is not bound by the Go compatibility promise and is expected to evolve as updates are made to the json/v2 proposal. The contents of encoding/json/internal/jsontest/testdata are compressed with zstd v1.5.7 with the -19 option. Fixes #71845 For #71497 Change-Id: Ib8c94e5f0586b6aaa22833190b41cf6ef59f4f01 Reviewed-on: https://go-review.googlesource.com/c/go/+/665796 Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
40 lines
895 B
Go
40 lines
895 B
Go
// Copyright 2020 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
//go:build goexperiment.jsonv2
|
|
|
|
package json
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func FuzzEqualFold(f *testing.F) {
|
|
for _, tt := range equalFoldTestdata {
|
|
f.Add([]byte(tt.in1), []byte(tt.in2))
|
|
}
|
|
|
|
equalFoldSimple := func(x, y []byte) bool {
|
|
strip := func(b []byte) []byte {
|
|
return bytes.Map(func(r rune) rune {
|
|
if r == '_' || r == '-' {
|
|
return -1 // ignore underscores and dashes
|
|
}
|
|
return r
|
|
}, b)
|
|
}
|
|
return bytes.EqualFold(strip(x), strip(y))
|
|
}
|
|
|
|
f.Fuzz(func(t *testing.T, s1, s2 []byte) {
|
|
// Compare the optimized and simplified implementations.
|
|
got := equalFold(s1, s2)
|
|
want := equalFoldSimple(s1, s2)
|
|
if got != want {
|
|
t.Errorf("equalFold(%q, %q) = %v, want %v", s1, s2, got, want)
|
|
}
|
|
})
|
|
}
|