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.
30 var c = make(chan int)
32 var a = []int{0, 1, 2, 3}
34 var m = make(map[string]int)
36 func assert(b bool, s string) {
43 func f(i int) interface{} {
64 panic("bad type number")
68 for i := Bool; i < Last; i++ {
69 switch x := f(i).(type) {
71 assert(x == true && i == Bool, "bool")
73 assert(x == 7 && i == Int, "int")
75 assert(x == 7.4 && i == Float, "float64")
77 assert(x == "hello" && i == String, "string")
79 assert(x.a == 1234 && i == Struct, "struct")
81 assert(x == c && i == Chan, "chan")
83 assert(x[3] == 3 && i == Array, "array")
85 assert(x == m && i == Map, "map")
86 case func(i int) interface{}:
87 assert(x == f && i == Func, "fun")
89 assert(false, "unknown")
93 // boolean switch (has had bugs in past; worth writing down)
96 assert(true, "switch 2 bool")
98 assert(false, "switch 2 unknown")
103 assert(true, "switch 3 bool")
105 assert(false, "switch 3 unknown")
110 assert(true, "switch 4 bool")
112 assert(false, "switch 4 unknown")