aboutsummaryrefslogtreecommitdiff
path: root/test/utf.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-10-25 22:20:02 -0700
committerRuss Cox <rsc@golang.org>2011-10-25 22:20:02 -0700
commitdb33959797ad8ef1e86725db62aafb40297ea725 (patch)
tree83205f46a52d3ebc4a22cc151968d958b8524b28 /test/utf.go
parent6ed3fa6553d84391157eae963eeee5f20b6dca74 (diff)
downloadgo-db33959797ad8ef1e86725db62aafb40297ea725.tar.gz
go-db33959797ad8ef1e86725db62aafb40297ea725.zip
cgo, goyacc, go/build, html, http, path, path/filepath, testing/quick, test: use rune
Nothing terribly interesting here. R=golang-dev, bradfitz, gri, r CC=golang-dev https://golang.org/cl/5300043
Diffstat (limited to 'test/utf.go')
-rw-r--r--test/utf.go30
1 files changed, 20 insertions, 10 deletions
diff --git a/test/utf.go b/test/utf.go
index a93fc29341..ed8a983d8f 100644
--- a/test/utf.go
+++ b/test/utf.go
@@ -9,7 +9,7 @@ package main
import "utf8"
func main() {
- var chars [6] int
+ var chars [6]rune
chars[0] = 'a'
chars[1] = 'b'
chars[2] = 'c'
@@ -21,16 +21,22 @@ func main() {
s += string(chars[i])
}
var l = len(s)
- for w, i, j := 0,0,0; i < l; i += w {
- var r int
+ for w, i, j := 0, 0, 0; i < l; i += w {
+ var r rune
r, w = utf8.DecodeRuneInString(s[i:len(s)])
- if w == 0 { panic("zero width in string") }
- if r != chars[j] { panic("wrong value from string") }
+ if w == 0 {
+ panic("zero width in string")
+ }
+ if r != chars[j] {
+ panic("wrong value from string")
+ }
j++
}
// encoded as bytes: 'a' 'b' 'c' e6 97 a5 e6 9c ac e8 aa 9e
const L = 12
- if L != l { panic("wrong length constructing array") }
+ if L != l {
+ panic("wrong length constructing array")
+ }
a := make([]byte, L)
a[0] = 'a'
a[1] = 'b'
@@ -44,11 +50,15 @@ func main() {
a[9] = 0xe8
a[10] = 0xaa
a[11] = 0x9e
- for w, i, j := 0,0,0; i < L; i += w {
- var r int
+ for w, i, j := 0, 0, 0; i < L; i += w {
+ var r rune
r, w = utf8.DecodeRune(a[i:L])
- if w == 0 { panic("zero width in bytes") }
- if r != chars[j] { panic("wrong value from bytes") }
+ if w == 0 {
+ panic("zero width in bytes")
+ }
+ if r != chars[j] {
+ panic("wrong value from bytes")
+ }
j++
}
}