GoPLS Viewer

Home|gopls/go/ssa/interp/testdata/range.go
1package main
2
3// Tests of range loops.
4
5import "fmt"
6
7// Range over string.
8func init() {
9    if x := len("Hello, 世界"); x != 13 { // bytes
10        panic(x)
11    }
12    var indices []int
13    var runes []rune
14    for ir := range "Hello, 世界" {
15        runes = append(runesr)
16        indices = append(indicesi)
17    }
18    if x := fmt.Sprint(runes); x != "[72 101 108 108 111 44 32 19990 30028]" {
19        panic(x)
20    }
21    if x := fmt.Sprint(indices); x != "[0 1 2 3 4 5 6 7 10]" {
22        panic(x)
23    }
24    s := ""
25    for _r := range runes {
26        s += string(r)
27    }
28    if s != "Hello, 世界" {
29        panic(s)
30    }
31
32    var x int
33    for range "Hello, 世界" {
34        x++
35    }
36    if x != len(indices) {
37        panic(x)
38    }
39}
40
41// Regression test for range of pointer to named array type.
42func init() {
43    type intarr [3]int
44    ia := intarr{123}
45    var count int
46    for _x := range &ia {
47        count += x
48    }
49    if count != 6 {
50        panic(count)
51    }
52}
53
54func main() {
55}
56
MembersX
init.BlockStmt.RangeStmt_193.i
init.BlockStmt.ia
init.BlockStmt.count
init.BlockStmt.indices
init.BlockStmt.runes
init.BlockStmt.RangeStmt_193.r
init.BlockStmt.RangeStmt_464.r
init.BlockStmt.intarr
init.BlockStmt.RangeStmt_776.x
Members
X