Source file
test/ken/string.go
1
2
3
4
5
6
7
8
9 package main
10
11 func main() {
12 var c string
13
14 a := `abc`
15 b := `xyz`
16
17
18 print(`abc`)
19
20
21 print(b, "-")
22
23
24 print(`abc`+`xyz`, "-")
25
26
27 print(a+b, "-")
28
29
30 if `abc` == `xyz` || `abc` != "abc" || `abc` > `xyz` {
31 panic("compare literals")
32 }
33
34
35 if a == b || a != a || a > b {
36 panic("compare variables")
37 }
38
39
40 c = a + b
41 print(c, "-")
42
43
44 c = a
45 c += b
46 print(c, "-")
47
48
49 c = b
50 c = a + c
51 print(c, "-")
52
53
54 if len(c) != 6 {
55 print("len ", len(c))
56 panic("fail")
57 }
58
59
60 for i := 0; i < len(c); i = i + 1 {
61 if c[i] != (a + b)[i] {
62 print("index ", i, " ", c[i], " ", (a + b)[i])
63 panic("fail")
64 }
65 }
66
67
68 print(c[0:3], c[3:])
69
70 print("\n")
71
72
73 c = string('x')
74 if c != "x" {
75 panic("create int " + c)
76 }
77
78
79 v := 'x'
80 c = string(v)
81 if c != "x" {
82 panic("create int " + c)
83 }
84
85
86 var z1 [3]byte
87 z1[0] = 'a'
88 z1[1] = 'b'
89 z1[2] = 'c'
90 c = string(z1[0:])
91 if c != "abc" {
92 panic("create byte array " + c)
93 }
94
95
96 var z2 [3]rune
97 z2[0] = 'a'
98 z2[1] = '\u1234'
99 z2[2] = 'c'
100 c = string(z2[0:])
101 if c != "a\u1234c" {
102 panic("create int array " + c)
103 }
104
105
106 z3 := new([3]byte)
107 z3[0] = 'a'
108 z3[1] = 'b'
109 z3[2] = 'c'
110 c = string(z3[0:])
111 if c != "abc" {
112 panic("create array pointer " + c)
113 }
114 }
115
View as plain text