Home | History | Annotate | Download | only in ken
      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 struct-valued variables (not pointers).
      8 
      9 package main
     10 
     11 type	x2	struct { a,b,c int; d int; };
     12 var	g1	x2;
     13 var	g2	struct { a,b,c int; d x2; };
     14 
     15 func
     16 main() {
     17 	var x int;
     18 	var s1 *x2;
     19 	var s2 *struct { a,b,c int; d x2; };
     20 	var s3 struct { a,b,c int; d x2; };
     21 
     22 	s1 = &g1;
     23 	s2 = &g2;
     24 
     25 	s1.a = 1;
     26 	s1.b = 2;
     27 	s1.c = 3;
     28 	s1.d = 5;
     29 
     30 	if(s1.c != 3) { panic(s1.c); }
     31 	if(g1.c != 3) { panic(g1.c); }
     32 
     33 	s2.a = 7;
     34 	s2.b = 11;
     35 	s2.c = 13;
     36 	s2.d.a = 17;
     37 	s2.d.b = 19;
     38 	s2.d.c = 23;
     39 	s2.d.d = 29;
     40 
     41 	if(s2.d.c != 23) { panic(s2.d.c); }
     42 	if(g2.d.c != 23) { panic(g2.d.c); }
     43 
     44 	x =	s1.a +
     45 		s1.b +
     46 		s1.c +
     47 		s1.d +
     48 
     49 		s2.a +
     50 		s2.b +
     51 		s2.c +
     52 		s2.d.a +
     53 		s2.d.b +
     54 		s2.d.c +
     55 		s2.d.d;
     56 
     57 	if(x != 130) { panic(x); }
     58 
     59 	// test an automatic struct
     60 	s3.a = 7;
     61 	s3.b = 11;
     62 	s3.c = 13;
     63 	s3.d.a = 17;
     64 	s3.d.b = 19;
     65 	s3.d.c = 23;
     66 	s3.d.d = 29;
     67 
     68 	if(s3.d.c != 23) { panic(s3.d.c); }
     69 
     70 	x =	s3.a +
     71 		s3.b +
     72 		s3.c +
     73 		s3.d.a +
     74 		s3.d.b +
     75 		s3.d.c +
     76 		s3.d.d;
     77 
     78 	if(x != 119) { panic(x); }
     79 }
     80