diff options
| author | jiahua wang <wjh180909@gmail.com> | 2021-10-07 15:30:03 +0800 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2021-11-05 21:29:18 +0000 |
| commit | 75952abc6a8a8ad09e6bb1966c66b9a68b5d6c4e (patch) | |
| tree | 9a33f6bf8782963bb40175809f4513adc2e47709 | |
| parent | fb8b1764d8e8afdaf5d8fd00af3720e42d96ad9c (diff) | |
| download | go-75952abc6a8a8ad09e6bb1966c66b9a68b5d6c4e.tar.xz | |
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>
| -rw-r--r-- | src/unicode/utf8/example_test.go | 10 | ||||
| -rw-r--r-- | src/unicode/utf8/utf8_test.go | 2 |
2 files changed, 11 insertions, 1 deletions
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) } } } |
