summaryrefslogtreecommitdiff
path: root/gcc/testsuite/go.test/test/utf.go
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/go.test/test/utf.go
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/go.test/test/utf.go')
-rw-r--r--gcc/testsuite/go.test/test/utf.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/gcc/testsuite/go.test/test/utf.go b/gcc/testsuite/go.test/test/utf.go
new file mode 100644
index 000000000..a93fc2934
--- /dev/null
+++ b/gcc/testsuite/go.test/test/utf.go
@@ -0,0 +1,54 @@
+// $G $F.go && $L $F.$A && ./$A.out
+
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "utf8"
+
+func main() {
+ var chars [6] int
+ chars[0] = 'a'
+ chars[1] = 'b'
+ chars[2] = 'c'
+ chars[3] = '\u65e5'
+ chars[4] = '\u672c'
+ chars[5] = '\u8a9e'
+ s := ""
+ for i := 0; i < 6; i++ {
+ s += string(chars[i])
+ }
+ var l = len(s)
+ for w, i, j := 0,0,0; i < l; i += w {
+ var r int
+ 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") }
+ 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") }
+ a := make([]byte, L)
+ a[0] = 'a'
+ a[1] = 'b'
+ a[2] = 'c'
+ a[3] = 0xe6
+ a[4] = 0x97
+ a[5] = 0xa5
+ a[6] = 0xe6
+ a[7] = 0x9c
+ a[8] = 0xac
+ a[9] = 0xe8
+ a[10] = 0xaa
+ a[11] = 0x9e
+ for w, i, j := 0,0,0; i < L; i += w {
+ var r int
+ r, w = utf8.DecodeRune(a[i:L])
+ if w == 0 { panic("zero width in bytes") }
+ if r != chars[j] { panic("wrong value from bytes") }
+ j++
+ }
+}