go.tools/go/types: simplified GcImportedTypes test
R=adonovan CC=golang-dev https://golang.org/cl/23340043
This commit is contained in:
parent
7520cff8d3
commit
0f193b767d
|
|
@ -5,7 +5,6 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go/ast"
|
|
||||||
"go/build"
|
"go/build"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -116,14 +115,13 @@ func TestGcImport(t *testing.T) {
|
||||||
|
|
||||||
var importedObjectTests = []struct {
|
var importedObjectTests = []struct {
|
||||||
name string
|
name string
|
||||||
kind ast.ObjKind
|
want string
|
||||||
typ string
|
|
||||||
}{
|
}{
|
||||||
{"unsafe.Pointer", ast.Typ, "unsafe.Pointer"},
|
{"unsafe.Pointer", "type Pointer unsafe.Pointer"},
|
||||||
{"math.Pi", ast.Con, "untyped float"},
|
{"math.Pi", "const Pi untyped float"},
|
||||||
{"io.Reader", ast.Typ, "interface{Read(p []byte) (n int, err error)}"},
|
{"io.Reader", "type Reader interface{Read(p []byte) (n int, err error)}"},
|
||||||
{"io.ReadWriter", ast.Typ, "interface{Read(p []byte) (n int, err error); Write(p []byte) (n int, err error)}"},
|
{"io.ReadWriter", "type ReadWriter interface{Read(p []byte) (n int, err error); Write(p []byte) (n int, err error)}"},
|
||||||
{"math.Sin", ast.Fun, "func(x·2 float64) (_ float64)"},
|
{"math.Sin", "func math.Sin(x·2 float64) (_ float64)"},
|
||||||
// TODO(gri) add more tests
|
// TODO(gri) add more tests
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -147,34 +145,14 @@ func TestGcImportedTypes(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
obj := pkg.scope.Lookup(objName)
|
obj := pkg.scope.Lookup(objName)
|
||||||
|
if obj == nil {
|
||||||
// TODO(gri) should define an accessor on Object
|
t.Errorf("%s: object not found", test.name)
|
||||||
var kind ast.ObjKind
|
continue
|
||||||
var typ Type
|
|
||||||
switch obj := obj.(type) {
|
|
||||||
case *Const:
|
|
||||||
kind = ast.Con
|
|
||||||
typ = obj.typ
|
|
||||||
case *TypeName:
|
|
||||||
kind = ast.Typ
|
|
||||||
typ = obj.typ
|
|
||||||
case *Var:
|
|
||||||
kind = ast.Var
|
|
||||||
typ = obj.typ
|
|
||||||
case *Func:
|
|
||||||
kind = ast.Fun
|
|
||||||
typ = obj.typ
|
|
||||||
default:
|
|
||||||
unreachable()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if kind != test.kind {
|
got := obj.String()
|
||||||
t.Errorf("%s: got kind = %q; want %q", test.name, kind, test.kind)
|
if got != test.want {
|
||||||
}
|
t.Errorf("%s: got %q; want %q", test.name, got, test.want)
|
||||||
|
|
||||||
str := typeString(typ.Underlying())
|
|
||||||
if str != test.typ {
|
|
||||||
t.Errorf("%s: got type = %q; want %q", test.name, typ, test.typ)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue