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.go tests chan operations.
6package main
7
8import "testing"
9
10//go:noinline
11func lenChan_ssa(v chan int) int {
12	return len(v)
13}
14
15//go:noinline
16func capChan_ssa(v chan int) int {
17	return cap(v)
18}
19
20func testLenChan(t *testing.T) {
21
22	v := make(chan int, 10)
23	v <- 1
24	v <- 1
25	v <- 1
26
27	if want, got := 3, lenChan_ssa(v); got != want {
28		t.Errorf("expected len(chan) = %d, got %d", want, got)
29	}
30}
31
32func testLenNilChan(t *testing.T) {
33
34	var v chan int
35	if want, got := 0, lenChan_ssa(v); got != want {
36		t.Errorf("expected len(nil) = %d, got %d", want, got)
37	}
38}
39
40func testCapChan(t *testing.T) {
41
42	v := make(chan int, 25)
43
44	if want, got := 25, capChan_ssa(v); got != want {
45		t.Errorf("expected cap(chan) = %d, got %d", want, got)
46	}
47}
48
49func testCapNilChan(t *testing.T) {
50
51	var v chan int
52	if want, got := 0, capChan_ssa(v); got != want {
53		t.Errorf("expected cap(nil) = %d, got %d", want, got)
54	}
55}
56
57func TestChan(t *testing.T) {
58	testLenChan(t)
59	testLenNilChan(t)
60
61	testCapChan(t)
62	testCapNilChan(t)
63}
64