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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [string_lit.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 "os"
10
 
11
var ecode int
12
 
13
func assert(a, b, c string) {
14
        if a != b {
15
                ecode = 1
16
                print("FAIL: ", c, ": ", a, "!=", b, "\n")
17
                var max int = len(a)
18
                if len(b) > max {
19
                        max = len(b)
20
                }
21
                for i := 0; i < max; i++ {
22
                        ac := 0
23
                        bc := 0
24
                        if i < len(a) {
25
                                ac = int(a[i])
26
                        }
27
                        if i < len(b) {
28
                                bc = int(b[i])
29
                        }
30
                        if ac != bc {
31
                                print("\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n")
32
                        }
33
                }
34
        }
35
}
36
 
37
const (
38
        gx1    = "aä本☺"
39
        gx2    = "aä\xFF\xFF本☺"
40
        gx2fix = "aä\uFFFD\uFFFD本☺"
41
)
42
 
43
var (
44
        gr1 = []rune(gx1)
45
        gr2 = []rune(gx2)
46
        gb1 = []byte(gx1)
47
        gb2 = []byte(gx2)
48
)
49
 
50
func main() {
51
        ecode = 0
52
        s :=
53
                "" +
54
                        " " +
55
                        "'`" +
56
                        "a" +
57
                        "ä" +
58
                        "本" +
59
                        "\a\b\f\n\r\t\v\\\"" +
60
                        "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe" +
61
 
62
                        `` +
63
                        ` ` +
64
                        `'"` +
65
                        `a` +
66
                        `ä` +
67
                        `本` +
68
                        `\a\b\f\n\r\t\v\\\'` +
69
                        `\000\123\x00\xca\xFE\u0123\ubabe\U0000babe` +
70
                        `\x\u\U\`
71
 
72
        assert("", ``, "empty")
73
        assert(" ", " ", "blank")
74
        assert("\x61", "a", "lowercase a")
75
        assert("\x61", `a`, "lowercase a (backquote)")
76
        assert("\u00e4", "ä", "a umlaut")
77
        assert("\u00e4", `ä`, "a umlaut (backquote)")
78
        assert("\u672c", "本", "nihon")
79
        assert("\u672c", `本`, "nihon (backquote)")
80
        assert("\x07\x08\x0c\x0a\x0d\x09\x0b\x5c\x22",
81
                "\a\b\f\n\r\t\v\\\"",
82
                "backslashes")
83
        assert("\\a\\b\\f\\n\\r\\t\\v\\\\\\\"",
84
                `\a\b\f\n\r\t\v\\\"`,
85
                "backslashes (backquote)")
86
        assert("\x00\x53\000\xca\376S몾몾",
87
                "\000\123\x00\312\xFE\u0053\ubabe\U0000babe",
88
                "backslashes 2")
89
        assert("\\000\\123\\x00\\312\\xFE\\u0123\\ubabe\\U0000babe",
90
                `\000\123\x00\312\xFE\u0123\ubabe\U0000babe`,
91
                "backslashes 2 (backquote)")
92
        assert("\\x\\u\\U\\", `\x\u\U\`, "backslash 3 (backquote)")
93
 
94
        // test large runes. perhaps not the most logical place for this test.
95
        var r int32
96
        r = 0x10ffff // largest rune value
97
        s = string(r)
98
        assert(s, "\xf4\x8f\xbf\xbf", "largest rune")
99
        r = 0x10ffff + 1
100
        s = string(r)
101
        assert(s, "\xef\xbf\xbd", "too-large rune")
102
 
103
        assert(string(gr1), gx1, "global ->[]rune")
104
        assert(string(gr2), gx2fix, "global invalid ->[]rune")
105
        assert(string(gb1), gx1, "->[]byte")
106
        assert(string(gb2), gx2, "global invalid ->[]byte")
107
 
108
        var (
109
                r1 = []rune(gx1)
110
                r2 = []rune(gx2)
111
                b1 = []byte(gx1)
112
                b2 = []byte(gx2)
113
        )
114
        assert(string(r1), gx1, "->[]rune")
115
        assert(string(r2), gx2fix, "invalid ->[]rune")
116
        assert(string(b1), gx1, "->[]byte")
117
        assert(string(b2), gx2, "invalid ->[]byte")
118
 
119
        os.Exit(ecode)
120
}

powered by: WebSVN 2.1.0

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