mirror of
https://github.com/golang/go
synced 2024-11-17 08:04:46 -07:00
cmd/compile/internal/types: change structuraltype_test.go to external test
This test can run against package types's exported API just fine. Change-Id: I74184eedc9ca9159b05d893c5f7c615c3dd1884d Reviewed-on: https://go-review.googlesource.com/c/go/+/405655 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
e99275241c
commit
53db708a1d
@ -5,9 +5,11 @@
|
||||
// Test that StructuralType() calculates the correct value of structural type for
|
||||
// unusual cases.
|
||||
|
||||
package types
|
||||
package types_test
|
||||
|
||||
import (
|
||||
"cmd/compile/internal/ir"
|
||||
. "cmd/compile/internal/types"
|
||||
"cmd/internal/src"
|
||||
"testing"
|
||||
)
|
||||
@ -25,32 +27,33 @@ func TestStructuralType(t *testing.T) {
|
||||
RegSize = 8
|
||||
MaxWidth = 1 << 50
|
||||
|
||||
InitTypes(func(sym *Sym, typ *Type) Object {
|
||||
obj := ir.NewDeclNameAt(src.NoXPos, ir.OTYPE, sym)
|
||||
obj.SetType(typ)
|
||||
sym.Def = obj
|
||||
return obj
|
||||
})
|
||||
|
||||
// type intType = int
|
||||
intType := newType(TINT)
|
||||
intType := Types[TINT]
|
||||
// type structf = struct { f int }
|
||||
structf := NewStruct(nil, []*Field{
|
||||
NewField(src.NoXPos, LocalPkg.Lookup("f"), intType),
|
||||
})
|
||||
|
||||
// type Sf structf
|
||||
Sf := newType(TFORW)
|
||||
Sf.sym = LocalPkg.Lookup("Sf")
|
||||
Sf.SetUnderlying(structf)
|
||||
defNamed := func(name string, underlying *Type) *Type {
|
||||
sym := LocalPkg.Lookup(name)
|
||||
obj := ir.NewDeclNameAt(src.NoXPos, ir.OTYPE, sym)
|
||||
typ := NewNamed(obj)
|
||||
typ.SetUnderlying(underlying)
|
||||
return typ
|
||||
}
|
||||
|
||||
// type A int
|
||||
A := newType(TFORW)
|
||||
A.sym = LocalPkg.Lookup("A")
|
||||
A.SetUnderlying(intType)
|
||||
Sf := defNamed("Sf", structf) // type Sf structf
|
||||
A := defNamed("A", intType) // type A int
|
||||
B := defNamed("B", intType) // type B int
|
||||
|
||||
// type B int
|
||||
B := newType(TFORW)
|
||||
B.sym = LocalPkg.Lookup("B")
|
||||
B.SetUnderlying(intType)
|
||||
|
||||
emptyInterface := NewInterface(BuiltinPkg, []*Field{}, false)
|
||||
any := newType(TFORW)
|
||||
any.sym = LocalPkg.Lookup("any")
|
||||
any.SetUnderlying(emptyInterface)
|
||||
any := AnyType
|
||||
|
||||
// The tests marked NONE have no structural type; all the others have a
|
||||
// structural type of structf - "struct { f int }"
|
||||
@ -71,7 +74,7 @@ func TestStructuralType(t *testing.T) {
|
||||
structf,
|
||||
},
|
||||
{
|
||||
// interface { any | Sf }
|
||||
// interface { any; Sf }
|
||||
embed(any, Sf),
|
||||
structf,
|
||||
},
|
||||
@ -118,10 +121,10 @@ func TestStructuralType(t *testing.T) {
|
||||
structf,
|
||||
},
|
||||
}
|
||||
for _, tst := range tests {
|
||||
for i, tst := range tests {
|
||||
if got, want := tst.typ.StructuralType(), tst.structuralType; got != want {
|
||||
t.Errorf("StructuralType(%v) = %v, wanted %v",
|
||||
tst.typ, got, want)
|
||||
t.Errorf("#%v: StructuralType(%v) = %v, wanted %v",
|
||||
i, tst.typ, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user