modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/ken/complit.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 composite literals.
     8  
     9  package main
    10  
    11  type	M	map[int]int
    12  type	S	struct{ a,b,c int };
    13  type	SS	struct{ aa,bb,cc S };
    14  type	SA	struct{ a,b,c [3]int };
    15  type	SC	struct{ a,b,c []int };
    16  type	SM	struct{ a,b,c M };
    17  
    18  func
    19  main() {
    20  	test("s.a", s.a);
    21  	test("s.b", s.b);
    22  	test("s.c", s.c);
    23  
    24  	test("ss.aa.a", ss.aa.a);
    25  	test("ss.aa.b", ss.aa.b);
    26  	test("ss.aa.c", ss.aa.c);
    27  
    28  	test("ss.bb.a", ss.bb.a);
    29  	test("ss.bb.b", ss.bb.b);
    30  	test("ss.bb.c", ss.bb.c);
    31  
    32  	test("ss.cc.a", ss.cc.a);
    33  	test("ss.cc.b", ss.cc.b);
    34  	test("ss.cc.c", ss.cc.c);
    35  
    36  	for i:=0; i<3; i++ {
    37  		test("a[i]", a[i]);
    38  		test("c[i]", c[i]);
    39  		test("m[i]", m[i]);
    40  
    41  		test("as[i].a", as[i].a);
    42  		test("as[i].b", as[i].b);
    43  		test("as[i].c", as[i].c);
    44  
    45  		test("cs[i].a", cs[i].a);
    46  		test("cs[i].b", cs[i].b);
    47  		test("cs[i].c", cs[i].c);
    48  
    49  		test("ms[i].a", ms[i].a);
    50  		test("ms[i].b", ms[i].b);
    51  		test("ms[i].c", ms[i].c);
    52  
    53  		test("sa.a[i]", sa.a[i]);
    54  		test("sa.b[i]", sa.b[i]);
    55  		test("sa.c[i]", sa.c[i]);
    56  
    57  		test("sc.a[i]", sc.a[i]);
    58  		test("sc.b[i]", sc.b[i]);
    59  		test("sc.c[i]", sc.c[i]);
    60  
    61  		test("sm.a[i]", sm.a[i]);
    62  		test("sm.b[i]", sm.b[i]);
    63  		test("sm.c[i]", sm.c[i]);
    64  
    65  		for j:=0; j<3; j++ {
    66  			test("aa[i][j]", aa[i][j]);
    67  			test("ac[i][j]", ac[i][j]);
    68  			test("am[i][j]", am[i][j]);
    69  			test("ca[i][j]", ca[i][j]);
    70  			test("cc[i][j]", cc[i][j]);
    71  			test("cm[i][j]", cm[i][j]);
    72  			test("ma[i][j]", ma[i][j]);
    73  			test("mc[i][j]", mc[i][j]);
    74  			test("mm[i][j]", mm[i][j]);
    75  		}
    76  	}
    77  
    78  }
    79  
    80  var	ref	= 0;
    81  
    82  func
    83  test(xs string, x int) {
    84  
    85  	if ref >= len(answers) {
    86  		println(xs, x);
    87  		return;
    88  	}
    89  
    90  	if x != answers[ref] {
    91  		println(xs, "is", x, "should be", answers[ref])
    92  	}
    93  	ref++;
    94  }
    95  
    96  
    97  var	a	= [3]int{1001, 1002, 1003}
    98  var	s	= S{1101, 1102, 1103}
    99  var	c	= []int{1201, 1202, 1203}
   100  var	m	= M{0:1301, 1:1302, 2:1303}
   101  
   102  var	aa	= [3][3]int{[3]int{2001,2002,2003}, [3]int{2004,2005,2006}, [3]int{2007,2008,2009}}
   103  var	as	= [3]S{S{2101,2102,2103},S{2104,2105,2106},S{2107,2108,2109}}
   104  var	ac	= [3][]int{[]int{2201,2202,2203}, []int{2204,2205,2206}, []int{2207,2208,2209}}
   105  var	am	= [3]M{M{0:2301,1:2302,2:2303}, M{0:2304,1:2305,2:2306}, M{0:2307,1:2308,2:2309}}
   106  
   107  var	sa	= SA{[3]int{3001,3002,3003},[3]int{3004,3005,3006},[3]int{3007,3008,3009}}
   108  var	ss	= SS{S{3101,3102,3103},S{3104,3105,3106},S{3107,3108,3109}}
   109  var	sc	= SC{[]int{3201,3202,3203},[]int{3204,3205,3206},[]int{3207,3208,3209}}
   110  var	sm	= SM{M{0:3301,1:3302,2:3303}, M{0:3304,1:3305,2:3306}, M{0:3307,1:3308,2:3309}}
   111  
   112  var	ca	= [][3]int{[3]int{4001,4002,4003}, [3]int{4004,4005,4006}, [3]int{4007,4008,4009}}
   113  var	cs	= []S{S{4101,4102,4103},S{4104,4105,4106},S{4107,4108,4109}}
   114  var	cc	= [][]int{[]int{4201,4202,4203}, []int{4204,4205,4206}, []int{4207,4208,4209}}
   115  var	cm	= []M{M{0:4301,1:4302,2:4303}, M{0:4304,1:4305,2:4306}, M{0:4307,1:4308,2:4309}}
   116  
   117  var	ma	= map[int][3]int{0:[3]int{5001,5002,5003}, 1:[3]int{5004,5005,5006}, 2:[3]int{5007,5008,5009}}
   118  var	ms	= map[int]S{0:S{5101,5102,5103},1:S{5104,5105,5106},2:S{5107,5108,5109}}
   119  var	mc	= map[int][]int{0:[]int{5201,5202,5203}, 1:[]int{5204,5205,5206}, 2:[]int{5207,5208,5209}}
   120  var	mm	= map[int]M{0:M{0:5301,1:5302,2:5303}, 1:M{0:5304,1:5305,2:5306}, 2:M{0:5307,1:5308,2:5309}}
   121  
   122  var	answers	= [...]int {
   123  	// s
   124  	1101, 1102, 1103,
   125  
   126  	// ss
   127  	3101, 3102, 3103,
   128  	3104, 3105, 3106,
   129  	3107, 3108, 3109,
   130  
   131  	// [0]
   132  	1001, 1201, 1301,
   133  	2101, 2102, 2103,
   134  	4101, 4102, 4103,
   135  	5101, 5102, 5103,
   136  	3001, 3004, 3007,
   137  	3201, 3204, 3207,
   138  	3301, 3304, 3307,
   139  
   140  	// [0][j]
   141  	2001, 2201, 2301, 4001, 4201, 4301, 5001, 5201, 5301,
   142  	2002, 2202, 2302, 4002, 4202, 4302, 5002, 5202, 5302,
   143  	2003, 2203, 2303, 4003, 4203, 4303, 5003, 5203, 5303,
   144  
   145  	// [1]
   146  	1002, 1202, 1302,
   147  	2104, 2105, 2106,
   148  	4104, 4105, 4106,
   149  	5104, 5105, 5106,
   150  	3002, 3005, 3008,
   151  	3202, 3205, 3208,
   152  	3302, 3305, 3308,
   153  
   154  	// [1][j]
   155  	2004, 2204, 2304, 4004, 4204, 4304, 5004, 5204, 5304,
   156  	2005, 2205, 2305, 4005, 4205, 4305, 5005, 5205, 5305,
   157  	2006, 2206, 2306, 4006, 4206, 4306, 5006, 5206, 5306,
   158  
   159  	// [2]
   160  	1003, 1203, 1303,
   161  	2107, 2108, 2109,
   162  	4107, 4108, 4109,
   163  	5107, 5108, 5109,
   164  	3003, 3006, 3009,
   165  	3203, 3206, 3209,
   166  	3303, 3306, 3309,
   167  
   168  	// [2][j]
   169  	2007, 2207, 2307, 4007, 4207, 4307, 5007, 5207, 5307,
   170  	2008, 2208, 2308, 4008, 4208, 4308, 5008, 5208, 5308,
   171  	2009, 2209, 2309, 4009, 4209, 4309, 5009, 5209, 5309,
   172  }