~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to test/convert.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-04-20 17:36:48 UTC
  • Revision ID: james.westby@ubuntu.com-20110420173648-ifergoxyrm832trd
Tags: upstream-2011.03.07.1
Import upstream version 2011.03.07.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// $G $D/$F.go && $L $F.$A && ./$A.out
 
2
 
 
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.
 
6
 
 
7
package main
 
8
 
 
9
import "reflect"
 
10
 
 
11
func typeof(x interface{}) string { return reflect.Typeof(x).String() }
 
12
 
 
13
func f() int { return 0 }
 
14
 
 
15
func g() int { return 0 }
 
16
 
 
17
type T func() int
 
18
 
 
19
var m = map[string]T{"f": f}
 
20
 
 
21
type A int
 
22
type B int
 
23
 
 
24
var a A = 1
 
25
var b B = 2
 
26
var x int
 
27
 
 
28
func main() {
 
29
        want := typeof(g)
 
30
        if t := typeof(f); t != want {
 
31
                println("type of f is", t, "want", want)
 
32
                panic("fail")
 
33
        }
 
34
 
 
35
        want = typeof(a)
 
36
        if t := typeof(+a); t != want {
 
37
                println("type of +a is", t, "want", want)
 
38
                panic("fail")
 
39
        }
 
40
        if t := typeof(a + 0); t != want {
 
41
                println("type of a+0 is", t, "want", want)
 
42
                panic("fail")
 
43
        }
 
44
}