~ubuntu-branches/ubuntu/utopic/gccgo-go/utopic

« back to all changes in this revision

Viewing changes to test/ken/strvar.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-27 09:18:55 UTC
  • Revision ID: package-import@ubuntu.com-20140127091855-zxfshmykfsyyw4b2
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}