bytes.go
663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// RUN: llgo -o %t %s
// RUN: %t 2>&1 | FileCheck %s
// CHECK: testBytesConversion: true
// CHECK-NEXT: 97
// CHECK-NEXT: 98
// CHECK-NEXT: 99
// CHECK-NEXT: abc
// CHECK-NEXT: !bc
// CHECK-NEXT: testBytesCopy: true
package main
type namedByte byte
func testBytesConversion() {
s := "abc"
b := []byte(s)
println("testBytesConversion:", s == string(b))
nb := []namedByte(s)
for _, v := range nb {
println(v)
}
b[0] = '!'
println(s)
s = string(b)
b[0] = 'a'
println(s)
}
func testBytesCopy() {
s := "abc"
b := make([]byte, len(s))
copy(b, s)
println("testBytesCopy:", string(b) == s)
}
func main() {
testBytesConversion()
testBytesCopy()
}