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 that basic operations on named types are valid
8 // and preserve the type.
21 // Calling these functions checks at compile time that the argument
22 // can be converted implicitly to (used as) the given type.
23 func asArray(Array) {}
26 func asFloat(Float) {}
29 func asSlice(Slice) {}
30 func asString(String) {}
35 // These functions check at run time that the default type
36 // (in the absence of any implicit conversion hints)
38 func isArray(x interface{}) { _ = x.(Array) }
39 func isBool(x interface{}) { _ = x.(Bool) }
40 func isChan(x interface{}) { _ = x.(Chan) }
41 func isFloat(x interface{}) { _ = x.(Float) }
42 func isInt(x interface{}) { _ = x.(Int) }
43 func isMap(x interface{}) { _ = x.(Map) }
44 func isSlice(x interface{}) { _ = x.(Slice) }
45 func isString(x interface{}) { _ = x.(String) }
55 slice Slice = make(Slice, 10)
239 asSlice(make(Slice, 5))
240 isSlice(make(Slice, 5))
241 asSlice([]byte{1, 2, 3})
242 asSlice([]byte{1, 2, 3}[0:2])
251 asSlice(Slice{1, 2, 3})
252 isSlice(Slice{1, 2, 3})
268 asString(String('a'))
269 isString(String('a'))
270 asString(String([]byte(slice)))
271 isString(String([]byte(slice)))
272 asString(String([]byte(nil)))
273 isString(String([]byte(nil)))
275 asString(String("hello"))
276 isString(String("hello"))