blob: 393edac804eca0a0d3a38949743cd9e38f70149b [file] [log] [blame]
Rob Pike126150d2008-06-06 13:28:03 -07001// $G $F.go && $L $F.$A && ./$A.out
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
7package main
8
9func assert(cond bool, msg string) {
10 if !cond {
Rob Pikebc2f5f12008-08-11 22:07:49 -070011 print("assertion fail: ", msg, "\n");
12 panic(1);
Rob Pike126150d2008-06-06 13:28:03 -070013 }
14}
15
16const (
17 x int = iota;
18 y = iota;
19 z = 1 << iota;
20 f float = 2 * iota;
21 g float = 4.5 * float(iota);
Rob Pike787cdc62008-07-03 17:16:08 -070022)
23
Russ Cox839a6842009-01-20 14:40:40 -080024const (
Rob Pike787cdc62008-07-03 17:16:08 -070025 X = 0;
26 Y;
27 Z;
28)
29
Russ Cox839a6842009-01-20 14:40:40 -080030const (
Rob Pike787cdc62008-07-03 17:16:08 -070031 A = 1 << iota;
32 B;
33 C;
34 D;
35 E = iota * iota;
36 F;
37 G;
38)
39
40const (
41 a = 1;
42 b = iota << a;
43 c = iota << b;
44 d;
45)
46
47const (
48 i = (a << iota) + (b * iota);
49 j;
50 k;
51 l;
52)
53
54const (
55 m = iota == 0;
56 n;
57)
58
59const (
60 p = float(iota);
61 q;
62 r;
63)
64
65const (
66 s = string(iota + 'a');
67 t;
68)
Rob Pike126150d2008-06-06 13:28:03 -070069
Rob Pike2fe97c32008-12-05 15:37:09 -080070const (
71 abit, amask = 1 << iota, 1 << iota - 1;
72 bbit, bmask = 1 << iota, 1 << iota - 1;
73 cbit, cmask = 1 << iota, 1 << iota - 1;
74)
75
Rob Pike126150d2008-06-06 13:28:03 -070076func main() {
77 assert(x == 0, "x");
78 assert(y == 1, "y");
79 assert(z == 4, "z");
80 assert(f == 6.0, "f");
81 assert(g == 18.0, "g");
Rob Pike787cdc62008-07-03 17:16:08 -070082
83 assert(X == 0, "X");
84 assert(Y == 0, "Y");
85 assert(Z == 0, "Z");
86
87 assert(A == 1, "A");
88 assert(B == 2, "B");
89 assert(C == 4, "C");
90 assert(D == 8, "D");
91 assert(E == 16, "E");
92 assert(F == 25, "F");
93
94 assert(a == 1, "a");
95 assert(b == 2, "b");
96 assert(c == 8, "c");
97 assert(d == 12, "d");
98
99 assert(i == 1, "i");
100 assert(j == 4, "j");
101 assert(k == 8, "k");
102 assert(l == 14, "l");
103
104 assert(m, "m");
105 assert(!n, "n");
106
107 assert(p == 0.0, "p");
108 assert(q == 1.0, "q");
109 assert(r == 2.0, "r");
110
111 assert(s == "a", "s");
Rob Pike3308eb42008-08-20 15:46:05 -0700112 assert(t == "b", "t");
Rob Pike2fe97c32008-12-05 15:37:09 -0800113
114 assert(abit == 1, "abit");
115 assert(amask == 0, "amask");
116 assert(bbit == 2, "bbit");
117 assert(bmask == 1, "bmask");
118 assert(cbit == 4, "cbit");
119 assert(cmask == 3, "cmask");
Rob Pike126150d2008-06-06 13:28:03 -0700120}