]> Cypherpunks.ru repositories - gostls13.git/blob - test/utf.go
minor int/float fixes
[gostls13.git] / test / utf.go
1 // $G $F.go && $L $F.$A && ./$A.out
2
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.
6
7 package main
8
9 func main() {
10         var chars [6] int;
11         chars[0] = 'a';
12         chars[1] = 'b';
13         chars[2] = 'c';
14         chars[3] = '\u65e5';
15         chars[4] = '\u672c';
16         chars[5] = '\u8a9e';
17         s := "";
18         for i := 0; i < 6; i++ {
19                 s += string(chars[i]);
20         }
21         var l = len(s);
22         for w, i, j := 0,0,0; i < l; i += w {
23                 var r int;
24                 r, w = sys.stringtorune(s, i);
25                 if w == 0 { panic("zero width in string") }
26                 if r != chars[j] { panic("wrong value from string") }
27                 j++;
28         }
29         // encoded as bytes:  'a' 'b' 'c' e6 97 a5 e6 9c ac e8 aa 9e
30         const L = 12;
31         if L != l { panic("wrong length constructing array") }
32         a := new([L]byte);
33         a[0] = 'a';
34         a[1] = 'b';
35         a[2] = 'c';
36         a[3] = 0xe6;
37         a[4] = 0x97;
38         a[5] = 0xa5;
39         a[6] = 0xe6;
40         a[7] = 0x9c;
41         a[8] = 0xac;
42         a[9] = 0xe8;
43         a[10] = 0xaa;
44         a[11] = 0x9e;
45         for w, i, j := 0,0,0; i < L; i += w {
46                 var r int;
47                 r, w = sys.bytestorune(&a[0], i, L);
48                 if w == 0 { panic("zero width in bytes") }
49                 if r != chars[j] { panic("wrong value from bytes") }
50                 j++;
51         }
52 }