diff options
author | Rob Pike <r@golang.org> | 2010-03-24 16:46:53 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2010-03-24 16:46:53 -0700 |
commit | 325cf8ef217b4e9ae2caf53fa0d4534cd5003bd8 (patch) | |
tree | 72405fbc32b0bef0850cac2797f818bccc12b44e /test/closure.go | |
parent | acfd6d5f055ca5283dff5de16390c1d0cfc9f0ca (diff) | |
download | go-git-325cf8ef217b4e9ae2caf53fa0d4534cd5003bd8.tar.gz |
delete all uses of panicln by rewriting them using panic or,
in the tests, println+panic.
gofmt some tests too.
R=rsc
CC=golang-dev
https://golang.org/cl/741041
Diffstat (limited to 'test/closure.go')
-rw-r--r-- | test/closure.go | 107 |
1 files changed, 54 insertions, 53 deletions
diff --git a/test/closure.go b/test/closure.go index 8bb516d29c..54e4cf8eae 100644 --- a/test/closure.go +++ b/test/closure.go @@ -6,95 +6,96 @@ package main -var c = make(chan int); +var c = make(chan int) func check(a []int) { for i := 0; i < len(a); i++ { - n := <-c; + n := <-c if n != a[i] { - panicln("want", a[i], "got", n, "at", i); + println("want", a[i], "got", n, "at", i) + panic("fail") } } } func f() { - var i, j int; + var i, j int - i = 1; - j = 2; + i = 1 + j = 2 f := func() { - c <- i; - i = 4; + c <- i + i = 4 g := func() { - c <- i; - c <- j; - }; - g(); - c <- i; - }; - j = 5; - f(); + c <- i + c <- j + } + g() + c <- i + } + j = 5 + f() } // Accumulator generator -func accum(n int) (func(int) int) { +func accum(n int) func(int) int { return func(i int) int { - n += i; - return n; + n += i + return n } } func g(a, b func(int) int) { - c <- a(2); - c <- b(3); - c <- a(4); - c <- b(5); + c <- a(2) + c <- b(3) + c <- a(4) + c <- b(5) } func h() { - var x8 byte = 100; - var x64 int64 = 200; + var x8 byte = 100 + var x64 int64 = 200 - c <- int(x8); - c <- int(x64); + c <- int(x8) + c <- int(x64) f := func(z int) { g := func() { - c <- int(x8); - c <- int(x64); - c <- z; - }; - g(); - c <- int(x8); - c <- int(x64); - c <- int(z); - }; - x8 = 101; - x64 = 201; - f(500); + c <- int(x8) + c <- int(x64) + c <- z + } + g() + c <- int(x8) + c <- int(x64) + c <- int(z) + } + x8 = 101 + x64 = 201 + f(500) } -func newfunc() (func(int) int) { - return func(x int) int { return x } -} +func newfunc() func(int) int { return func(x int) int { return x } } func main() { - go f(); - check([]int{1,4,5,4}); + go f() + check([]int{1, 4, 5, 4}) - a := accum(0); - b := accum(1); - go g(a, b); - check([]int{2,4,6,9}); + a := accum(0) + b := accum(1) + go g(a, b) + check([]int{2, 4, 6, 9}) - go h(); - check([]int{100,200,101,201,500,101,201,500}); + go h() + check([]int{100, 200, 101, 201, 500, 101, 201, 500}) - x, y := newfunc(), newfunc(); + x, y := newfunc(), newfunc() if x == y { - panicln("newfunc returned same func"); + println("newfunc returned same func") + panic("fail") } if x(1) != 1 || y(2) != 2 { - panicln("newfunc returned broken funcs"); + println("newfunc returned broken funcs") + panic("fail") } } |