]> Cypherpunks repositories - gostls13.git/commitdiff
unicode/utf8: add AppendRune Example
authorjiahua wang <wjh180909@gmail.com>
Thu, 7 Oct 2021 07:30:03 +0000 (15:30 +0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 5 Nov 2021 21:29:18 +0000 (21:29 +0000)
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>

src/unicode/utf8/example_test.go
src/unicode/utf8/utf8_test.go

index 5cd931d24279ff27eb4a1343dc9a306998f32020..fe434c94767c08d560e224fcdf0fec80f95f39e0 100644 (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๐€€
+}
index a60040ecfde8db8853d59b62d30375a960b91993..e9be4d2d636eec84bcb8dc9efe55047a83bf2fd3 100644 (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)
                }
        }
 }