codekingpro/portable-devtools
114k
1// run2 3// Copyright 2011 The Go Authors. All rights reserved.4// Use of this source code is governed by a BSD-style5// license that can be found in the LICENSE file.6 7// Test len constants and non-constants, https://golang.org/issue/3244.8 9package main10 11var b struct {12 a [10]int13}14 15var m map[string][20]int16 17var s [][30]int18 19const (20 n1 = len(b.a)21 n2 = len(m[""])22 n3 = len(s[10])23)24 25// Non-constants (see also const5.go).26var (27 n4 = len(f())28 n5 = len(<-c)29 n6 = cap(g())30 n7 = cap(<-c1)31)32 33var calledF = false34 35func f() *[40]int {36 calledF = true37 return nil38}39 40var c = func() chan *[50]int {41 c := make(chan *[50]int, 2)42 c <- nil43 c <- new([50]int)44 return c45}()46 47var calledG = false48 49func g() *[60]int {50 calledG = true51 return nil52}53 54var c1 = func() chan *[70]int {55 c := make(chan *[70]int, 2)56 c <- nil57 c <- new([70]int)58 return c59}()60 61func main() {62 if n1 != 10 || n2 != 20 || n3 != 30 || n4 != 40 || n5 != 50 || n6 != 60 || n7 != 70 {63 println("BUG:", n1, n2, n3, n4, n5, n6, n7)64 panic("fail")65 }66 if !calledF {67 println("BUG: did not call f")68 panic("fail")69 }70 if <-c == nil {71 println("BUG: did not receive from c")72 panic("fail")73 }74 if !calledG {75 println("BUG: did not call g")76 panic("fail")77 }78 if <-c1 == nil {79 println("BUG: did not receive from c1")80 panic("fail")81 }82}83 