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