]> Cypherpunks.ru repositories - gostls13.git/blob - test/stringrange.go
fix up some irregular indentation
[gostls13.git] / test / stringrange.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 import (
10         "fmt";
11         "os";
12         "utf8";
13 )
14
15 func main() {
16         s := "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe\U0010FFFFx";
17         expect := []int{ 0, 0123, 0, 0xFFFD, 0xFFFD, 0x123, 0xbabe, 0xbabe, 0x10FFFF, 'x' };
18         var rune, size int;
19         offset := 0;
20         var i, c int;
21         ok := true;
22         cnum := 0;
23         for i, c = range s {
24                 rune, size := utf8.DecodeRuneInString(s[i:len(s)]);  // check it another way
25                 if i != offset {
26                         fmt.Printf("unexpected offset %d not %d\n", i, offset);
27                         ok = false;
28                 }
29                 if rune != expect[cnum] {
30                         fmt.Printf("unexpected rune %d from DecodeRuneInString: %x not %x\n", i, rune, expect[cnum]);
31                         ok = false;
32                 }
33                 if c != expect[cnum] {
34                         fmt.Printf("unexpected rune %d from range: %x not %x\n", i, rune, expect[cnum]);
35                         ok = false;
36                 }
37                 offset += size;
38                 cnum++;
39         }
40         if i != len(s)-1 {
41                 fmt.Println("after loop i is", i, "not", len(s)-1);
42                 ok = false;
43         }
44
45         i = 12345;
46         c = 23456;
47         for i, c = range "" {
48         }
49         if i != 12345 {
50                 fmt.Println("range empty string assigned to index:", i);
51                 ok = false;
52         }
53         if c != 23456 {
54                 fmt.Println("range empty string assigned to value:", c);
55                 ok = false;
56         }
57
58         if !ok {
59                 fmt.Println("BUG: stringrange");
60                 os.Exit(1)
61         }
62 }