-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefinedtype_test.go
57 lines (50 loc) · 1.36 KB
/
definedtype_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
package gospec
import "testing"
// IsDefinedType(code,v string) bool
// A's type is example.A, and analysed to *types.Named
// A is a defined type
func TestIsDefinedType01(t *testing.T) {
if !IsDefinedType(`type A int`, "A") {
t.Error(`test rule failed`)
}
}
// A's type is int, and analysed to *types.Basic
// A is a defined type
func TestIsDefinedType02(t *testing.T) {
if !IsDefinedType(`type A = int`, "A") {
t.Error(`test rule failed`)
}
}
// A's type is example.A, and analysed to *types.Named
// A is a defined type
func TestIsDefinedType03(t *testing.T) {
if !IsDefinedType(`type A func()`, "A") {
t.Error(`test rule failed`)
}
}
// A's type is func(), and analysed to *types.Signature
// A is not a defined type
func TestIsDefinedType04(t *testing.T) {
if IsDefinedType(`type A = func()`, "A") {
t.Error(`test rule failed`)
}
}
// test func (s *Spec) IsDefinedType(v string) bool
// A's type is example.A, and analysed to *types.Named
// A is a defined type
func TestIsDefinedType05(t *testing.T) {
s := NewSpec(`type A int`)
if !s.IsDefinedType("A") {
t.Error(`test rule failed`)
}
}
// test IsDefinedType(t types.Type) bool
// A's type is example.A, and analysed to *types.Named
// A is a defined type
func TestIsDefinedType06(t *testing.T) {
s := NewSpec(`type A int`)
typ := s.GetType("A")
if !IsDefinedType(typ) {
t.Error(`test rule failed`)
}
}