-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypeinfo_test.go
90 lines (83 loc) · 1.91 KB
/
typeinfo_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
package main
import (
"bytes"
"fmt"
"io/ioutil"
"path/filepath"
"runtime"
"testing"
)
func getSrcCodeDir() string {
if _, file, _, ok := runtime.Caller(0); ok {
return filepath.Dir(file)
} else {
panic("can't get source code dir")
}
}
func getTestDataDir() string {
return filepath.Join(getSrcCodeDir(), "testdata")
}
func TestBuiltinType(t *testing.T) {
testFile := filepath.Join(getTestDataDir(), "file3.go")
def, err := findDefinition(testFile, 77, nil)
if err == nil {
t.Logf("%s, %s", def.decl, def.pos)
} else {
t.Logf("%s", err.Error())
}
}
func TestFindDeclare(t *testing.T) {
testFile := filepath.Join(getTestDataDir(), "file2.go")
def, err := findDefinition(testFile, 169, nil)
if err == nil {
t.Logf("%s, %s", def.decl, def.pos)
} else {
t.Logf("%s", err.Error())
}
def, err = findDefinition(testFile, 177, nil)
if err == nil {
t.Logf("%s, %s", def.decl, def.pos)
} else {
t.Logf("%s", err.Error())
}
def, err = findDefinition(testFile, 146, nil)
if err == nil {
t.Logf("%s, %s", def.decl, def.pos)
} else {
t.Logf("%s", err.Error())
}
def, err = findDefinition(testFile, 142, nil)
if err == nil {
t.Logf("%s, %s", def.decl, def.pos)
} else {
t.Logf("%s", err.Error())
}
def, err = findDefinition(testFile, 29, nil)
if err == nil {
t.Logf("%s, %s", def.decl, def.pos)
} else {
t.Logf("%s", err.Error())
}
def, err = findDefinition(testFile, 203, nil)
if err == nil {
t.Logf("%s, %s", def.decl, def.pos)
} else {
t.Logf("%s", err.Error())
}
}
func TestOverlayArchive(t *testing.T) {
var buf bytes.Buffer
testFile := filepath.Join(getTestDataDir(), "file2.go")
s := testFile + "\n"
buf.Write([]byte(s))
buf2, _ := ioutil.ReadFile(testFile)
s = fmt.Sprintf("%d\n", len(buf2))
buf.Write([]byte(s))
buf.Write(buf2)
def, err := findDefinition(testFile, 169, &buf)
if err == nil {
t.Logf("%s, %s", def.decl, def.pos)
} else {
t.Logf("%s", err.Error())
}
}