OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [stringrange.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $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
        "unicode/utf8"
13
)
14
 
15
func main() {
16
        s := "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe\U0010FFFFx"
17
        expect := []rune{0, 0123, 0, 0xFFFD, 0xFFFD, 0x123, 0xbabe, 0xbabe, 0x10FFFF, 'x'}
18
        offset := 0
19
        var i int
20
        var c rune
21
        ok := true
22
        cnum := 0
23
        for i, c = range s {
24
                r, 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 r != expect[cnum] {
30
                        fmt.Printf("unexpected rune %d from DecodeRuneInString: %x not %x\n", i, r, expect[cnum])
31
                        ok = false
32
                }
33
                if c != expect[cnum] {
34
                        fmt.Printf("unexpected rune %d from range: %x not %x\n", i, r, 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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.