forked from x-motemen/gore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_test.go
119 lines (96 loc) · 1.8 KB
/
session_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"testing"
)
func TestRun_import(t *testing.T) {
s, err := NewSession()
noError(t, err)
codes := []string{
":import encoding/json",
"b, err := json.Marshal(nil)",
"string(b)",
}
for _, code := range codes {
err := s.Eval(code)
noError(t, err)
}
}
func TestRun_QuickFix_evaluated_but_not_used(t *testing.T) {
s, err := NewSession()
noError(t, err)
codes := []string{
`[]byte("")`,
`make([]int, 0)`,
`1+1`,
`func() {}`,
`(4 & (1 << 1))`,
`1`,
}
for _, code := range codes {
err := s.Eval(code)
noError(t, err)
}
}
func TestRun_QuickFix_used_as_value(t *testing.T) {
s, err := NewSession()
noError(t, err)
codes := []string{
`:import log`,
`a := 1`,
`log.SetPrefix("")`,
}
for _, code := range codes {
err := s.Eval(code)
noError(t, err)
}
}
func TestRun_FixImports(t *testing.T) {
s, err := NewSession()
noError(t, err)
autoimport := true
flagAutoImport = &autoimport
codes := []string{
`filepath.Join("a", "b")`,
}
for _, code := range codes {
err := s.Eval(code)
noError(t, err)
}
}
func TestIncludePackage(t *testing.T) {
s, err := NewSession()
noError(t, err)
err = s.includePackage("github.com/motemen/gore/gocode")
noError(t, err)
err = s.Eval("Completer{}")
noError(t, err)
}
func TestRun_Copy(t *testing.T) {
s, err := NewSession()
noError(t, err)
codes := []string{
`a := []string{"hello", "world"}`,
`b := []string{"goodbye", "world"}`,
`copy(a, b)`,
`if (a[0] != "goodbye") {
panic("should be copied")
}`,
}
for _, code := range codes {
err := s.Eval(code)
noError(t, err)
}
}
func TestRun_Const(t *testing.T) {
s, err := NewSession()
noError(t, err)
codes := []string{
`const ( a = iota; b )`,
`a`,
`b`,
}
for _, code := range codes {
err := s.Eval(code)
noError(t, err)
}
}