1
2
3
4
5 package specgen
6
7 import (
8 "go/types"
9 "testing"
10 )
11
12 func TestTypeSet(t *testing.T) {
13 pkg := loadSpec(t)
14
15 obj := pkg.Pkg.Scope().Lookup("Nums")
16 if obj == nil {
17 t.Fatalf("failed to find 'Nums' in spec package scope")
18 }
19
20 typeName, ok := obj.(*types.TypeName)
21 if !ok {
22 t.Fatalf("Nums is not a TypeName, got %T", obj)
23 }
24
25 typesList := typeSet(typeName.Type())
26
27 expected := []string{
28 "float32", "float64",
29 "int8", "int16", "int32", "int64",
30 "uint8", "uint16", "uint32", "uint64",
31 }
32
33 if len(typesList) != len(expected) {
34 t.Errorf("expected %d types, got %d", len(expected), len(typesList))
35 }
36
37 found := make(map[string]bool)
38 for _, ty := range typesList {
39 found[ty.String()] = true
40 }
41
42 for _, exp := range expected {
43 if !found[exp] {
44 t.Errorf("expected type %s not found in satisfying list", exp)
45 }
46 }
47 }
48
View as plain text