From: jiahua wang Date: Thu, 7 Oct 2021 07:30:03 +0000 (+0800) Subject: unicode/utf8: add AppendRune Example X-Git-Tag: go1.18beta1~487 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=75952abc6a8a8ad09e6bb1966c66b9a68b5d6c4e;p=gostls13.git unicode/utf8: add AppendRune Example Also, correct TestAppendRune error message. Change-Id: I3ca3ac7051af1ae6d449381b78efa86c2f6be8ac Reviewed-on: https://go-review.googlesource.com/c/go/+/354529 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Trust: Robert Findley Trust: Cherry Mui TryBot-Result: Go Bot --- diff --git a/src/unicode/utf8/example_test.go b/src/unicode/utf8/example_test.go index 5cd931d242..fe434c9476 100644 --- a/src/unicode/utf8/example_test.go +++ b/src/unicode/utf8/example_test.go @@ -214,3 +214,13 @@ func ExampleValidString() { // true // false } + +func ExampleAppendRune() { + buf1 := utf8.AppendRune(nil, 0x10000) + buf2 := utf8.AppendRune([]byte("init"), 0x10000) + fmt.Println(string(buf1)) + fmt.Println(string(buf2)) + // Output: + // 𐀀 + // init𐀀 +} diff --git a/src/unicode/utf8/utf8_test.go b/src/unicode/utf8/utf8_test.go index a60040ecfd..e9be4d2d63 100644 --- a/src/unicode/utf8/utf8_test.go +++ b/src/unicode/utf8/utf8_test.go @@ -133,7 +133,7 @@ func TestAppendRune(t *testing.T) { t.Errorf("AppendRune(nil, %#04x) = %s, want %s", m.r, buf, m.str) } if buf := AppendRune([]byte("init"), m.r); string(buf) != "init"+m.str { - t.Errorf("AppendRune(nil, %#04x) = %s, want %s", m.r, buf, "init"+m.str) + t.Errorf("AppendRune(init, %#04x) = %s, want %s", m.r, buf, "init"+m.str) } } }