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 <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Trust: Robert Findley <rfindley@google.com>
Trust: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
jiahua wang 2021-10-07 15:30:03 +08:00 committed by Ian Lance Taylor
parent fb8b1764d8
commit 75952abc6a
2 changed files with 11 additions and 1 deletions

View File

@ -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𐀀
}

View File

@ -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)
}
}
}