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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $D/$F.go && $L $F.$A && ./$A.out 2>&1 | cmp - $D/$F.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
 
8
package main
9
 
10
func main() {
11
        var c string
12
 
13
        a := `abc`
14
        b := `xyz`
15
 
16
        /* print a literal */
17
        print(`abc`)
18
 
19
        /* print a variable */
20
        print(b, "-")
21
 
22
        /* catenate literals */
23
        print(`abc`+`xyz`, "-")
24
 
25
        /* catenate variables */
26
        print(a+b, "-")
27
 
28
        /* compare literals */
29
        if `abc` == `xyz` || `abc` != "abc" || `abc` > `xyz` {
30
                panic("compare literals")
31
        }
32
 
33
        /* compare variables */
34
        if a == b || a != a || a > b {
35
                panic("compare variables")
36
        }
37
 
38
        /* cat */
39
        c = a + b
40
        print(c, "-")
41
 
42
        /* catequal */
43
        c = a
44
        c += b
45
        print(c, "-")
46
 
47
        /* clumsy evaluation */
48
        c = b
49
        c = a + c
50
        print(c, "-")
51
 
52
        /* len */
53
        if len(c) != 6 {
54
                print("len ", len(c))
55
                panic("fail")
56
        }
57
 
58
        /* index strings */
59
        for i := 0; i < len(c); i = i + 1 {
60
                if c[i] != (a + b)[i] {
61
                        print("index ", i, " ", c[i], " ", (a + b)[i])
62
                        panic("fail")
63
                }
64
        }
65
 
66
        /* slice strings */
67
        print(c[0:3], c[3:])
68
 
69
        print("\n")
70
 
71
        /* create string with integer constant */
72
        c = string('x')
73
        if c != "x" {
74
                panic("create int " + c)
75
        }
76
 
77
        /* create string with integer variable */
78
        v := 'x'
79
        c = string(v)
80
        if c != "x" {
81
                panic("create int " + c)
82
        }
83
 
84
        /* create string with byte array */
85
        var z1 [3]byte
86
        z1[0] = 'a'
87
        z1[1] = 'b'
88
        z1[2] = 'c'
89
        c = string(z1[0:])
90
        if c != "abc" {
91
                panic("create byte array " + c)
92
        }
93
 
94
        /* create string with int array */
95
        var z2 [3]rune
96
        z2[0] = 'a'
97
        z2[1] = '\u1234'
98
        z2[2] = 'c'
99
        c = string(z2[0:])
100
        if c != "a\u1234c" {
101
                panic("create int array " + c)
102
        }
103
 
104
        /* create string with byte array pointer */
105
        z3 := new([3]byte)
106
        z3[0] = 'a'
107
        z3[1] = 'b'
108
        z3[2] = 'c'
109
        c = string(z3[0:])
110
        if c != "abc" {
111
                panic("create array pointer " + c)
112
        }
113
}

powered by: WebSVN 2.1.0

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