modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/initcomma.go (about) 1 // run 2 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. 6 7 // Test trailing commas. DO NOT gofmt THIS FILE. 8 9 package main 10 11 var a = []int{1, 2, } 12 var b = [5]int{1, 2, 3, } 13 var c = []int{1, } 14 var d = [...]int{1, 2, 3, } 15 16 func main() { 17 if len(a) != 2 { 18 println("len a", len(a)) 19 panic("fail") 20 } 21 if len(b) != 5 { 22 println("len b", len(b)) 23 panic("fail") 24 } 25 if len(c) != 1 { 26 println("len d", len(c)) 27 panic("fail") 28 } 29 if len(d) != 3 { 30 println("len c", len(d)) 31 panic("fail") 32 } 33 34 if a[0] != 1 { 35 println("a[0]", a[0]) 36 panic("fail") 37 } 38 if a[1] != 2 { 39 println("a[1]", a[1]) 40 panic("fail") 41 } 42 43 if b[0] != 1 { 44 println("b[0]", b[0]) 45 panic("fail") 46 } 47 if b[1] != 2 { 48 println("b[1]", b[1]) 49 panic("fail") 50 } 51 if b[2] != 3 { 52 println("b[2]", b[2]) 53 panic("fail") 54 } 55 if b[3] != 0 { 56 println("b[3]", b[3]) 57 panic("fail") 58 } 59 if b[4] != 0 { 60 println("b[4]", b[4]) 61 panic("fail") 62 } 63 64 if c[0] != 1 { 65 println("c[0]", c[0]) 66 panic("fail") 67 } 68 69 if d[0] != 1 { 70 println("d[0]", d[0]) 71 panic("fail") 72 } 73 if d[1] != 2 { 74 println("d[1]", d[1]) 75 panic("fail") 76 } 77 if d[2] != 3 { 78 println("d[2]", d[2]) 79 panic("fail") 80 } 81 }