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.
7 // Test simple type switches on basic types.
21 var x = []int{1, 2, 3}
23 func f(x int, len *byte) {
27 func whatis(x interface{}) string {
28 switch xx := x.(type) {
30 return fmt.Sprint("default ", xx)
31 case int, int8, int16, int32:
32 return fmt.Sprint("signed ", xx)
34 return fmt.Sprint("signed64 ", int64(xx))
35 case uint, uint8, uint16, uint32:
36 return fmt.Sprint("unsigned ", xx)
38 return fmt.Sprint("unsigned64 ", uint64(xx))
40 return fmt.Sprint("nil ", xx)
45 func whatis1(x interface{}) string {
49 return fmt.Sprint("default ", xx)
50 case int, int8, int16, int32:
51 return fmt.Sprint("signed ", xx)
53 return fmt.Sprint("signed64 ", xx.(int64))
54 case uint, uint8, uint16, uint32:
55 return fmt.Sprint("unsigned ", xx)
57 return fmt.Sprint("unsigned64 ", xx.(uint64))
59 return fmt.Sprint("nil ", xx)
64 func check(x interface{}, s string) {
67 fmt.Println("whatis", x, "=>", w, "!=", s)
73 fmt.Println("whatis1", x, "=>", w, "!=", s)
80 check(uint(1), "unsigned 1")
81 check(int64(1), "signed64 1")
82 check(uint64(1), "unsigned64 1")
83 check(1.5, "default 1.5")
84 check(nil, "nil <nil>")