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