Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / testsuite / go.test / test / utf.go
bloba93fc293416ef31ace5d7dad6eaca7c3666d3d36
1 // $G $F.go && $L $F.$A && ./$A.out
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 package main
9 import "utf8"
11 func main() {
12 var chars [6] int
13 chars[0] = 'a'
14 chars[1] = 'b'
15 chars[2] = 'c'
16 chars[3] = '\u65e5'
17 chars[4] = '\u672c'
18 chars[5] = '\u8a9e'
19 s := ""
20 for i := 0; i < 6; i++ {
21 s += string(chars[i])
23 var l = len(s)
24 for w, i, j := 0,0,0; i < l; i += w {
25 var r int
26 r, w = utf8.DecodeRuneInString(s[i:len(s)])
27 if w == 0 { panic("zero width in string") }
28 if r != chars[j] { panic("wrong value from string") }
29 j++
31 // encoded as bytes: 'a' 'b' 'c' e6 97 a5 e6 9c ac e8 aa 9e
32 const L = 12
33 if L != l { panic("wrong length constructing array") }
34 a := make([]byte, L)
35 a[0] = 'a'
36 a[1] = 'b'
37 a[2] = 'c'
38 a[3] = 0xe6
39 a[4] = 0x97
40 a[5] = 0xa5
41 a[6] = 0xe6
42 a[7] = 0x9c
43 a[8] = 0xac
44 a[9] = 0xe8
45 a[10] = 0xaa
46 a[11] = 0x9e
47 for w, i, j := 0,0,0; i < L; i += w {
48 var r int
49 r, w = utf8.DecodeRune(a[i:L])
50 if w == 0 { panic("zero width in bytes") }
51 if r != chars[j] { panic("wrong value from bytes") }
52 j++