3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test the cap predeclared function applied to channels.
18 const ptrSize = unsafe.Sizeof((*byte)(nil))
22 if len(c) != 0 || cap(c) != 10 {
23 println("chan len/cap ", len(c), cap(c), " want 0 10")
27 for i := 0; i < 3; i++ {
30 if len(c) != 3 || cap(c) != 10 {
31 println("chan len/cap ", len(c), cap(c), " want 3 10")
36 if len(c) != 0 || cap(c) != 0 {
37 println("chan len/cap ", len(c), cap(c), " want 0 0")
42 shouldPanic("makechan: size out of range", func() { _ = make(T, n) })
43 shouldPanic("makechan: size out of range", func() { _ = make(T, int64(n)) })
45 var n2 int64 = 1 << 50
46 shouldPanic("makechan: size out of range", func() { _ = make(T, int(n2)) })
48 shouldPanic("makechan: size out of range", func() { _ = make(T, int(n2)) })
51 shouldPanic("makechan: size out of range", func() { _ = make(T, n) })
52 shouldPanic("makechan: size out of range", func() { _ = make(T, int64(n)) })
56 func shouldPanic(str string, f func()) {
60 panic("did not panic")
62 s := err.(error).Error()
63 if !strings.Contains(s, str) {
64 panic("got panic " + s + ", want " + str)