.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.1.0 / go / ssa / interp / testdata / range.go
diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.0/go/ssa/interp/testdata/range.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.0/go/ssa/interp/testdata/range.go
new file mode 100644 (file)
index 0000000..a106336
--- /dev/null
@@ -0,0 +1,55 @@
+package main
+
+// Tests of range loops.
+
+import "fmt"
+
+// Range over string.
+func init() {
+       if x := len("Hello, 世界"); x != 13 { // bytes
+               panic(x)
+       }
+       var indices []int
+       var runes []rune
+       for i, r := range "Hello, 世界" {
+               runes = append(runes, r)
+               indices = append(indices, i)
+       }
+       if x := fmt.Sprint(runes); x != "[72 101 108 108 111 44 32 19990 30028]" {
+               panic(x)
+       }
+       if x := fmt.Sprint(indices); x != "[0 1 2 3 4 5 6 7 10]" {
+               panic(x)
+       }
+       s := ""
+       for _, r := range runes {
+               s += string(r)
+       }
+       if s != "Hello, 世界" {
+               panic(s)
+       }
+
+       var x int
+       for range "Hello, 世界" {
+               x++
+       }
+       if x != len(indices) {
+               panic(x)
+       }
+}
+
+// Regression test for range of pointer to named array type.
+func init() {
+       type intarr [3]int
+       ia := intarr{1, 2, 3}
+       var count int
+       for _, x := range &ia {
+               count += x
+       }
+       if count != 6 {
+               panic(count)
+       }
+}
+
+func main() {
+}