1 // $G $D/$F.go && $L $F.$A && ./$A.out
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.
9 // test range over channels
11 func gen(c chan int, lo, hi int) {
12 for i := lo; i <= hi; i++ {
18 func seq(lo, hi int) chan int {
26 for i := range seq('a', 'z') {
29 if s != "abcdefghijklmnopqrstuvwxyz" {
30 panicln("Wanted lowercase alphabet; got", s);
34 // test that range over array only evaluates
35 // the expression after "range" once.
38 func makearray() []int {
40 return []int{1,2,3,4,5};
45 for _, v := range makearray() {
49 panicln("range called makearray", nmake, "times");
52 panicln("wrong sum ranging over makearray");
56 // test that range evaluates the index and value expressions
57 // exactly once per iteration.
60 func getvar(p *int) *int {
69 for *getvar(&i), *getvar(&v) = range [2]int{1, 2} {
74 panicln("wrong number of calls:", ncalls, "!= 4")
76 if si != 1 || sv != 3 {
77 panicln("wrong sum in testcalls", si, sv)
81 for *getvar(&i), *getvar(&v) = range [0]int{} {
82 panicln("loop ran on empty array")
85 panicln("wrong number of calls:", ncalls, "!= 0")