forked from clipperhouse/typewriter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage_test.go
105 lines (78 loc) · 1.64 KB
/
package_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package typewriter
import (
"testing"
"golang.org/x/tools/go/types"
)
func TestEval(t *testing.T) {
// this'll create a real package with types from this, um, package
a, err := NewApp("+test")
if err != nil {
t.Error(err)
return // we got problems, continuing will panic
}
p := a.Packages[0]
s1 := "App"
t1, err1 := p.Eval(s1)
if err1 != nil {
t.Error(err1)
}
if t1.Pointer {
t.Errorf("'app' is not a pointer type")
}
if t1.comparable {
t.Errorf("'app' is not a comparable type")
}
if t1.numeric {
t.Errorf("'app' is not a numeric type")
}
if t1.ordered {
t.Errorf("'app' is not an ordered type")
}
// embedded types.Type should be accessible via type assertion
tt1, ok1 := t1.Underlying().(*types.Struct)
if !ok1 {
t.Errorf("unable to assert %s as a *types.Struct", t1)
}
if tt1.NumFields() != 3 {
t.Errorf("%s should have 3 fields", tt1)
}
s2 := "*App"
t2, err2 := p.Eval(s2)
if err2 != nil {
t.Error(err2)
}
if !t2.Pointer {
t.Errorf("'*app' is a pointer type")
}
if !t2.comparable {
t.Errorf("'*app' is a comparable type")
}
if t2.numeric {
t.Errorf("'*app' is not a numeric type")
}
if t2.ordered {
t.Errorf("'*app' is not an ordered type")
}
s3 := "int"
t3, err3 := p.Eval(s3)
if err3 != nil {
t.Error(err3)
}
if t3.Pointer {
t.Errorf("int is not a pointer type")
}
if !t3.comparable {
t.Errorf("int is a comparable type")
}
if !t3.numeric {
t.Errorf("int is a numeric type")
}
if !t3.ordered {
t.Errorf("int is an ordered type")
}
s4 := "notreal"
_, err4 := p.Eval(s4)
if err4 == nil {
t.Error("'notreal' should not successfully evaluate as a type")
}
}