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.
22 type S struct { a int }
25 var c = make(chan int);
27 var a = []int{0,1,2,3}
29 var m = make(map[string]int)
31 func assert(b bool, s string) {
38 func f(i int) interface{} {
59 panic("bad type number");
63 for i := Bool; i < Last; i++ {
64 switch x := f(i).(type) {
66 assert(x == true && i == Bool, "bool");
68 assert(x == 7 && i == Int, "int");
70 assert(x == 7.4 && i == Float, "float");
72 assert(x == "hello"&& i == String, "string");
74 assert(x.a == 1234 && i == Struct, "struct");
76 assert(x == c && i == Chan, "chan");
78 assert(x[3] == 3 && i == Array, "array");
80 assert(x == m && i == Map, "map");
81 case func(i int) interface{}:
82 assert(x == f && i == Func, "fun");
84 assert(false, "unknown");
88 // boolean switch (has had bugs in past; worth writing down)
91 assert(true, "switch 2 bool");
93 assert(false, "switch 2 unknown");
98 assert(true, "switch 3 bool");
100 assert(false, "switch 3 unknown");
105 assert(true, "switch 4 bool");
107 assert(false, "switch 4 unknown");