1 // $G $F.go && $L $F.$A && ./$A.out
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.
11 const arraylen = 2; // BUG: shouldn't need this
13 func P(a []string) string {
15 for i := 0; i < len(a); i++ {
19 s += `"` + a[i] + `"`;
28 // BUG: should test a map literal when there's syntax
30 mib := new(map[int] bool);
31 mii := new(map[int] int);
32 mfi := new(map[float] int);
33 mif := new(map[int] float);
34 msi := new(map[string] int);
35 mis := new(map[int] string);
36 mss := new(map[string] string);
37 mspa := new(map[string] []string);
38 // BUG need an interface map both ways too
44 mipT := new(map[int] *T);
45 mpTi := new(map[*T] int);
46 //mit := new(map[int] T); // should be able to do a value but: fatal error: algtype: cant find type <T>{}
47 //mti := new(map[T] int); // should be able to do a value but: fatal error: algtype: cant find type <T>{}
50 mipM := new(map[int] *M);
52 const count = 100; // BUG: should be bigger but maps do linear lookup
55 for i := 0; i < count; i++ {
61 apT[2*i] = new(T); // need twice as many entries as we use, for the nonexistence check
65 t := new(T); t.s = s; t.f = f;
66 // BUG m := M(i, i+1);
67 m := new(M); m[i] = i+1;
73 msi[F.d(i).str()] = i;
74 mss[F.d(i).str()] = F.d(10*i).str();
75 mss[F.d(i).str()] = F.d(10*i).str();
76 as := new([arraylen]string);
77 as[0] = F.d(10*i).str();
78 as[1] = F.d(10*i).str();
79 mspa[F.d(i).str()] = as;
87 if len(mib) != count {
88 F.s("len(mib) = ").d(len(mib)).putnl();
90 if len(mii) != count {
91 F.s("len(mii) = ").d(len(mii)).putnl();
93 if len(mfi) != count {
94 F.s("len(mfi) = ").d(len(mfi)).putnl();
96 if len(mif) != count {
97 F.s("len(mif) = ").d(len(mif)).putnl();
99 if len(msi) != count {
100 F.s("len(msi) = ").d(len(msi)).putnl();
102 if len(mis) != count {
103 F.s("len(mis) = ").d(len(mis)).putnl();
105 if len(mss) != count {
106 F.s("len(mss) = ").d(len(mss)).putnl();
108 if len(mspa) != count {
109 F.s("len(mspa) = ").d(len(mspa)).putnl();
111 if len(mipT) != count {
112 F.s("len(mipT) = ").d(len(mipT)).putnl();
114 if len(mpTi) != count {
115 F.s("len(mpTi) = ").d(len(mpTi)).putnl();
117 // if len(mti) != count {
118 // F.s("len(mti) = ").d(len(mti)).putnl();
120 if len(mipM) != count {
121 F.s("len(mipM) = ").d(len(mipM)).putnl();
124 // test construction directly
125 for i := 0; i < count; i++ {
129 var t T; t.s = s; t.f = f;
130 // BUG m := M(i, i+1);
131 if mib[i] != (i != 0) {
132 F.s("mib[").d(i).s("] = ").boolean(mib[i]).putnl();
135 F.s("mii[").d(i).s("] = ").d(mii[i]).putnl();
138 F.s("mfi[").d(i).s("] = ").d(mfi[f]).putnl();
140 if(mif[i] != 10.0*f) {
141 F.s("mif[").d(i).s("] = ").g(mif[i]).putnl();
144 F.s("mis[").d(i).s("] = ").s(mis[i]).putnl();
147 F.s("msi[").s(s).s("] = ").d(msi[s]).putnl();
149 if mss[s] != F.d(10*i).str() {
150 F.s("mss[").s(s).s("] = ").s(mss[s]).putnl();
152 for j := 0; j < arraylen; j++ {
153 if mspa[s][j] != F.d(10*i).str() {
154 F.s("mspa[").s(s).s("][").d(j).s("] = ").s(mspa[s][j]).putnl();
157 if(mipT[i].s != s || mipT[i].f != f) {
158 F.s("mipT[").d(i).s("] = {").s(mipT[i].s).s(", ").g(mipT[i].f).s("}").putnl();
160 if(mpTi[apT[i]] != i) {
161 F.s("mpTi[apT[").d(i).s("]] = ").d(mpTi[apT[i]]).putnl();
164 // F.s("mti[").s(s).s("] = ").s(mti[s]).putnl();
166 if (mipM[i][i] != i + 1) {
167 F.s("mipM[").d(i).s("][").d(i).s("] =").d(mipM[i][i]).putnl();
171 // test existence with tuple check
172 // failed lookups yield a false value for the boolean.
173 for i := 0; i < count; i++ {
177 var t T; t.s = s; t.f = f;
178 // BUG m := M(i, i+1);
182 F.s("tuple existence decl: mib[").d(i).s("]").putnl();
186 F.s("tuple existence assign: mib[").d(i).s("]").putnl();
192 F.s("tuple existence decl: mii[").d(i).s("]").putnl();
196 F.s("tuple existence assign: mii[").d(i).s("]").putnl();
202 F.s("tuple existence decl: mfi[").g(f).s("]").putnl();
206 F.s("tuple existence assign: mfi[").g(f).s("]").putnl();
212 F.s("tuple existence decl: mif[").d(i).s("]").putnl();
216 F.s("tuple existence assign: mif[").d(i).s("]").putnl();
222 F.s("tuple existence decl: mis[").d(i).s("]").putnl();
226 F.s("tuple existence assign: mis[").d(i).s("]").putnl();
232 F.s("tuple existence decl: msi[").s(s).s("]").putnl();
236 F.s("tuple existence assign: msi[").s(s).s("]").putnl();
242 F.s("tuple existence decl: mss[").s(s).s("]").putnl();
246 F.s("tuple existence assign: mss[").s(s).s("]").putnl();
252 F.s("tuple existence decl: mspa[").s(s).s("]").putnl();
256 F.s("tuple existence assign: mspa[").s(s).s("]").putnl();
262 F.s("tuple existence decl: mipT[").d(i).s("]").putnl();
266 F.s("tuple existence assign: mipT[").d(i).s("]").putnl();
270 a, b := mpTi[apT[i]];
272 F.s("tuple existence decl: mpTi[apT[").d(i).s("]]").putnl();
276 F.s("tuple existence assign: mpTi[apT[").d(i).s("]]").putnl();
280 // emit stdout <- format("haskey mti[%s] false", string(t));
284 F.s("tuple existence decl: mipM[").d(i).s("]").putnl();
288 F.s("tuple existence assign: mipM[").d(i).s("]").putnl();
293 // test nonexistence with tuple check
294 // failed lookups yield a false value for the boolean.
295 for i := count; i < 2*count; i++ {
299 var t T; t.s = s; t.f = f;
300 // BUG m := M(i, i+1);
304 F.s("tuple nonexistence decl: mib[").d(i).s("]").putnl();
308 F.s("tuple nonexistence assign: mib[").d(i).s("]").putnl();
314 F.s("tuple nonexistence decl: mii[").d(i).s("]").putnl();
318 F.s("tuple nonexistence assign: mii[").d(i).s("]").putnl();
324 F.s("tuple nonexistence decl: mfi[").g(f).s("]").putnl();
328 F.s("tuple nonexistence assign: mfi[").g(f).s("]").putnl();
334 F.s("tuple nonexistence decl: mif[").d(i).s("]").putnl();
338 F.s("tuple nonexistence assign: mif[").d(i).s("]").putnl();
344 F.s("tuple nonexistence decl: mis[").d(i).s("]").putnl();
348 F.s("tuple nonexistence assign: mis[").d(i).s("]").putnl();
354 F.s("tuple nonexistence decl: msi[").s(s).s("]").putnl();
358 F.s("tuple nonexistence assign: msi[").s(s).s("]").putnl();
364 F.s("tuple nonexistence decl: mss[").s(s).s("]").putnl();
368 F.s("tuple nonexistence assign: mss[").s(s).s("]").putnl();
374 F.s("tuple nonexistence decl: mspa[").s(s).s("]").putnl();
378 F.s("tuple nonexistence assign: mspa[").s(s).s("]").putnl();
384 F.s("tuple nonexistence decl: mipT[").d(i).s("]").putnl();
388 F.s("tuple nonexistence assign: mipT[").d(i).s("]").putnl();
392 a, b := mpTi[apT[i]];
394 F.s("tuple nonexistence decl: mpTi[apt[").d(i).s("]]").putnl();
398 F.s("tuple nonexistence assign: mpTi[apT[").d(i).s("]]").putnl();
402 // emit stdout <- format("haskey mti[%s] false", string(t));
406 F.s("tuple nonexistence decl: mipM[").d(i).s("]").putnl();
410 F.s("tuple nonexistence assign: mipM[").d(i).s("]").putnl();
416 // tests for structured map element updates
417 for i := 0; i < count; i++ {
419 mspa[s][i % 2] = "deleted";
420 if mspa[s][i % 2] != "deleted" {
421 F.s("mspa[").d(i).s("][").d(i).s("%2] =").s(mspa[s][i % 2]).putnl();
423 mipT[i].s = string('a' + i % 26) + mipT[i].s[1:len(s)];
424 first := string('a' + i % 26);
425 if mipT[i].s != first + s[1:len(s)] {
426 F.s("mit[").d(i).s("].s = ").s(mipT[i].s).putnl();
428 mipT[i].f = float(i + 1);
429 if (mipT[i].f != float(i + 1)) {
430 F.s("mipT[").d(i).s("].f = ").g(mipT[i].f).putnl();
433 if mipM[i][i] != (i + 1) + 1 {
434 F.s("mipM[").d(i).s("][").d(i).s("] = ").d(mipM[i][i]).putnl();