mirror of
https://github.com/golang/go
synced 2024-11-22 02:44:39 -07:00
test: enable tests using v, ok := <-ch syntax
R=rsc, r CC=golang-dev https://golang.org/cl/4290059
This commit is contained in:
parent
1da382c871
commit
169e6d40e3
@ -7,15 +7,14 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
//TODO(rsc): uncomment when this syntax is valid for receive+check closed
|
||||
// c := make(chan int);
|
||||
// ok := false;
|
||||
// var i int;
|
||||
//
|
||||
// i, ok = <-c; // works
|
||||
// _, _ = i, ok;
|
||||
//
|
||||
// ca := new([2]chan int);
|
||||
// i, ok = <-(ca[0]); // fails: c.go:11: bad shape across assignment - cr=1 cl=2
|
||||
// _, _ = i, ok;
|
||||
c := make(chan int);
|
||||
ok := false;
|
||||
var i int;
|
||||
|
||||
i, ok = <-c; // works
|
||||
_, _ = i, ok;
|
||||
|
||||
ca := new([2]chan int);
|
||||
i, ok = <-(ca[0]); // fails: c.go:11: bad shape across assignment - cr=1 cl=2
|
||||
_, _ = i, ok;
|
||||
}
|
||||
|
@ -13,12 +13,11 @@ var i int
|
||||
func multi() (int, int) { return 1, 2 }
|
||||
|
||||
func xxx() {
|
||||
//TODO(rsc): uncomment when this syntax is valid for receive+check closed
|
||||
// var c chan int
|
||||
// x, ok := <-c
|
||||
var c chan int
|
||||
x, ok := <-c
|
||||
|
||||
var m map[int]int
|
||||
x, ok := m[1]
|
||||
x, ok = m[1]
|
||||
|
||||
var i interface{}
|
||||
var xx int
|
||||
|
@ -7,17 +7,17 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
//TODO(rsc): uncomment when this syntax is valid for receive+check closed
|
||||
// c := make(chan int, 1)
|
||||
// c <- 100
|
||||
// x, ok := <-c
|
||||
// if x != 100 || !ok {
|
||||
// println("x=", x, " ok=", ok, " want 100, true")
|
||||
// panic("fail")
|
||||
// }
|
||||
// x, ok = <-c
|
||||
// if x != 0 || ok {
|
||||
// println("x=", x, " ok=", ok, " want 0, false")
|
||||
// panic("fail")
|
||||
// }
|
||||
c := make(chan int, 1)
|
||||
c <- 100
|
||||
x, ok := <-c
|
||||
if x != 100 || !ok {
|
||||
println("x=", x, " ok=", ok, " want 100, true")
|
||||
panic("fail")
|
||||
}
|
||||
close(c)
|
||||
x, ok = <-c
|
||||
if x != 0 || ok {
|
||||
println("x=", x, " ok=", ok, " want 0, false")
|
||||
panic("fail")
|
||||
}
|
||||
}
|
||||
|
@ -101,13 +101,11 @@ func main() {
|
||||
|
||||
c := make(chan byte, 1)
|
||||
c <- 'C'
|
||||
//TODO(rsc): uncomment when this syntax is valid for receive+check closed
|
||||
// 15 16
|
||||
// *f(), p1 = <-e1(c, 16)
|
||||
*f(), p1 = <-e1(c, 16), true // delete uncommenting above
|
||||
*f(), p1 = <-e1(c, 16)
|
||||
close(c)
|
||||
// 17 18
|
||||
// *f(), p2 = <-e1(c, 18)
|
||||
*f(), p2, _ = 0, false, e1(c, 18) // delete when uncommenting above
|
||||
*f(), p2 = <-e1(c, 18)
|
||||
a[17] += '0'
|
||||
if !p1 || p2 {
|
||||
println("bad chan check", i, p1, p2)
|
||||
|
Loading…
Reference in New Issue
Block a user