aboutsummaryrefslogtreecommitdiff
path: root/src/unicode/utf8/example_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/unicode/utf8/example_test.go')
-rw-r--r--src/unicode/utf8/example_test.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/unicode/utf8/example_test.go b/src/unicode/utf8/example_test.go
index 7b3e7ac742..5cd931d242 100644
--- a/src/unicode/utf8/example_test.go
+++ b/src/unicode/utf8/example_test.go
@@ -107,6 +107,26 @@ func ExampleEncodeRune() {
// 3
}
+func ExampleEncodeRune_outOfRange() {
+ runes := []rune{
+ // Less than 0, out of range.
+ -1,
+ // Greater than 0x10FFFF, out of range.
+ 0x110000,
+ // The Unicode replacement character.
+ utf8.RuneError,
+ }
+ for i, c := range runes {
+ buf := make([]byte, 3)
+ size := utf8.EncodeRune(buf, c)
+ fmt.Printf("%d: %d %[2]s %d\n", i, buf, size)
+ }
+ // Output:
+ // 0: [239 191 189] � 3
+ // 1: [239 191 189] � 3
+ // 2: [239 191 189] � 3
+}
+
func ExampleFullRune() {
buf := []byte{228, 184, 150} // 世
fmt.Println(utf8.FullRune(buf))