aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2022-06-15 17:25:12 -0700
committerGopher Robot <gobot@golang.org>2022-08-22 23:36:38 +0000
commit0f42e35feeef606977859039b876773ae5fb4de9 (patch)
tree7455d6be4cf228aa332473ae87062b05a6354e31 /src
parente0388c92d048fc31b39e133441bd4f6d85959ec4 (diff)
downloadgo-0f42e35feeef606977859039b876773ae5fb4de9.tar.xz
encoding/json: rely on utf8.AppendRune
Change-Id: I50e5609ff9c5f2b216b93cec7fb5214d196cae90 Reviewed-on: https://go-review.googlesource.com/c/go/+/412537 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/encoding/json/fold_test.go12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/encoding/json/fold_test.go b/src/encoding/json/fold_test.go
index 9fb94646a8..4daa3590f5 100644
--- a/src/encoding/json/fold_test.go
+++ b/src/encoding/json/fold_test.go
@@ -52,9 +52,7 @@ func TestFold(t *testing.T) {
}
func TestFoldAgainstUnicode(t *testing.T) {
- const bufSize = 5
- buf1 := make([]byte, 0, bufSize)
- buf2 := make([]byte, 0, bufSize)
+ var buf1, buf2 []byte
var runes []rune
for i := 0x20; i <= 0x7f; i++ {
runes = append(runes, rune(i))
@@ -96,12 +94,8 @@ func TestFoldAgainstUnicode(t *testing.T) {
continue
}
for _, r2 := range runes {
- buf1 := append(buf1[:0], 'x')
- buf2 := append(buf2[:0], 'x')
- buf1 = buf1[:1+utf8.EncodeRune(buf1[1:bufSize], r)]
- buf2 = buf2[:1+utf8.EncodeRune(buf2[1:bufSize], r2)]
- buf1 = append(buf1, 'x')
- buf2 = append(buf2, 'x')
+ buf1 = append(utf8.AppendRune(append(buf1[:0], 'x'), r), 'x')
+ buf2 = append(utf8.AppendRune(append(buf2[:0], 'x'), r2), 'x')
want := bytes.EqualFold(buf1, buf2)
if got := ff.fold(buf1, buf2); got != want {
t.Errorf("%s(%q, %q) = %v; want %v", ff.name, buf1, buf2, got, want)