Home | History | Annotate | Download | only in testdata
      1 // Copyright 2015 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 // chan_ssa.go tests chan operations.
      6 package main
      7 
      8 import "fmt"
      9 
     10 var failed = false
     11 
     12 //go:noinline
     13 func lenChan_ssa(v chan int) int {
     14 	return len(v)
     15 }
     16 
     17 //go:noinline
     18 func capChan_ssa(v chan int) int {
     19 	return cap(v)
     20 }
     21 
     22 func testLenChan() {
     23 
     24 	v := make(chan int, 10)
     25 	v <- 1
     26 	v <- 1
     27 	v <- 1
     28 
     29 	if want, got := 3, lenChan_ssa(v); got != want {
     30 		fmt.Printf("expected len(chan) = %d, got %d", want, got)
     31 		failed = true
     32 	}
     33 }
     34 
     35 func testLenNilChan() {
     36 
     37 	var v chan int
     38 	if want, got := 0, lenChan_ssa(v); got != want {
     39 		fmt.Printf("expected len(nil) = %d, got %d", want, got)
     40 		failed = true
     41 	}
     42 }
     43 
     44 func testCapChan() {
     45 
     46 	v := make(chan int, 25)
     47 
     48 	if want, got := 25, capChan_ssa(v); got != want {
     49 		fmt.Printf("expected cap(chan) = %d, got %d", want, got)
     50 		failed = true
     51 	}
     52 }
     53 
     54 func testCapNilChan() {
     55 
     56 	var v chan int
     57 	if want, got := 0, capChan_ssa(v); got != want {
     58 		fmt.Printf("expected cap(nil) = %d, got %d", want, got)
     59 		failed = true
     60 	}
     61 }
     62 
     63 func main() {
     64 	testLenChan()
     65 	testLenNilChan()
     66 
     67 	testCapChan()
     68 	testCapNilChan()
     69 
     70 	if failed {
     71 		panic("failed")
     72 	}
     73 }
     74