-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcheck_test.go
96 lines (80 loc) · 1.34 KB
/
check_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
package gotype
import (
"testing"
)
func TestImplements(t *testing.T) {
const src = `
package a
import "time"
var now = time.Now()
`
scope := Parse(t, src)
typ, ok := scope.ChildByName("now")
if !ok {
t.Fail()
}
scopeTime := Import(t, "time")
val, ok := scopeTime.ChildByName("Time")
if !ok {
t.Fail()
return
}
if !Identical(typ.Declaration().Declaration(), val) {
t.Fail()
}
scopeEncodin := Import(t, "encoding")
inter, ok := scopeEncodin.ChildByName("TextMarshaler")
if !ok {
t.Fail()
return
}
if !Implements(val, inter) {
t.Fail()
}
}
func TestIdentical(t *testing.T) {
var src = `package a
import time "time"
type A struct {
String string
Int int
Array [8]byte
Channel chan int
Interface interface{}
Map map[string]string
Time time.Time
}
type B struct {
String string
Int int
Array [8]byte
Channel chan int
Interface interface{}
Map map[string]string
Time time.Time
}
`
scopeSrc := Parse(t, src)
a, _ := scopeSrc.ChildByName("A")
b, _ := scopeSrc.ChildByName("B")
if !Identical(a, b) {
t.Fail()
return
}
}
func TestEqual(t *testing.T) {
scopeTime := Import(t, "time")
val, ok := scopeTime.ChildByName("Time")
if !ok {
t.Fail()
return
}
now, ok := scopeTime.ChildByName("Now")
if !ok {
t.Fail()
return
}
if !Equal(val, now.Declaration().Out(0).Declaration()) {
t.Fail()
}
}